Merge branch 'rs/diff-files-r-find-copies-fix'

"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
This commit is contained in:
Junio C Hamano
2025-12-23 11:33:16 +09:00
2 changed files with 31 additions and 4 deletions

View File

@@ -226,8 +226,12 @@ void run_diff_files(struct rev_info *revs, unsigned int option)
continue;
}
if (ce_uptodate(ce) || ce_skip_worktree(ce))
if (ce_uptodate(ce) || ce_skip_worktree(ce)) {
if (revs->diffopt.flags.find_copies_harder)
diff_same(&revs->diffopt, ce->ce_mode,
&ce->oid, ce->name);
continue;
}
/*
* 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)
if (!changed && !dirty_submodule) {
ce_mark_uptodate(ce);
mark_fsmonitor_valid(istate, ce);
if (!revs->diffopt.flags.find_copies_harder)
continue;
if (revs->diffopt.flags.find_copies_harder)
diff_same(&revs->diffopt, newmode,
&ce->oid, ce->name);
continue;
}
oldmode = ce->ce_mode;
old_oid = &ce->oid;

View File

@@ -67,7 +67,28 @@ test_expect_success 'copy, limited to a subtree' '
'
test_expect_success 'tweak work tree' '
rm -f path0/COPYING &&
rm -f path0/COPYING
'
cat >expected <<EOF
:100644 100644 $blob $blob C100 path1/COPYING path0/COPYING
EOF
# The cache has path0/COPYING and path1/COPYING, the working tree only
# path1/COPYING. This is a deletion -- we don't treat deduplication
# specially. In reverse it should be detected as a copy, though.
test_expect_success 'copy detection, files to index' '
git diff-files -C --find-copies-harder -R >current &&
compare_diff_raw current expected
'
test_expect_success 'copy detection, files to preloaded index' '
GIT_TEST_PRELOAD_INDEX=1 \
git diff-files -C --find-copies-harder -R >current &&
compare_diff_raw current expected
'
test_expect_success 'tweak index' '
git update-index --remove path0/COPYING
'
# In the tree, there is only path0/COPYING. In the cache, path0 does