]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/diff-I-status-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 18 Dec 2020 23:15:18 +0000 (15:15 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 18 Dec 2020 23:15:18 +0000 (15:15 -0800)
"git diff -I<pattern> -exit-code" should exit with 0 status when
all the changes match the ignored pattern, but it didn't.

* jc/diff-I-status-fix:
  diff: correct interaction between --exit-code and -I<pattern>

diff.c
t/t4015-diff-whitespace.sh

diff --git a/diff.c b/diff.c
index 643f4f3f6d02583ba74b81a5454ec89a79784161..2253ec880298b4f146cb20f6dbae365d77b8fdfe 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -4634,7 +4634,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 47f0e2889dade09889aa84558ac6567748799cdb..8c574221b27445938694163f90f90ce337bfc4e2 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 &&