Thread (3 messages) flat view 3 messages, 2 authors, 2016-06-15
DORMANTno replies

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

From: Gustaf Hendeby <hidden>
Date: 2016-06-15 22:44:38
Subsystem: the rest · Maintainer: Linus Torvalds

Possibly related (same subject, not in this thread)

Signed-off-by: Gustaf Hendeby <redacted>
---

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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help