Skip to content

Commit 3f3e2c2

Browse files
committed
Merge branch 'jc/maint-1.6.0-diff-borrow-carefully' into maint-1.6.1
* 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 652f0c8 + 150115a commit 3f3e2c2

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
@@ -1649,7 +1649,8 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
16491649
struct stat st;
16501650
int pos, len;
16511651

1652-
/* We do not read the cache ourselves here, because the
1652+
/*
1653+
* We do not read the cache ourselves here, because the
16531654
* benchmark with my previous version that always reads cache
16541655
* shows that it makes things worse for diff-tree comparing
16551656
* two linux-2.6 kernel trees in an already checked out work
@@ -1689,6 +1690,13 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int
16891690
if (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode))
16901691
return 0;
16911692

1693+
/*
1694+
* If ce is marked as "assume unchanged", there is no
1695+
* guarantee that work tree matches what we are looking for.
1696+
*/
1697+
if (ce->ce_flags & CE_VALID)
1698+
return 0;
1699+
16921700
/*
16931701
* If ce matches the file in the work tree, we can reuse it.
16941702
*/

t/t4020-diff-external.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,12 @@ test_expect_success 'force diff with "diff"' '
128128
test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual
129129
'
130130

131+
test_expect_success 'diff --cached' '
132+
git add file &&
133+
git update-index --assume-unchanged file &&
134+
echo second >file &&
135+
git diff --cached >actual &&
136+
test_cmp ../t4020/diff.NUL actual
137+
'
138+
131139
test_done

0 commit comments

Comments
 (0)