Skip to content

Commit aa72a14

Browse files
committed
Merge branch 'jc/maint-1.6.0-diff-borrow-carefully'
* 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 48bcfbd + 150115a commit aa72a14

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

diff.c

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

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

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

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)