]> Pileus Git - ~andy/git/commitdiff
add: don't complain when adding empty project root
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 23 Dec 2013 09:02:41 +0000 (16:02 +0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Dec 2013 18:46:26 +0000 (10:46 -0800)
This behavior was added in 07d7bed (add: don't complain when adding
empty project root - 2009-04-28) then broken by 84b8b5d (remove
match_pathspec() in favor of match_pathspec_depth() -
2013-07-14). Reinstate it.

Noticed-by: Thomas Ferris Nicolaisen <tfnico@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
t/t3700-add.sh

index 226f758869358444ad1c39e5e0a05c961fb76859..d7e3e44d06cdf56ac661600788cfdf751037226e 100644 (file)
@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
                for (i = 0; i < pathspec.nr; i++) {
                        const char *path = pathspec.items[i].match;
-                       if (!seen[i] &&
+                       if (!seen[i] && path[0] &&
                            ((pathspec.items[i].magic &
                              (PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
                             !file_exists(path))) {
index aab86e838b806f9bb2289f536f4ba9324d75da0a..fe274e2fb14869314dfb21d563fd2c3f367365c8 100755 (executable)
@@ -272,6 +272,25 @@ test_expect_success '"add non-existent" should fail' '
        ! (git ls-files | grep "non-existent")
 '
 
+test_expect_success 'git add -A on empty repo does not error out' '
+       rm -fr empty &&
+       git init empty &&
+       (
+               cd empty &&
+               git add -A . &&
+               git add -A
+       )
+'
+
+test_expect_success '"git add ." in empty repo' '
+       rm -fr empty &&
+       git init empty &&
+       (
+               cd empty &&
+               git add .
+       )
+'
+
 test_expect_success 'git add --dry-run of existing changed file' "
        echo new >>track-this &&
        git add --dry-run track-this >actual 2>&1 &&