]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff: correct interaction between --exit-code and -I<pattern>
authorJunio C Hamano <gitster@pobox.com>
Thu, 17 Dec 2020 01:27:13 +0000 (17:27 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Dec 2020 01:33:26 +0000 (17:33 -0800)
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>
diff.c
t/t4015-diff-whitespace.sh

diff --git a/diff.c b/diff.c
index 92e247fb83e0f24862ad829e78bd190794db547d..e162d59eaeb776035221b6ddef38975f1a9290ea 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4602,7 +4602,8 @@ void diff_setup_done(struct diff_options *options)
         * inside contents.
         */
 
-       if ((options->xdl_opts & XDF_WHITESPACE_FLAGS))
+       if ((options->xdl_opts & XDF_WHITESPACE_FLAGS) ||
+           options->ignore_regex_nr)
                options->flags.diff_from_contents = 1;
        else
                options->flags.diff_from_contents = 0;
index 88d3026894f87f4d86cb6f4178898b6879630e73..8ae02fe3c3155617432f2c56ddefe06d5dd33c1e 100755 (executable)
@@ -567,6 +567,30 @@ test_expect_success '--check and --quiet are not exclusive' '
        git diff --check --quiet
 '
 
+test_expect_success '-w and --exit-code interact sensibly' '
+       test_when_finished "git checkout x" &&
+       {
+               test_seq 15 &&
+               echo " 16"
+       } >x &&
+       test_must_fail git diff --exit-code &&
+       git diff -w >actual &&
+       test_must_be_empty actual &&
+       git diff -w --exit-code
+'
+
+test_expect_success '-I and --exit-code interact sensibly' '
+       test_when_finished "git checkout x" &&
+       {
+               test_seq 15 &&
+               echo " 16"
+       } >x &&
+       test_must_fail git diff --exit-code &&
+       git diff -I. >actual &&
+       test_must_be_empty actual &&
+       git diff -I. --exit-code
+'
+
 test_expect_success 'check staged with no whitespace errors' '
        echo "foo();" >x &&
        git add x &&