Merge branch 'jc/diff-exit-code-with-w-fixes' into maint-2.42

"git diff -w --exit-code" with various options did not work
correctly, which is being addressed.

* jc/diff-exit-code-with-w-fixes:
  diff: the -w option breaks --exit-code for --raw and other output modes
  t4040: remove test that succeeded for a wrong reason
  diff: teach "--stat -w --exit-code" to notice differences
  diff: mode-only change should be noticed by "--patch -w --exit-code"
  diff: move the fallback "--exit-code" code down
This commit is contained in:
Junio C Hamano
2023-11-02 16:53:15 +09:00
3 changed files with 64 additions and 18 deletions

View File

@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright (c) 2006 Johannes E. Schindelin
#
# Copyright (c) 2023 Google LLC
test_description='Test special whitespace in diff engine.
@ -11,6 +11,43 @@ TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-diff.sh
for opt_res in --patch --quiet -s --stat --shortstat --dirstat=lines \
--raw! --name-only! --name-status!
do
opts=${opt_res%!} expect_failure=
test "$opts" = "$opt_res" ||
expect_failure="test_expect_code 1"
test_expect_success "status with $opts (different)" '
echo foo >x &&
git add x &&
echo bar >x &&
test_expect_code 1 git diff -w $opts --exit-code x
'
test_expect_success POSIXPERM "status with $opts (mode differs)" '
test_when_finished "git update-index --chmod=-x x" &&
echo foo >x &&
git add x &&
git update-index --chmod=+x x &&
test_expect_code 1 git diff -w $opts --exit-code x
'
test_expect_success "status with $opts (removing an empty file)" '
: >x &&
git add x &&
rm x &&
test_expect_code 1 git diff -w $opts --exit-code -- x
'
test_expect_success "status with $opts (different but equivalent)" '
echo foo >x &&
git add x &&
echo " foo" >x &&
$expect_failure git diff -w $opts --exit-code x
'
done
test_expect_success "Ray Lehtiniemi's example" '
cat <<-\EOF >x &&
do {

View File

@ -28,8 +28,7 @@ test_expect_success 'diff-tree --exit-code' '
test_expect_success 'diff-tree -b --exit-code' '
git diff -b --exit-code HEAD^ HEAD &&
git diff-tree -b -p --exit-code HEAD^ HEAD &&
git diff-tree -b --exit-code HEAD^ HEAD
git diff-tree -b -p --exit-code HEAD^ HEAD
'
test_expect_success 'diff-index --cached --exit-code' '