add: don't complain when adding empty project root
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>
Nguyễn Thái Ngọc Duy committed
Dec 23, 2013 at 16:02 UTC
64ed07cee0394509c65331f1e7acb36c58fd18fb
2 files changed
+20
-1
builtin/add.c
+1
-1
@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
544
545
for (i = 0; i < pathspec.nr; i++) {
546
const char *path = pathspec.items[i].match;
547
- if (!seen[i] &&
547
+ if (!seen[i] && path[0] &&
548
((pathspec.items[i].magic &
549
(PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
550
!file_exists(path))) {
t/t3700-add.sh
+19
@@ -272,6 +272,25 @@ test_expect_success '"add non-existent" should fail' '
272
! (git ls-files | grep "non-existent")
273
'
274
275
+test_expect_success 'git add -A on empty repo does not error out' '
276
+ rm -fr empty &&
277
+ git init empty &&
278
+ (
279
+ cd empty &&
280
+ git add -A . &&
281
+ git add -A
282
+ )
283
+'
284
+
285
+test_expect_success '"git add ." in empty repo' '
286
+ rm -fr empty &&
287
+ git init empty &&
288
+ (
289
+ cd empty &&
290
+ git add .
291
+ )
292
+'
293
+
294
test_expect_success 'git add --dry-run of existing changed file' "
295
echo new >>track-this &&
296
git add --dry-run track-this >actual 2>&1 &&