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

[PATCH] diff: exit(1) if 'diff --quiet <repo file> <external file>' finds changes

From
Tim Henigan <tim.henigan@gmail.com>
Date
Jun 15, 2012, 17:31 UTC
Message-ID
<1339781463-13536-1-git-send-email-tim.henigan@gmail.com>

When running 'git diff --quiet <file1> <file2>', if file1 or file2 is outside the repository, it will exit(0) even if the files differ. It should exit(1) when they differ.

Signed-off-by: Tim Henigan <tim.henigan@gmail.com>
---

This was the least invasive fix that I found. I considered adding the following when the '--quiet' option is parsed instead:

+   DIFF_OPT_SET(options, EXIT_WITH_STATUS)
+   DIFF_OPT_SET(options, DIFF_FROM_CONTENTS)
 diff.c                | 5 +++--
 t/t4035-diff-quiet.sh | 5 +++++
 2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/diff.c b/diff.c
index 77edd50..b1d74fe 100644
--- a/diff.c
+++ b/diff.c
@@ -4432,9 +4432,10 @@ void diff_flush(struct diff_options *options)
 		separator++;
 	}
 
-	if (output_format & DIFF_FORMAT_NO_OUTPUT &&
+	if ((output_format & DIFF_FORMAT_NO_OUTPUT &&
 	    DIFF_OPT_TST(options, EXIT_WITH_STATUS) &&
-	    DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) {
+	    DIFF_OPT_TST(options, DIFF_FROM_CONTENTS)) ||
+		DIFF_OPT_TST(options, QUICK)) {
 		/*
 		 * run diff_flush_patch for the exit status. setting
 		 * options->file to /dev/null should be safe, becaue we
diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh
index cdb9202..e14e676 100755
--- a/t/t4035-diff-quiet.sh
+++ b/t/t4035-diff-quiet.sh
@@ -77,4 +77,9 @@ test_expect_success 'git diff-index --cached HEAD' '
 	}
 '
 
+test_expect_success 'git diff <tracked file> <file outside repo>' '
+	git diff --quiet c /dev/null
+	test $? = 1
+'
+
 test_done
-- 
1.7.11.rc3.6.g501bf14
Next: Jeff King
Message 1 of 12 in “diff: exit(1) if 'diff --quiet <repo file> <external file>' finds changes”
  1. diff: exit(1) if 'diff --quiet <repo file> <external file>' finds changesTim Henigan, Jun 15, 2012
  2. Jeff KingJun 15, 2012
  3. Jeff KingJun 15, 2012
  4. Junio C HamanoJun 15, 2012
  5. Jeff KingJun 15, 2012
  6. Tim HeniganJun 15, 2012
  7. Junio C HamanoJun 15, 2012
  8. Jeff KingJun 15, 2012
  9. Junio C HamanoJun 15, 2012
  10. Junio C HamanoJun 15, 2012
  11. Tim HeniganJun 18, 2012
  12. Junio C HamanoJun 18, 2012

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.