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 <jrnie...@gmail.com>
---
 builtin/add.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/builtin/add.c b/builtin/add.c
index f05ec1c1..56ac4519 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -160,7 +160,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;
@@ -177,6 +179,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);
@@ -423,8 +435,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;
@@ -464,9 +474,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) {
-- 
1.8.2.rc3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to