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

[PATCH] diff: don't run pager if user asked for a diff style exit code

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Aug 12, 2007, 17:46 UTC
Message-ID
<46BF478F.7030603@lsrfire.ath.cx>
In-Reply-To
<17875.88.10.191.55.1186873960.squirrel@secure.wincent.com>

As Wincent Colaiuta found out, it's a bit unexpected for git diff to start a pager even when the --quiet option is specified. The problem is that the pager hides the return code -- which is the only output we're interested in in this case.

Push pager setup down into builtin-diff.c and don't start the pager if --exit-code or --quiet (which implies --exit-code) was specified.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
 builtin-diff.c |    6 ++++++
 git.c          |    2 +-
 2 files changed, 7 insertions(+), 1 deletions(-)
diff --git a/builtin-diff.c b/builtin-diff.c
index b48121e..8dc17b0 100644
--- a/builtin-diff.c
+++ b/builtin-diff.c
@@ -235,6 +235,12 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 	rev.diffopt.allow_external = 1;
 	rev.diffopt.recursive = 1;
 
+	/* If the user asked for our exit code then don't start a
+	 * pager or we would end up reporting its exit code instead.
+	 */
+	if (!rev.diffopt.exit_with_status)
+		setup_pager();
+
 	/* Do we have --cached and not have a pending object, then
 	 * default to HEAD by hand.  Eek.
 	 */
diff --git a/git.c b/git.c
index e5daae0..cab0e72 100644
--- a/git.c
+++ b/git.c
@@ -325,7 +325,7 @@ static void handle_internal_command(int argc, const char **argv)
 		{ "config", cmd_config },
 		{ "count-objects", cmd_count_objects, RUN_SETUP },
 		{ "describe", cmd_describe, RUN_SETUP },
-		{ "diff", cmd_diff, USE_PAGER },
+		{ "diff", cmd_diff },
 		{ "diff-files", cmd_diff_files },
 		{ "diff-index", cmd_diff_index, RUN_SETUP },
 		{ "diff-tree", cmd_diff_tree, RUN_SETUP },
Previous: Steffen ProhaskaNext: Wincent Colaiuta
Message 9 of 12 in “--exit-code (and --quiet) broken in git-diff?”
  1. Wincent ColaiutaAug 11, 2007
  2. René ScharfeAug 12, 2007
  3. Wincent ColaiutaAug 12, 2007
  4. David KastrupAug 12, 2007
  5. Steven GrimmAug 12, 2007
  6. David KastrupAug 12, 2007
  7. Wincent ColaiutaAug 12, 2007
  8. Steffen ProhaskaAug 12, 2007
  9. diff: don't run pager if user asked for a diff style exit codeRené Scharfe, Aug 12, 2007
  10. Wincent ColaiutaAug 13, 2007
  11. David KastrupAug 13, 2007
  12. Junio C HamanoAug 13, 2007

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.