mirror of
https://github.com/git/git.git
synced 2024-11-05 08:47:56 +01:00
5304810044
If we try to diff an index entry marked CE_VALID (because it
was marked with --assume-unchanged), we do not bother even
running stat() on the file to see if it was removed. This
started long ago with 540e694
(Prevent diff machinery from
examining assume-unchanged entries on worktree, 2009-08-11).
However, the subsequent code may look at our "struct stat"
and expect to find actual data; currently it will find
whatever cruft was left on the stack. This can cause
problems in two situations:
1. We call match_stat_with_submodule with the stat data,
so a submodule may be erroneously marked as changed.
2. If --find-copies-harder is in effect, we pass all
entries, even unchanged ones, to diff_change, so it can
list them as rename/copy sources. Since we found no
change, we assume that function will realize it and not
actually display any diff output. However, we end up
feeding it a bogus mode, leading it to sometimes claim
there was a mode change.
We can fix both by splitting the CE_VALID and regular code
paths, and making sure only to look at the stat information
in the latter. Furthermore, we push the declaration of our
"struct stat" down into the code paths that actually set it,
so we cannot accidentally access it uninitialized in future
code.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
42 lines
1 KiB
Bash
Executable file
42 lines
1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
test_description='diff with assume-unchanged entries'
|
|
|
|
. ./test-lib.sh
|
|
|
|
# external diff has been tested in t4020-diff-external.sh
|
|
|
|
test_expect_success 'setup' '
|
|
echo zero > zero &&
|
|
git add zero &&
|
|
git commit -m zero &&
|
|
echo one > one &&
|
|
echo two > two &&
|
|
git add one two &&
|
|
git commit -m onetwo &&
|
|
git update-index --assume-unchanged one &&
|
|
echo borked >> one &&
|
|
test "$(git ls-files -v one)" = "h one"
|
|
'
|
|
|
|
test_expect_success 'diff-index does not examine assume-unchanged entries' '
|
|
git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171
|
|
'
|
|
|
|
test_expect_success 'diff-files does not examine assume-unchanged entries' '
|
|
rm one &&
|
|
test -z "$(git diff-files -- one)"
|
|
'
|
|
|
|
test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits' '
|
|
echo content >exec &&
|
|
chmod +x exec &&
|
|
git add exec &&
|
|
git commit -m exec &&
|
|
git update-index --assume-unchanged exec &&
|
|
>expect &&
|
|
git diff-files --find-copies-harder -- exec >actual &&
|
|
test_cmp expect actual
|
|
'
|
|
|
|
test_done
|