add -A: only show pathless 'add -A' warning when changes exist outside cwd

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Mar 19, 2013 at 15:51 UTC 9df84e94ed16dfaeb50350d7e8ec36eee3fc213e
1 file changed +16 -5
builtin/add.c
+16 -5
@@ -170,7 +170,9 @@ int add_files_to_cache(const char *prefix, const char **pathspec, int flags)
170 return !!data.add_errors;
171 }
172
173 -static char *prune_directory(struct dir_struct *dir, const char **pathspec, int prefix)
173 +#define WARN_IMPLICIT_DOT (1u << 0)
174 +static char *prune_directory(struct dir_struct *dir, const char **pathspec,
175 + int prefix, unsigned flag)
176 {
177 char *seen;
178 int i, specs;
@@ -187,6 +189,16 @@ static char *prune_directory(struct dir_struct *dir, const char **pathspec, int
189 if (match_pathspec(pathspec, entry->name, entry->len,
190 prefix, seen))
191 *dst++ = entry;
192 + else if (flag & WARN_IMPLICIT_DOT)
193 + /*
194 + * "git add -A" was run from a subdirectory with a
195 + * new file outside that directory.
196 + *
197 + * "git add -A" will behave like "git add -A :/"
198 + * instead of "git add -A ." in the future.
199 + * Warn about the coming behavior change.
200 + */
201 + warn_pathless_add();
202 }
203 dir->nr = dst - dir->entries;
204 add_pathspec_matches_against_index(pathspec, seen, specs);
@@ -433,8 +445,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
445 }
446 if (option_with_implicit_dot && !argc) {
447 static const char *here[2] = { ".", NULL };
436 - if (prefix && addremove)
437 - warn_pathless_add();
448 argc = 1;
449 argv = here;
450 implicit_dot = 1;
@@ -475,9 +485,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
485 }
486
487 /* This picks up the paths that are not tracked */
478 - baselen = fill_directory(&dir, pathspec);
488 + baselen = fill_directory(&dir, implicit_dot ? NULL : pathspec);
489 if (pathspec)
480 - seen = prune_directory(&dir, pathspec, baselen);
490 + seen = prune_directory(&dir, pathspec, baselen,
491 + implicit_dot ? WARN_IMPLICIT_DOT : 0);
492 }
493
494 if (refresh_only) {