mirror of
https://github.com/git/git.git
synced 2024-12-14 20:33:46 +08:00
74faaa16f0
The behavior of "git diff --stat" is rather odd for files that have zero lines of changes: it will discount them entirely unless they were renames. Which means that the stat output will simply not show files that only had "other" changes: they were created or deleted, or their mode was changed. Now, those changes do show up in the summary, but so do renames, so the diffstat logic is inconsistent. Why does it show renames with zero lines changed, but not mode changes or added files with zero lines changed? So change the logic to not check for "is_renamed", but for "is_interesting" instead, where "interesting" is judged to be any action but a pure data change (because a pure data change with zero data changed really isn't worth showing, if we ever get one in our diffpairs). So if you did chmod +x Makefile git diff --stat before, it would show empty (" 0 files changed"), with this it shows Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) which I think is a more correct diffstat (and then with "--summary" it shows *what* the metadata change to Makefile was - this is completely consistent with our handling of renamed files). Side note: the old behavior was *really* odd. With no changes at all, "git diff --stat" output was empty. With just a chmod, it said "0 files changed". No way is our legacy behavior sane. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
60 lines
1.3 KiB
Bash
Executable File
60 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
#
|
|
|
|
test_description='Test mode change diffs.
|
|
|
|
'
|
|
. ./test-lib.sh
|
|
|
|
sed_script='s/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /'
|
|
|
|
test_expect_success 'setup' '
|
|
echo frotz >rezrov &&
|
|
git update-index --add rezrov &&
|
|
tree=`git write-tree` &&
|
|
echo $tree
|
|
'
|
|
|
|
test_expect_success 'chmod' '
|
|
test_chmod +x rezrov &&
|
|
git diff-index $tree >current &&
|
|
sed -e "$sed_script" <current >check &&
|
|
echo ":100644 100755 X X M rezrov" >expected &&
|
|
test_cmp expected check
|
|
'
|
|
|
|
test_expect_success 'prepare binary file' '
|
|
git commit -m rezrov &&
|
|
printf "\00\01\02\03\04\05\06" >binbin &&
|
|
git add binbin &&
|
|
git commit -m binbin
|
|
'
|
|
|
|
# test_expect_success '--stat output after text chmod' '
|
|
# test_chmod -x rezrov &&
|
|
# echo " 0 files changed" >expect &&
|
|
# git diff HEAD --stat >actual &&
|
|
# test_i18ncmp expect actual
|
|
# '
|
|
#
|
|
# test_expect_success '--shortstat output after text chmod' '
|
|
# git diff HEAD --shortstat >actual &&
|
|
# test_i18ncmp expect actual
|
|
# '
|
|
#
|
|
# test_expect_success '--stat output after binary chmod' '
|
|
# test_chmod +x binbin &&
|
|
# echo " 0 files changed" >expect &&
|
|
# git diff HEAD --stat >actual &&
|
|
# test_i18ncmp expect actual
|
|
# '
|
|
#
|
|
# test_expect_success '--shortstat output after binary chmod' '
|
|
# git diff HEAD --shortstat >actual &&
|
|
# test_i18ncmp expect actual
|
|
# '
|
|
|
|
test_done
|