aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2025-12-23 11:33:16 +0900
committerJunio C Hamano <gitster@pobox.com>2025-12-23 11:33:16 +0900
commit5d2be7425cbfecac75211f47128e8aeab029e8b5 (patch)
tree5ec5a00a03130187d5c30b686291614a4015b575
parent86ebd83e6a78671624cf118e3a04d3afcfbe5df4 (diff)
parentf293bdcc29f91e3e56c478473a85a8e13e6fd87c (diff)
downloadgit-5d2be7425cbfecac75211f47128e8aeab029e8b5.tar.xz
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
-rw-r--r--diff-lib.c12
-rwxr-xr-xt/t4007-rename-3.sh23
2 files changed, 31 insertions, 4 deletions
diff --git a/diff-lib.c b/diff-lib.c
index 8e624f38c6..5307390ff3 100644
--- a/diff-lib.c
+++ b/diff-lib.c
@@ -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;
diff --git a/t/t4007-rename-3.sh b/t/t4007-rename-3.sh
index 3fc81bcd76..1012a370dd 100755
--- a/t/t4007-rename-3.sh
+++ b/t/t4007-rename-3.sh
@@ -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