]> git.scripts.mit.edu Git - git.git/commitdiff
diff --no-index: fix -R with stdin
authorRené Scharfe <l.s.r@web.de>
Sat, 9 Sep 2023 22:12:52 +0000 (00:12 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 11 Sep 2023 19:05:37 +0000 (12:05 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-no-index.c
t/t4053-diff-no-index.sh

index 4771cf02aa8588b9e7cb162c38e109e42332cf46..3e573505e0d629aecbcf9fbfc73c77375853a564 100644 (file)
@@ -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);
index 6781cc90786e3eb247b83f107a5407d50ba139f3..5f059f65fced87fd0c25400cec0ed1a50b24edb4 100755 (executable)
@@ -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