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

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

From
Jeff King <peff@peff.net>
Date
Jun 15, 2012, 19:13 UTC
Message-ID
<20120615191353.GA26473@sigill.intra.peff.net>
In-Reply-To
<20120615184030.GC14843@sigill.intra.peff.net>
On Fri, Jun 15, 2012 at 02:40:30PM -0400, Jeff King wrote:
> I suspect what you actually want is to set DIFF_FROM_CONTENTS in the
> no-index case, since we by definition do not have a pair of sha1s to
> compare. But it may also be that diff.c could detect this case
> automatically. I'd have to look closer.
This works for me:
diff --git a/diff.c b/diff.c
index 77edd50..27231d2 100644
--- a/diff.c
+++ b/diff.c
@@ -3228,7 +3228,8 @@ int diff_setup_done(struct diff_options *options)
 
 	if (DIFF_XDL_TST(options, IGNORE_WHITESPACE) ||
 	    DIFF_XDL_TST(options, IGNORE_WHITESPACE_CHANGE) ||
-	    DIFF_XDL_TST(options, IGNORE_WHITESPACE_AT_EOL))
+	    DIFF_XDL_TST(options, IGNORE_WHITESPACE_AT_EOL) ||
+	    DIFF_OPT_TST(options, NO_INDEX))
 		DIFF_OPT_SET(options, DIFF_FROM_CONTENTS);
 	else
 		DIFF_OPT_CLR(options, DIFF_FROM_CONTENTS);

One could also set DIFF_FROM_CONTENTS manually in diff_on_index, but
note that diff_setup_done unsets it (which seems odd; who would have set
it in the first place if they did not want to override it? I think that
else clause can simply be dropped).

-Peff

PS Your test should probably be spelled with test_expect_code, like:

diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh
index cdb9202..0b83235 100755
--- a/t/t4035-diff-quiet.sh
+++ b/t/t4035-diff-quiet.sh
@@ -77,4 +77,8 @@ test_expect_success 'git diff-index --cached HEAD' '
 	}
 '
 
+test_expect_success 'git diff <tracked file> <file outside repo>' '
+	test_expect_code 1 git diff --quiet c /dev/null
+'
+
 test_done
Previous: Jeff KingNext: Junio C Hamano
Message 3 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.