Merge branch 'nd/add-empty-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 10 Jan 2014 18:33:03 +0000 (10:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jan 2014 18:33:03 +0000 (10:33 -0800)
"git add -A" (no other arguments) in a totally empty working tree
used to emit an error.

* nd/add-empty-fix:
add: don't complain when adding empty project root

builtin/add.c
t/t3700-add.sh
index 0df73ae73596546966af18e7076d9a6f54964786..2a2722fa10aa981695b21984e7c425c35b4f18d0 100644 (file)
@@ -547,7 +547,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
                        const char *path = pathspec.items[i].match;
                        if (pathspec.items[i].magic & PATHSPEC_EXCLUDE)
                                continue;
-                       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 &&