Skip to content

Commit e8efd86

Browse files
committed
diff: teach "--stat -w --exit-code" to notice differences
When options like "-w" is used while "--exit-code" option is in effect, instead of the usual "do we have any filepair whose preimage and postimage have different <mode,object>?" check, we need to compare the contents of the blobs, taking into account that certain changes are considered no-op. With the previous step, we taught "--patch" codepath to set the .found_changes bit correctly, even for a change that only affects the mode and not object. The "--stat" codepath, however, did not set the .found_changes bit at all. This lead to $ git diff --stat -w --exit-code for a change that does have an output to exit with status 0. Set the bit by inspecting the list of paths the diffstat output is given for (a mode-only change will still appear as a "0-line added 0-line deleted" change) to fix it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent c9a3e72 commit e8efd86

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

diff.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6901,6 +6901,7 @@ void compute_diffstat(struct diff_options *options,
69016901
if (check_pair_status(p))
69026902
diff_flush_stat(p, options, diffstat);
69036903
}
6904+
options->found_changes = !!diffstat->nr;
69046905
}
69056906

69066907
void diff_addremove(struct diff_options *options,

t/t4015-diff-whitespace.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST_PASSES_SANITIZE_LEAK=true
1111
. ./test-lib.sh
1212
. "$TEST_DIRECTORY"/lib-diff.sh
1313

14-
for opts in --patch --quiet -s
14+
for opts in --patch --quiet -s --stat --shortstat --dirstat=lines
1515
do
1616

1717
test_expect_success "status with $opts (different)" '

0 commit comments

Comments
 (0)