Skip to content

Commit 48944f2

Browse files
rscharfegitster
authored andcommitted
diff --no-index: fix -R with stdin
When -R is given, queue_diff() swaps the mode and name variables of the two files to produce a reverse diff. 1e3f265 (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ö <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e5cb1e3 commit 48944f2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

diff-no-index.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ static int queue_diff(struct diff_options *o,
232232
if (o->flags.reverse_diff) {
233233
SWAP(mode1, mode2);
234234
SWAP(name1, name2);
235+
SWAP(special1, special2);
235236
}
236237

237238
d1 = noindex_filespec(name1, mode1, special1);

t/t4053-diff-no-index.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,25 @@ test_expect_success "diff --no-index treats '-' as stdin" '
224224
test_must_be_empty actual
225225
'
226226

227+
test_expect_success "diff --no-index -R treats '-' as stdin" '
228+
cat >expect <<-EOF &&
229+
diff --git b/a/1 a/-
230+
index $(git hash-object --stdin <a/1)..$ZERO_OID 100644
231+
--- b/a/1
232+
+++ a/-
233+
@@ -1 +1 @@
234+
-1
235+
+x
236+
EOF
237+
238+
test_write_lines x | test_expect_code 1 \
239+
git -c core.abbrev=no diff --no-index -R -- - a/1 >actual &&
240+
test_cmp expect actual &&
241+
242+
test_write_lines 1 | git diff --no-index -R -- a/1 - >actual &&
243+
test_must_be_empty actual
244+
'
245+
227246
test_expect_success 'diff --no-index refuses to diff stdin and a directory' '
228247
test_must_fail git diff --no-index -- - a </dev/null 2>err &&
229248
grep "fatal: cannot compare stdin to a directory" err

0 commit comments

Comments
 (0)