git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 5/6] add -A: only show pathless 'add -A' warning when changes exist outside cwd

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 20, 2013, 15:30 UTC
Message-ID
<7v1ubagkbe.fsf@alter.siamese.dyndns.org>
In-Reply-To
<20130319225134.GF19014@google.com>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 8 quoted lines
> In the spirit of the recent similar change for 'git add -u', avoid
> pestering users that restrict their attention to a subdirectory and
> will not be affected by the coming change in the behavior of pathless
> 'git add -A'.
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> As before.

Have you considered implementing this by adding a separate check immediately after fill_directory() to inspect the paths in dir with the same strncmp_icase() against the prefix, without touching prune_directory() at all? I suspect that would be much cleaner and easier to change in the version boundary.

Same comment about measuring the size of the working tree and the area the user is working on applies to this. After Git 2.0, we would still want to advise users who say "git add -A" without pathspecs to see if the user would have been better off with an explicit ".", so unless advice.addUAuseexplicitdot is set to false, we would still want to inspect the result from fill_directory (and in that case we won't be calling into prune_directory).

Show 57 quoted lines
>  builtin/add.c | 21 ++++++++++++++++-----
>  1 file changed, 16 insertions(+), 5 deletions(-)
>
> diff --git a/builtin/add.c b/builtin/add.c
> index 4d8d441..2493493 100644
> --- a/builtin/add.c
> +++ b/builtin/add.c
> @@ -170,7 +170,9 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
>  	return !!data.add_errors;
>  }
>  
> -static char *prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
> +#define WARN_IMPLICIT_DOT (1u << 0)
> +static char *prune_directory(struct dir_struct *dir, const char **pathspec,
> +			     int prefix, unsigned flag)
>  {
>  	char *seen;
>  	int i, specs;
> @@ -187,6 +189,16 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, int
>  		if (match_pathspec(pathspec, entry->name, entry->len,
>  				   prefix, seen))
>  			*dst++ = entry;
> +		else if (flag & WARN_IMPLICIT_DOT)
> +			/*
> +			 * "git add -A" was run from a subdirectory with a
> +			 * new file outside that directory.
> +			 *
> +			 * "git add -A" will behave like "git add -A :/"
> +			 * instead of "git add -A ." in the future.
> +			 * Warn about the coming behavior change.
> +			 */
> +			warn_pathless_add();
>  	}
>  	dir->nr = dst - dir->entries;
>  	add_pathspec_matches_against_index(pathspec, seen, specs);
> @@ -433,8 +445,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  	}
>  	if (option_with_implicit_dot && !argc) {
>  		static const char *here[2] = { ".", NULL };
> -		if (prefix && addremove)
> -			warn_pathless_add();
>  		argc = 1;
>  		argv = here;
>  		implicit_dot = 1;
> @@ -475,9 +485,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
>  		}
>  
>  		/* This picks up the paths that are not tracked */
> -		baselen = fill_directory(&dir, pathspec);
> +		baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec);
>  		if (pathspec)
> -			seen = prune_directory(&dir, pathspec, baselen);
> +			seen = prune_directory(&dir, pathspec, baselen,
> +					implicit_dot ? WARN_IMPLICIT_DOT : 0);
>  	}
>  
>  	if (refresh_only) {
Previous: Jonathan NiederNext: Jonathan Nieder
Message 50 of 51 in “"git add -u/-A" from future”
  1. 0/2 "git add -u/-A" from futureJunio C Hamano, Mar 8, 2013
  2. 1/2 require pathspec for "git add -u/-A"Junio C Hamano, Mar 8, 2013
  3. Matthieu MoyMar 10, 2013
  4. Junio C HamanoMar 11, 2013
  5. Matthieu MoyMar 11, 2013
  6. 1/2 add: update pathless 'add [-u|-A]' warning to reflect change of planMatthieu Moy, Mar 11, 2013
  7. 2/2 add: add a newline at the end of pathless 'add [-u|-A]' warningMatthieu Moy, Mar 11, 2013
  8. Junio C HamanoMar 11, 2013
  9. Matthieu MoyApr 2, 2013
  10. Junio C HamanoApr 2, 2013
  11. Matthieu MoyApr 2, 2013
  12. Jeff KingMar 12, 2013
  13. Matthieu MoyMar 12, 2013
  14. Jeff KingMar 13, 2013
  15. 1/2 t2200: check that "add -u" limits itself to subdirectoryJeff King, Mar 13, 2013
  16. Matthieu MoyMar 13, 2013
  17. Junio C HamanoMar 13, 2013
  18. Jeff KingMar 14, 2013
  19. 2/2 add: respect add.updateroot config optionJeff King, Mar 13, 2013
  20. Matthieu MoyMar 13, 2013
  21. Jeff KingMar 13, 2013
  22. Junio C HamanoMar 13, 2013
  23. Matthieu MoyMar 14, 2013
  24. 0/4 make pathless 'add [-u|-A]' warning less noisyJonathan Nieder, Mar 19, 2013
  25. 1/4 add: make pathless 'add [-u|-A]' warning a file-global functionJonathan Nieder, Mar 19, 2013
  26. 2/4 add: make warn_pathless_add() a no-op after first callJonathan Nieder, Mar 19, 2013
  27. 3/4 add -u: only show pathless 'add -u' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  28. Junio C HamanoMar 19, 2013
  29. Jonathan NiederMar 19, 2013
  30. Junio C HamanoMar 19, 2013
  31. Jonathan NiederMar 19, 2013
  32. Duy NguyenMar 19, 2013
  33. Jonathan NiederMar 19, 2013
  34. Matthieu MoyMar 19, 2013
  35. Junio C HamanoMar 19, 2013
  36. Jonathan NiederMar 19, 2013
  37. Junio C HamanoMar 19, 2013
  38. Jonathan NiederMar 19, 2013
  39. 4/4 add -A: only show pathless 'add -A' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  40. Jeff KingMar 19, 2013
  41. 2/2 git add: -u/-A now affects the entire working treeJunio C Hamano, Mar 8, 2013
  42. 0/6 make pathless 'add [-u|-A]' warning less noisyJonathan Nieder, Mar 19, 2013
  43. 1/6 t2200: check that "add -u" limits itself to subdirectoryJonathan Nieder, Mar 19, 2013
  44. 2/6 add: make pathless 'add [-u|-A]' warning a file-global functionJonathan Nieder, Mar 19, 2013
  45. 3/6 add: make warn_pathless_add() a no-op after first callJonathan Nieder, Mar 19, 2013
  46. 4/6 add -u: only show pathless 'add -u' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  47. Jeff KingMar 20, 2013
  48. Junio C HamanoMar 20, 2013
  49. 5/6 add -A: only show pathless 'add -A' warning when changes exist outside cwdJonathan Nieder, Mar 19, 2013
  50. Junio C HamanoMar 20, 2013
  51. 6/6 git add: -u/-A now affects the entire working treeJonathan Nieder, Mar 19, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.