Skip to content

Commit ee5788e

Browse files
committed
Merge branch 'nd/add-empty-fix' into maint
"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
2 parents d11ade7 + 64ed07c commit ee5788e

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
544544

545545
for (i = 0; i < pathspec.nr; i++) {
546546
const char *path = pathspec.items[i].match;
547-
if (!seen[i] &&
547+
if (!seen[i] && path[0] &&
548548
((pathspec.items[i].magic &
549549
(PATHSPEC_GLOB | PATHSPEC_ICASE)) ||
550550
!file_exists(path))) {

t/t3700-add.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,25 @@ test_expect_success '"add non-existent" should fail' '
272272
! (git ls-files | grep "non-existent")
273273
'
274274

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+
275294
test_expect_success 'git add --dry-run of existing changed file' "
276295
echo new >>track-this &&
277296
git add --dry-run track-this >actual 2>&1 &&

0 commit comments

Comments
 (0)