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

[PATCH] Make the exit code of add_file_to_index actually useful

From
Alex Riesen <raa.lkml@gmail.com>
Date
Mar 2, 2008, 15:42 UTC
Message-ID
<20080302154238.GD2973@steel.home>
In-Reply-To
<20080302154154.GC2973@steel.home>
Update the programs which used the function (as add_file_to_cache).
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
 builtin-add.c    |    6 ++++--
 builtin-commit.c |    7 ++++---
 builtin-mv.c     |    3 ++-
 read-cache.c     |    8 ++++----
 4 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 820110e..abfe473 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -94,7 +94,8 @@ static void update_callback(struct diff_queue_struct *q,
 		case DIFF_STATUS_UNMERGED:
 		case DIFF_STATUS_MODIFIED:
 		case DIFF_STATUS_TYPE_CHANGED:
-			add_file_to_cache(path, verbose);
+			if (add_file_to_cache(path, verbose))
+				exit(1);
 			break;
 		case DIFF_STATUS_DELETED:
 			remove_file_from_cache(path);
@@ -266,7 +267,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 	}
 
 	for (i = 0; i < dir.nr; i++)
-		add_file_to_cache(dir.entries[i]->name, verbose);
+		if (add_file_to_cache(dir.entries[i]->name, verbose))
+			exit(1);
 
  finish:
 	if (active_cache_changed) {
diff --git a/builtin-commit.c b/builtin-commit.c
index f49c22e..fb1e588 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -176,9 +176,10 @@ static void add_remove_files(struct path_list *list)
 	int i;
 	for (i = 0; i < list->nr; i++) {
 		struct path_list_item *p = &(list->items[i]);
-		if (file_exists(p->path))
-			add_file_to_cache(p->path, 0);
-		else
+		if (file_exists(p->path)) {
+			if (add_file_to_cache(p->path, 0))
+				exit(1);
+		} else
 			remove_file_from_cache(p->path);
 	}
 }
diff --git a/builtin-mv.c b/builtin-mv.c
index 68aa2a6..ec6e09d 100644
--- a/builtin-mv.c
+++ b/builtin-mv.c
@@ -260,7 +260,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
 
 		for (i = 0; i < added.nr; i++) {
 			const char *path = added.items[i].path;
-			add_file_to_cache(path, verbose);
+			if (add_file_to_cache(path, verbose))
+				exit(1);
 		}
 
 		for (i = 0; i < deleted.nr; i++)
diff --git a/read-cache.c b/read-cache.c
index 657f0c5..4a4f511 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -461,10 +461,10 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
 	unsigned ce_option = CE_MATCH_IGNORE_VALID|CE_MATCH_RACY_IS_DIRTY;
 
 	if (lstat(path, &st))
-		die("%s: unable to stat (%s)", path, strerror(errno));
+		return error("%s: unable to stat (%s)", path, strerror(errno));
 
 	if (!S_ISREG(st.st_mode) && !S_ISLNK(st.st_mode) && !S_ISDIR(st.st_mode))
-		die("%s: can only add regular files, symbolic links or git-directories", path);
+		return error("%s: can only add regular files, symbolic links or git-directories", path);
 
 	namelen = strlen(path);
 	if (S_ISDIR(st.st_mode)) {
@@ -501,9 +501,9 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose)
 	}
 
 	if (index_path(ce->sha1, path, &st, 1))
-		die("unable to index file %s", path);
+		return error("unable to index file %s", path);
 	if (add_index_entry(istate, ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE))
-		die("unable to add %s to index",path);
+		return error("unable to add %s to index",path);
 	if (verbose)
 		printf("add '%s'\n", path);
 	return 0;
-- 
1.5.4.3.391.gf5a0c
Previous: Alex RiesenNext: Alex Riesen
Message 7 of 32 in “How to "git add ." when some files are not accessible (permission denied)?”
  1. Dirk SüsserottMar 1, 2008
  2. Jeff KingMar 2, 2008
  3. Dirk SüsserottMar 3, 2008
  4. Junio C HamanoMar 3, 2008
  5. Dirk SüsserottMar 3, 2008
  6. Alex RiesenMar 2, 2008
  7. Make the exit code of add_file_to_index actually usefulAlex Riesen, Mar 2, 2008
  8. Extend interface of add_files_to_cache to allow ignore indexing errorsAlex Riesen, Mar 2, 2008
  9. Add --ignore-errors to git-add to allow it to skip files with read errorsAlex Riesen, Mar 2, 2008
  10. Add a test for git-add --ignore-errorsAlex Riesen, Mar 2, 2008
  11. Johannes SchindelinMar 2, 2008
  12. Junio C HamanoMar 2, 2008
  13. Alex RiesenMar 2, 2008
  14. Joachim B HagaMar 2, 2008
  15. Alex RiesenMar 3, 2008
  16. Alex RiesenMay 12, 2008
  17. Make the exit code of add_file_to_index actually usefulAlex Riesen, May 12, 2008
  18. Extend interface of add_files_to_cache to allow ignore indexing errorsAlex Riesen, May 12, 2008
  19. Add --ignore-errors to git-add to allow it to skip files with read errorsAlex Riesen, May 12, 2008
  20. Add a test for git-add --ignore-errorsAlex Riesen, May 12, 2008
  21. Add a config option to ignore errors for git-addAlex Riesen, May 12, 2008
  22. Junio C HamanoMay 13, 2008
  23. Alex RiesenMay 13, 2008
  24. Junio C HamanoMay 13, 2008
  25. Alex RiesenMay 13, 2008
  26. Junio C HamanoMay 12, 2008
  27. Alex RiesenMay 12, 2008
  28. Junio C HamanoMay 12, 2008
  29. Alex RiesenMay 12, 2008
  30. Junio C HamanoMay 12, 2008
  31. Alex RiesenMay 13, 2008
  32. Daniel BarkalowMar 3, 2008

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.