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

[PATCH] port --ignore-unmatch to "git add"

From
Luke Dashjr <luke-jr+git@utopios.org>
Date
Aug 13, 2009, 21:02 UTC
Message-ID
<1250197365-23720-1-git-send-email-luke-jr+git@utopios.org>
In-Reply-To
<7vr5vfa4ha.fsf@alter.siamese.dyndns.org>

"git rm" has a --ignore-unmatch option that is also applicable to "git add" and may be useful for persons wanting to ignore unmatched arguments, but not all errors.

Signed-off-by: Luke Dashjr <luke-jr+git@utopios.org>
---
 builtin-add.c |   27 +++++++++++++++++++--------
 1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 581a2a1..3882482 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -19,6 +19,7 @@ static const char * const builtin_add_usage[] = {
 };
 static int patch_interactive, add_interactive, edit_interactive;
 static int take_worktree_changes;
+static int ignore_unmatch = 0;
 
 static void fill_pathspec_matches(const char **pathspec, char *seen, int specs)
 {
@@ -60,13 +61,18 @@ static void prune_directory(struct dir_struct *dir, const char **pathspec, int p
 			*dst++ = entry;
 	}
 	dir->nr = dst - dir->entries;
-	fill_pathspec_matches(pathspec, seen, specs);
 
-	for (i = 0; i < specs; i++) {
-		if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i]))
-			die("pathspec '%s' did not match any files",
-					pathspec[i]);
+	if (!ignore_unmatch)
+	{
+		fill_pathspec_matches(pathspec, seen, specs);
+
+		for (i = 0; i < specs; i++) {
+			if (!seen[i] && pathspec[i][0] && !file_exists(pathspec[i]))
+				die("pathspec '%s' did not match any files",
+						pathspec[i]);
+		}
 	}
+
         free(seen);
 }
 
@@ -107,9 +113,12 @@ static void refresh(int verbose, const char **pathspec)
 	seen = xcalloc(specs, 1);
 	refresh_index(&the_index, verbose ? REFRESH_SAY_CHANGED : REFRESH_QUIET,
 		      pathspec, seen);
-	for (i = 0; i < specs; i++) {
-		if (!seen[i])
-			die("pathspec '%s' did not match any files", pathspec[i]);
+	if (!ignore_unmatch)
+	{
+		for (i = 0; i < specs; i++) {
+			if (!seen[i])
+				die("pathspec '%s' did not match any files", pathspec[i]);
+		}
 	}
         free(seen);
 }
@@ -226,6 +235,8 @@ static struct option builtin_add_options[] = {
 	OPT_BOOLEAN('A', "all", &addremove, "add all, noticing removal of tracked files"),
 	OPT_BOOLEAN( 0 , "refresh", &refresh_only, "don't add, only refresh the index"),
 	OPT_BOOLEAN( 0 , "ignore-errors", &ignore_add_errors, "just skip files which cannot be added because of errors"),
+	OPT_BOOLEAN( 0 , "ignore-unmatch", &ignore_unmatch,
+				"exit with a zero status even if nothing matched"),
 	OPT_END(),
 };
 
-- 
1.6.3.3
Previous: Luke-JrNext: Luke Dashjr
Message 10 of 21 in “For review: git add --ignore-unmatch”
  1. Luke-JrAug 12, 2009
  2. Thomas RastAug 12, 2009
  3. 1/5 port --ignore-unmatch to "git add"Luke Dashjr, Aug 13, 2009
  4. 2/5 fix "git add --ignore-errors" to ignore pathspec errorsLuke Dashjr, Aug 13, 2009
  5. 3/5 Document --ignore-unmatch in git-add.txtLuke Dashjr, Aug 13, 2009
  6. 4/5 implement error_errno and warning_errnoLuke Dashjr, Aug 13, 2009
  7. 5/5 Convert add_file_to_index's lstat failure from a die to an errorLuke Dashjr, Aug 13, 2009
  8. Junio C HamanoAug 13, 2009
  9. Luke-JrAug 13, 2009
  10. port --ignore-unmatch to "git add"Luke Dashjr, Aug 13, 2009
  11. Document --ignore-unmatch in git-add.txtLuke Dashjr, Aug 13, 2009
  12. Junio C HamanoAug 13, 2009
  13. Luke-JrAug 13, 2009
  14. Alex RiesenAug 13, 2009
  15. Thomas RastAug 13, 2009
  16. Junio C HamanoAug 14, 2009
  17. Luke-JrAug 14, 2009
  18. Luke-JrAug 14, 2009
  19. Nanako ShiraishiAug 14, 2009
  20. Luke-JrAug 14, 2009
  21. Luke-JrOct 10, 2009

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.