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

[PATCH] Make git add -n and git -u -n output consistent

From
Gustaf Hendeby <hendeby@isy.liu.se>
Date
May 22, 2008, 21:59 UTC
Message-ID
<1211493582-13400-1-git-send-email-hendeby@isy.liu.se>
In-Reply-To
<4835E1AE.6030201@isy.liu.se>
Signed-off-by: Gustaf Hendeby <hendeby@isy.liu.se>
---

This would be one way to go to get a more coherent behavior or the -n switch to git add. It would also unify the implementation somewhat. I'd suggest amending this to your patch, or would the output be likely to be used by scrips? In that case I'd vote for changing the output of git add -n -u,

/Gustaf
 builtin-add.c |   19 ++++++-------------
 1 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index dd2ca4b..e8dce30 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -261,17 +261,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 
 	fill_directory(&dir, pathspec, ignored_too);
 
-	if (show_only) {
-		const char *sep = "", *eof = "";
-		for (i = 0; i < dir.nr; i++) {
-			printf("%s%s", sep, dir.entries[i]->name);
-			sep = " ";
-			eof = "\n";
-		}
-		fputs(eof, stdout);
-		return 0;
-	}
-
 	if (read_cache() < 0)
 		die("index file corrupt");
 
@@ -284,12 +273,16 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		die("no files added");
 	}
 
-	for (i = 0; i < dir.nr; i++)
-		if (add_file_to_cache(dir.entries[i]->name, verbose ? ADD_CACHE_VERBOSE : 0)) {
+	for (i = 0; i < dir.nr; i++) {
+		int flags = ((verbose ? ADD_CACHE_VERBOSE : 0) |
+								 (show_only ? ADD_CACHE_PRETEND : 0) |
+								 (ignore_add_errors ? ADD_CACHE_IGNORE_ERRORS : 0));
+		if (add_file_to_cache(dir.entries[i]->name, flags)) {
 			if (!ignore_add_errors)
 				die("adding files failed");
 			exit_status = 1;
 		}
+	}
 
  finish:
 	if (active_cache_changed) {
-- 
1.5.5.1.501.gefb4
Previous: Gustaf HendebyNext: Junio C Hamano
Message 11 of 13 in “[BUG] git add -u ignores --dry-run flag”
  1. Gustaf HendebyMay 15, 2008
  2. Make git add -u honor --dry-runMiklos Vajna, May 15, 2008
  3. Gustaf HendebyMay 15, 2008
  4. Re* [PATCH] Make git add -u honor --dry-runJunio C Hamano, May 15, 2008
  5. Miklos VajnaMay 16, 2008
  6. Gustaf HendebyMay 19, 2008
  7. Junio C HamanoMay 22, 2008
  8. Gustaf HendebyMay 22, 2008
  9. Junio C HamanoMay 22, 2008
  10. Gustaf HendebyMay 22, 2008
  11. Make git add -n and git -u -n output consistentGustaf Hendeby, May 22, 2008
  12. Junio C HamanoMay 23, 2008
  13. Gustaf HendebyMay 23, 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.