Skip to content

Commit c5b761f

Browse files
newrengitster
authored andcommitted
merge-recursive: ensure we write updates for directory-renamed file
When a file is present in HEAD before the merge and the other side of the merge does not modify that file, we try to avoid re-writing the file and making it stat-dirty. However, when a file is present in HEAD before the merge and was in a directory that was renamed by the other side of the merge, we have to move the file to a new location and re-write it. Update the code that checks whether we can skip the update to also work in the presence of directory renames. Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent febb3a8 commit c5b761f

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

merge-recursive.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,16 +2763,14 @@ static int merge_content(struct merge_options *o,
27632763

27642764
if (mfi.clean && !df_conflict_remains &&
27652765
oid_eq(&mfi.oid, a_oid) && mfi.mode == a_mode) {
2766-
int path_renamed_outside_HEAD;
27672766
output(o, 3, _("Skipped %s (merged same as existing)"), path);
27682767
/*
27692768
* The content merge resulted in the same file contents we
27702769
* already had. We can return early if those file contents
27712770
* are recorded at the correct path (which may not be true
27722771
* if the merge involves a rename).
27732772
*/
2774-
path_renamed_outside_HEAD = !path2 || !strcmp(path, path2);
2775-
if (!path_renamed_outside_HEAD) {
2773+
if (was_tracked(path)) {
27762774
add_cacheinfo(o, mfi.mode, &mfi.oid, path,
27772775
0, (!o->call_depth), 0);
27782776
return mfi.clean;

t/t6043-merge-rename-directories.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3884,7 +3884,7 @@ test_expect_success '12b-setup: Moving one directory hierarchy into another' '
38843884
)
38853885
'
38863886

3887-
test_expect_failure '12b-check: Moving one directory hierarchy into another' '
3887+
test_expect_success '12b-check: Moving one directory hierarchy into another' '
38883888
(
38893889
cd 12b &&
38903890

0 commit comments

Comments
 (0)