Skip to content

Commit 2c9d72e

Browse files
committed
Merge branch 'rs/diff-files-r-find-copies-fix' into next
"git diff-files -R --find-copies-harder" has been taught to use the potential copy sources from the index correctly. * rs/diff-files-r-find-copies-fix: diff-files: fix copy detection
2 parents 0dd398f + f293bdc commit 2c9d72e

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

diff-lib.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,12 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
226226
continue;
227227
}
228228

229-
if (ce_uptodate(ce) || ce_skip_worktree(ce))
229+
if (ce_uptodate(ce) || ce_skip_worktree(ce)) {
230+
if (revs->diffopt.flags.find_copies_harder)
231+
diff_same(&revs->diffopt, ce->ce_mode,
232+
&ce->oid, ce->name);
230233
continue;
234+
}
231235

232236
/*
233237
* When CE_VALID is set (via "update-index --assume-unchanged"
@@ -272,8 +276,10 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
272276
if (!changed && !dirty_submodule) {
273277
ce_mark_uptodate(ce);
274278
mark_fsmonitor_valid(istate, ce);
275-
if (!revs->diffopt.flags.find_copies_harder)
276-
continue;
279+
if (revs->diffopt.flags.find_copies_harder)
280+
diff_same(&revs->diffopt, newmode,
281+
&ce->oid, ce->name);
282+
continue;
277283
}
278284
oldmode = ce->ce_mode;
279285
old_oid = &ce->oid;

t/t4007-rename-3.sh

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,28 @@ test_expect_success 'copy, limited to a subtree' '
6767
'
6868

6969
test_expect_success 'tweak work tree' '
70-
rm -f path0/COPYING &&
70+
rm -f path0/COPYING
71+
'
72+
73+
cat >expected <<EOF
74+
:100644 100644 $blob $blob C100 path1/COPYING path0/COPYING
75+
EOF
76+
77+
# The cache has path0/COPYING and path1/COPYING, the working tree only
78+
# path1/COPYING. This is a deletion -- we don't treat deduplication
79+
# specially. In reverse it should be detected as a copy, though.
80+
test_expect_success 'copy detection, files to index' '
81+
git diff-files -C --find-copies-harder -R >current &&
82+
compare_diff_raw current expected
83+
'
84+
85+
test_expect_success 'copy detection, files to preloaded index' '
86+
GIT_TEST_PRELOAD_INDEX=1 \
87+
git diff-files -C --find-copies-harder -R >current &&
88+
compare_diff_raw current expected
89+
'
90+
91+
test_expect_success 'tweak index' '
7192
git update-index --remove path0/COPYING
7293
'
7394
# In the tree, there is only path0/COPYING. In the cache, path0 does

0 commit comments

Comments
 (0)