Skip to content

Commit 1d31e5a

Browse files
Michael J Grubergitster
authored andcommitted
add: ignore only ignored files
"git add foo bar" adds neither foo nor bar when bar is ignored, but dies to let the user recheck their command invocation. This becomes less helpful when "git add foo.*" is subject to shell expansion and some of the expanded files are ignored. "git add --ignore-errors" is supposed to ignore errors when indexing some files and adds the others. It does ignore errors from actual indexing attempts, but does not ignore the error "file is ignored" as outlined above. This is unexpected. Change "git add foo bar" to add foo when bar is ignored, but issue a warning and return a failure code as before the change. That is, in the case of trying to add ignored files we now act the same way (with or without "--ignore-errors") in which we act for more severe indexing errors when "--ignore-errors" is specified. Signed-off-by: Michael J Gruber <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7ba2ba7 commit 1d31e5a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

builtin/add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int add_files(struct dir_struct *dir, int flags)
284284
for (i = 0; i < dir->ignored_nr; i++)
285285
fprintf(stderr, "%s\n", dir->ignored[i]->name);
286286
fprintf(stderr, _("Use -f if you really want to add them.\n"));
287-
die(_("no files added"));
287+
exit_status = 1;
288288
}
289289

290290
for (i = 0; i < dir->nr; i++)

t/t3700-add.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ test_expect_success 'error out when attempting to add ignored ones without -f' '
9191
! (git ls-files | grep "\\.ig")
9292
'
9393

94+
test_expect_success 'error out when attempting to add ignored ones but add others' '
95+
touch a.if &&
96+
test_must_fail git add a.?? &&
97+
! (git ls-files | grep "\\.ig") &&
98+
(git ls-files | grep a.if)
99+
'
100+
94101
test_expect_success 'add ignored ones with -f' '
95102
git add -f a.?? &&
96103
git ls-files --error-unmatch a.ig
@@ -311,7 +318,6 @@ cat >expect.err <<\EOF
311318
The following paths are ignored by one of your .gitignore files:
312319
ignored-file
313320
Use -f if you really want to add them.
314-
fatal: no files added
315321
EOF
316322
cat >expect.out <<\EOF
317323
add 'track-this'

0 commit comments

Comments
 (0)