range-diff: fix regression in passing along diff options
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 9 Nov 2018 10:18:02 +0000 (10:18 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 12 Nov 2018 03:09:21 +0000 (12:09 +0900)
In 73a834e9e2 ("range-diff: relieve callers of low-level configuration
burden", 2018-07-22) we broke passing down options like --no-patch,
--stat etc.

Fix that regression, and add a test asserting the pre-73a834e9e2
behavior for some of these diff options.

As noted in a change leading up to this ("range-diff doc: add a
section about output stability", 2018-11-07) the output is not meant
to be stable. So this regression test will likely need to be tweaked
once we get a "proper" --stat option.

See
https://public-inbox.org/git/nycvar.QRO.7.76.6.1811071202480.39@tvgsbejvaqbjf.bet/
for a further explanation of the regression. The fix here is not the
same as in Johannes's on-list patch, for reasons that'll be explained
in a follow-up commit.

The quoting of "EOF" here mirrors that of an earlier test. Perhaps
that should be fixed, but let's leave that up to a later cleanup
change.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
range-diff.c
t/t3206-range-diff.sh
index 3dd2edda0176b326d5980cbe1e37f3a8eec6a2f7..1e72928f0274b3d4b99807c2a4d6ce8f86426150 100644 (file)
@@ -433,7 +433,7 @@ int show_range_diff(const char *range1, const char *range2,
                struct strbuf indent = STRBUF_INIT;
 
                memcpy(&opts, diffopt, sizeof(opts));
-               opts.output_format = DIFF_FORMAT_PATCH;
+               opts.output_format |= DIFF_FORMAT_PATCH;
                opts.flags.suppress_diff_headers = 1;
                opts.flags.dual_color_diffed_diffs = dual_color;
                opts.output_prefix = output_prefix_cb;
index 3d7a2d8a4d8191f93a70b2e3d4878537cd2c5564..08b0fddf24f0e1520e4e0a9d8bb7731b81ba5eff 100755 (executable)
@@ -122,6 +122,59 @@ test_expect_success 'changed commit' '
        test_cmp expected actual
 '
 
+test_expect_success 'changed commit with --no-patch diff option' '
+       git range-diff --no-color --no-patch topic...changed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  a4b3333 s/5/A/
+       2:  fccce22 = 2:  f51d370 s/4/A/
+       3:  147e64e ! 3:  0559556 s/11/B/
+       4:  a63e992 ! 4:  d966c5c s/12/B/
+       EOF
+       test_cmp expected actual
+'
+
+test_expect_success 'changed commit with --stat diff option' '
+       four_spaces="    " &&
+       git range-diff --no-color --stat topic...changed >actual &&
+       cat >expected <<-EOF &&
+       1:  4de457d = 1:  a4b3333 s/5/A/
+            a => b | 0
+            1 file changed, 0 insertions(+), 0 deletions(-)
+       $four_spaces
+       2:  fccce22 = 2:  f51d370 s/4/A/
+            a => b | 0
+            1 file changed, 0 insertions(+), 0 deletions(-)
+       $four_spaces
+       3:  147e64e ! 3:  0559556 s/11/B/
+            a => b | 0
+            1 file changed, 0 insertions(+), 0 deletions(-)
+       $four_spaces
+           @@ -10,7 +10,7 @@
+             9
+             10
+            -11
+           -+B
+           ++BB
+             12
+             13
+             14
+       4:  a63e992 ! 4:  d966c5c s/12/B/
+            a => b | 0
+            1 file changed, 0 insertions(+), 0 deletions(-)
+       $four_spaces
+           @@ -8,7 +8,7 @@
+            @@
+             9
+             10
+           - B
+           + BB
+            -12
+            +B
+             13
+       EOF
+       test_cmp expected actual
+'
+
 test_expect_success 'changed message' '
        git range-diff --no-color topic...changed-message >actual &&
        sed s/Z/\ /g >expected <<-EOF &&