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

[PATCH] diff --no-index: fix -R with stdin

From
René Scharfe <l.s.r@web.de>
Date
Sep 9, 2023, 22:12 UTC
Message-ID
<22fdfa3b-f90e-afcc-667c-705fb7670245@web.de>
In-Reply-To
<d42579a0-f438-9b4c-97e4-58724dbe4a4@martin.st>

When -R is given, queue_diff() swaps the mode and name variables of the two files to produce a reverse diff. 1e3f26542a (diff --no-index: support reading from named pipes, 2023-07-05) added variables that indicate whether files are special, i.e named pipes or - for stdin. These new variables were not swapped, though, which broke the handling of stdin with with -R. Swap them like the other metadata variables.

Reported-by: Martin Storsjö <martin@martin.st>
Signed-off-by: René Scharfe <l.s.r@web.de>
---
Great bug report, thank you!
 diff-no-index.c          |  1 +
 t/t4053-diff-no-index.sh | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)
diff --git a/diff-no-index.c b/diff-no-index.c
index 8aead3e332..e7041b89e3 100644
--- a/diff-no-index.c
+++ b/diff-no-index.c
@@ -232,6 +232,7 @@ static int queue_diff(struct diff_options *o,
 		if (o->flags.reverse_diff) {
 			SWAP(mode1, mode2);
 			SWAP(name1, name2);
+			SWAP(special1, special2);
 		}

 		d1 = noindex_filespec(name1, mode1, special1);
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 6781cc9078..5f059f65fc 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -224,6 +224,25 @@ test_expect_success "diff --no-index treats '-' as stdin" '
 	test_must_be_empty actual
 '

+test_expect_success "diff --no-index -R treats '-' as stdin" '
+	cat >expect <<-EOF &&
+	diff --git b/a/1 a/-
+	index $(git hash-object --stdin <a/1)..$ZERO_OID 100644
+	--- b/a/1
+	+++ a/-
+	@@ -1 +1 @@
+	-1
+	+x
+	EOF
+
+	test_write_lines x | test_expect_code 1 \
+		git -c core.abbrev=no diff --no-index -R -- - a/1 >actual &&
+	test_cmp expect actual &&
+
+	test_write_lines 1 | git diff --no-index -R -- a/1 - >actual &&
+	test_must_be_empty actual
+'
+
 test_expect_success 'diff --no-index refuses to diff stdin and a directory' '
 	test_must_fail git diff --no-index -- - a </dev/null 2>err &&
 	grep "fatal: cannot compare stdin to a directory" err
--
2.42.0
Previous: Martin StorsjöNext: Phillip Wood
Message 2 of 6 in “Regression in git diff with stdin, with -R”
  1. Martin StorsjöSep 9, 2023
  2. diff --no-index: fix -R with stdinRené Scharfe, Sep 9, 2023
  3. Phillip WoodSep 10, 2023
  4. Taylor BlauSep 10, 2023
  5. Martin StorsjöSep 11, 2023
  6. Junio C HamanoSep 11, 2023

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.