diff options
-rw-r--r-- | diff.c | 10 | ||||
-rwxr-xr-x | t/t4020-diff-external.sh | 8 |
2 files changed, 17 insertions, 1 deletions
@@ -1687,7 +1687,8 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int struct stat st; int pos, len; - /* We do not read the cache ourselves here, because the + /* + * We do not read the cache ourselves here, because the * benchmark with my previous version that always reads cache * shows that it makes things worse for diff-tree comparing * two linux-2.6 kernel trees in an already checked out work @@ -1728,6 +1729,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int return 0; /* + * If ce is marked as "assume unchanged", there is no + * guarantee that work tree matches what we are looking for. + */ + if (ce->ce_flags & CE_VALID) + return 0; + + /* * If ce matches the file in the work tree, we can reuse it. */ if (ce_uptodate(ce) || diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index 637b4e19d5..f853b8a894 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -107,4 +107,12 @@ test_expect_success 'force diff with "diff"' ' test_cmp ../t4020/diff.NUL actual ' +test_expect_success 'diff --cached' ' + git add file && + git update-index --assume-unchanged file && + echo second >file && + git diff --cached >actual && + test_cmp ../t4020/diff.NUL actual +' + test_done |