2011-05-28 06:50:39 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright (c) 2011, Google Inc.
|
|
|
|
|
|
|
|
test_description='diff --stat-count'
|
2021-10-31 00:24:19 +02:00
|
|
|
|
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2011-05-28 06:50:39 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2012-11-27 21:55:00 +01:00
|
|
|
test_expect_success 'setup' '
|
2011-05-28 06:50:39 +02:00
|
|
|
>a &&
|
|
|
|
>b &&
|
|
|
|
>c &&
|
|
|
|
>d &&
|
|
|
|
git add a b c d &&
|
2012-11-27 21:55:00 +01:00
|
|
|
git commit -m initial
|
|
|
|
'
|
|
|
|
|
2012-11-29 18:46:30 +01:00
|
|
|
test_expect_success 'mode-only change show as a 0-line change' '
|
2012-11-27 21:55:00 +01:00
|
|
|
git reset --hard &&
|
2012-11-29 18:46:30 +01:00
|
|
|
test_chmod +x b d &&
|
2011-05-28 06:50:39 +02:00
|
|
|
echo a >a &&
|
2012-11-29 18:46:30 +01:00
|
|
|
echo c >c &&
|
2015-03-20 11:07:15 +01:00
|
|
|
cat >expect <<-\EOF &&
|
2012-04-30 22:38:58 +02:00
|
|
|
a | 1 +
|
2012-11-29 18:46:30 +01:00
|
|
|
b | 0
|
Fix "git diff --stat" for interesting - but empty - file changes
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>
2012-10-17 19:00:37 +02:00
|
|
|
...
|
|
|
|
4 files changed, 2 insertions(+)
|
2011-05-28 06:50:39 +02:00
|
|
|
EOF
|
2012-11-29 18:46:30 +01:00
|
|
|
git diff --stat --stat-count=2 HEAD >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual
|
2011-05-28 06:50:39 +02:00
|
|
|
'
|
|
|
|
|
2012-11-27 20:47:46 +01:00
|
|
|
test_expect_success 'binary changes do not count in lines' '
|
2012-11-27 21:55:00 +01:00
|
|
|
git reset --hard &&
|
|
|
|
echo a >a &&
|
2012-11-29 18:46:30 +01:00
|
|
|
echo c >c &&
|
2012-11-27 21:55:00 +01:00
|
|
|
cat "$TEST_DIRECTORY"/test-binary-1.png >d &&
|
2015-03-20 11:07:15 +01:00
|
|
|
cat >expect <<-\EOF &&
|
2012-11-27 21:55:00 +01:00
|
|
|
a | 1 +
|
2012-11-29 18:46:30 +01:00
|
|
|
c | 1 +
|
2012-11-27 21:55:00 +01:00
|
|
|
...
|
2012-11-29 18:46:30 +01:00
|
|
|
3 files changed, 2 insertions(+)
|
2012-11-27 21:55:00 +01:00
|
|
|
EOF
|
|
|
|
git diff --stat --stat-count=2 >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual
|
2012-11-27 21:55:00 +01:00
|
|
|
'
|
|
|
|
|
2012-11-27 21:05:10 +01:00
|
|
|
test_expect_success 'exclude unmerged entries from total file count' '
|
2012-11-27 21:55:00 +01:00
|
|
|
git reset --hard &&
|
|
|
|
echo a >a &&
|
|
|
|
echo b >b &&
|
|
|
|
git ls-files -s a >x &&
|
|
|
|
git rm -f d &&
|
|
|
|
for stage in 1 2 3
|
|
|
|
do
|
2021-12-09 06:11:13 +01:00
|
|
|
sed -e "s/ 0 a/ $stage d/" x || return 1
|
2012-11-27 21:55:00 +01:00
|
|
|
done |
|
|
|
|
git update-index --index-info &&
|
|
|
|
echo d >d &&
|
2015-03-20 11:07:15 +01:00
|
|
|
cat >expect <<-\EOF &&
|
2012-11-27 21:55:00 +01:00
|
|
|
a | 1 +
|
|
|
|
b | 1 +
|
|
|
|
...
|
2012-11-29 18:46:30 +01:00
|
|
|
3 files changed, 3 insertions(+)
|
2012-11-27 21:55:00 +01:00
|
|
|
EOF
|
|
|
|
git diff --stat --stat-count=2 >actual &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expect actual
|
2012-11-27 21:55:00 +01:00
|
|
|
'
|
|
|
|
|
2011-05-28 06:50:39 +02:00
|
|
|
test_done
|