diff: correct interaction between --exit-code and -I<pattern>
Just like "git diff -w --exit-code" should exit with 0 when ignoring whitespace differences results in no changes shown, if ignoring certain changes with "git diff -I<pattern> --exit-code" result in an empty patch, we should exit with 0. The test suite did not cover the interaction between "--exit-code" and "-w"; add one while adding a new test for "--exit-code" + "-I". Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Dec 16, 2020 at 17:27 UTC
50f04394908fe308a421b360951b1f73b00363ee
2 files changed
+26
-1
diff.c
+2
-1
@@ -4602,7 +4602,8 @@ void diff_setup_done(struct diff_options *options)
4602
* inside contents.
4603
*/
4604
4605
- if ((options->xdl_opts & XDF_WHITESPACE_FLAGS))
4605
+ if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
4606
+ options->ignore_regex_nr)
4607
options->flags.diff_from_contents = 1;
4608
else
4609
options->flags.diff_from_contents = 0;
t/t4015-diff-whitespace.sh
+24
@@ -567,6 +567,30 @@ test_expect_success '--check and --quiet are not exclusive' '
567
git diff --check --quiet
568
'
569
570
+test_expect_success '-w and --exit-code interact sensibly' '
571
+ test_when_finished "git checkout x" &&
572
+ {
573
+ test_seq 15 &&
574
+ echo " 16"
575
+ } >x &&
576
+ test_must_fail git diff --exit-code &&
577
+ git diff -w >actual &&
578
+ test_must_be_empty actual &&
579
+ git diff -w --exit-code
580
+'
581
+
582
+test_expect_success '-I and --exit-code interact sensibly' '
583
+ test_when_finished "git checkout x" &&
584
+ {
585
+ test_seq 15 &&
586
+ echo " 16"
587
+ } >x &&
588
+ test_must_fail git diff --exit-code &&
589
+ git diff -I. >actual &&
590
+ test_must_be_empty actual &&
591
+ git diff -I. --exit-code
592
+'
593
+
594
test_expect_success 'check staged with no whitespace errors' '
595
echo "foo();" >x &&
596
git add x &&