]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add: ignore only ignored files
authorMichael J Gruber <git@drmicha.warpmail.net>
Fri, 21 Nov 2014 16:08:19 +0000 (17:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 21 Nov 2014 18:19:14 +0000 (10:19 -0800)
"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 <git@drmicha.warpmail.net>
Reviewed-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/add.c
t/t3700-add.sh

index ae6d3e262bcbb3dc57c0ddf146791380259b31be..1074e3234964deb279c3a487e9efd164afdb9c6c 100644 (file)
@@ -284,7 +284,7 @@ static int add_files(struct dir_struct *dir, int flags)
                for (i = 0; i < dir->ignored_nr; i++)
                        fprintf(stderr, "%s\n", dir->ignored[i]->name);
                fprintf(stderr, _("Use -f if you really want to add them.\n"));
-               die(_("no files added"));
+               exit_status = 1;
        }
 
        for (i = 0; i < dir->nr; i++)
index fe274e2fb14869314dfb21d563fd2c3f367365c8..f7ff1f555d473ec1e7bd0f32d8d3c29426adc9f0 100755 (executable)
@@ -91,6 +91,13 @@ test_expect_success 'error out when attempting to add ignored ones without -f' '
        ! (git ls-files | grep "\\.ig")
 '
 
+test_expect_success 'error out when attempting to add ignored ones but add others' '
+       touch a.if &&
+       test_must_fail git add a.?? &&
+       ! (git ls-files | grep "\\.ig") &&
+       (git ls-files | grep a.if)
+'
+
 test_expect_success 'add ignored ones with -f' '
        git add -f a.?? &&
        git ls-files --error-unmatch a.ig
@@ -311,7 +318,6 @@ cat >expect.err <<\EOF
 The following paths are ignored by one of your .gitignore files:
 ignored-file
 Use -f if you really want to add them.
-fatal: no files added
 EOF
 cat >expect.out <<\EOF
 add 'track-this'