Skip to content

Commit 197cf8d

Browse files
committed
Merge branch 'jc/maint-1.6.0-diff-borrow-carefully' into maint
* jc/maint-1.6.0-diff-borrow-carefully: diff --cached: do not borrow from a work tree when a path is marked as assume-unchanged
2 parents 0122cf6 + 150115a commit 197cf8d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

diff.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,8 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
17591759
struct stat st;
17601760
int pos, len;
17611761

1762-
/* We do not read the cache ourselves here, because the
1762+
/*
1763+
* We do not read the cache ourselves here, because the
17631764
* benchmark with my previous version that always reads cache
17641765
* shows that it makes things worse for diff-tree comparing
17651766
* two linux-2.6 kernel trees in an already checked out work
@@ -1799,6 +1800,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
17991800
if (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode))
18001801
return 0;
18011802

1803+
/*
1804+
* If ce is marked as "assume unchanged", there is no
1805+
* guarantee that work tree matches what we are looking for.
1806+
*/
1807+
if (ce->ce_flags & CE_VALID)
1808+
return 0;
1809+
18021810
/*
18031811
* If ce matches the file in the work tree, we can reuse it.
18041812
*/

t/t4020-diff-external.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,12 @@ test_expect_success 'external diff with autocrlf = true' '
152152
test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c)
153153
'
154154

155+
test_expect_success 'diff --cached' '
156+
git add file &&
157+
git update-index --assume-unchanged file &&
158+
echo second >file &&
159+
git diff --cached >actual &&
160+
test_cmp ../t4020/diff.NUL actual
161+
'
162+
155163
test_done

0 commit comments

Comments
 (0)