git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv2] add: ignore only ignored files

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Nov 21, 2014, 16:08 UTC
Message-ID
<b4834f562679d7ccad683463edc61db5ea962d8d.1416585536.git.git@drmicha.warpmail.net>
In-Reply-To
<546F5CC7.8060904@drmicha.warpmail.net>

"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>
---
As discussed, we change behavior even without the option.
I.a.w.: We declare "add ignored file" as a minor error compared
to an actual indexing error.

My sincere thanks go out to Jeff without whom I could not possibly have come up with a patch like this :)

 builtin/add.c  | 2 +-
 t/t3700-add.sh | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index ae6d3e2..1074e32 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -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++)
diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index fe274e2..f7ff1f5 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -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'
-- 
2.2.0.rc2.293.gc05a35d
Previous: Michael J GruberNext: Jeff King
Message 10 of 22 in “add: ignore only ignored files”
  1. add: ignore only ignored filesMichael J Gruber, Nov 19, 2014
  2. Junio C HamanoNov 19, 2014
  3. Jeff KingNov 19, 2014
  4. Junio C HamanoNov 19, 2014
  5. Michael J GruberNov 20, 2014
  6. Jeff KingNov 20, 2014
  7. Junio C HamanoNov 20, 2014
  8. Jeff KingNov 20, 2014
  9. Michael J GruberNov 21, 2014
  10. [PATCHv2] add: ignore only ignored filesMichael J Gruber, Nov 21, 2014
  11. Jeff KingNov 21, 2014
  12. Torsten BögershausenNov 22, 2014
  13. Jeff KingNov 22, 2014
  14. Torsten BögershausenNov 22, 2014
  15. Jeff KingNov 23, 2014
  16. Junio C HamanoNov 23, 2014
  17. Jeff KingNov 23, 2014
  18. Junio C HamanoNov 24, 2014
  19. Torsten BögershausenNov 24, 2014
  20. Jeff KingNov 25, 2014
  21. Michael J GruberNov 24, 2014
  22. Michael J GruberNov 24, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.