Skip to content

Commit 07413c5

Browse files
newrengitster
authored andcommitted
merge-recursive: Move handling of double rename of one file to two
Move the handling of rename/rename conflicts where one file is renamed to two different files, from process_renames() to process_df_entry(). Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2a669c3 commit 07413c5

File tree

2 files changed

+42
-17
lines changed

2 files changed

+42
-17
lines changed

merge-recursive.c

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,11 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
855855
* update_file(o, 0, pair2->two->sha1, pair2->two->mode, dst_name2);
856856
*/
857857
} else {
858-
update_stages(dst_name1, NULL, pair1->two, NULL, 1);
859-
update_stages(dst_name2, NULL, NULL, pair2->two, 1);
858+
update_stages(ren1_dst, NULL, pair1->two, NULL, 1);
859+
update_stages(ren2_dst, NULL, NULL, pair2->two, 1);
860+
861+
update_file(o, 0, pair1->two->sha1, pair1->two->mode, dst_name1);
862+
update_file(o, 0, pair2->two->sha1, pair2->two->mode, dst_name2);
860863
}
861864
while (delp--)
862865
free(del[delp]);
@@ -958,19 +961,15 @@ static int process_renames(struct merge_options *o,
958961
ren2->dst_entry->processed = 1;
959962
ren2->processed = 1;
960963
if (strcmp(ren1_dst, ren2_dst) != 0) {
961-
clean_merge = 0;
962-
output(o, 1, "CONFLICT (rename/rename): "
963-
"Rename \"%s\"->\"%s\" in branch \"%s\" "
964-
"rename \"%s\"->\"%s\" in \"%s\"%s",
965-
src, ren1_dst, branch1,
966-
src, ren2_dst, branch2,
967-
o->call_depth ? " (left unresolved)": "");
968-
if (o->call_depth) {
969-
remove_file_from_cache(src);
970-
update_file(o, 0, ren1->pair->one->sha1,
971-
ren1->pair->one->mode, src);
972-
}
973-
conflict_rename_rename_1to2(o, ren1->pair, branch1, ren2->pair, branch2);
964+
setup_rename_df_conflict_info(RENAME_ONE_FILE_TO_TWO,
965+
ren1->pair,
966+
ren2->pair,
967+
branch1,
968+
branch2,
969+
ren1->dst_entry,
970+
ren2->dst_entry);
971+
remove_file(o, 0, ren1_dst, 0);
972+
/* ren2_dst not in head, so no need to delete */
974973
} else {
975974
struct merge_file_info mfi;
976975
remove_file(o, 1, ren1_src, 1);
@@ -1364,7 +1363,33 @@ static int process_df_entry(struct merge_options *o,
13641363

13651364
entry->processed = 1;
13661365
if (entry->rename_df_conflict_info) {
1367-
die("Not yet implemented.");
1366+
struct rename_df_conflict_info *conflict_info = entry->rename_df_conflict_info;
1367+
char *src;
1368+
switch (conflict_info->rename_type) {
1369+
case RENAME_ONE_FILE_TO_TWO:
1370+
src = conflict_info->pair1->one->path;
1371+
clean_merge = 0;
1372+
output(o, 1, "CONFLICT (rename/rename): "
1373+
"Rename \"%s\"->\"%s\" in branch \"%s\" "
1374+
"rename \"%s\"->\"%s\" in \"%s\"%s",
1375+
src, conflict_info->pair1->two->path, conflict_info->branch1,
1376+
src, conflict_info->pair2->two->path, conflict_info->branch2,
1377+
o->call_depth ? " (left unresolved)" : "");
1378+
if (o->call_depth) {
1379+
remove_file_from_cache(src);
1380+
update_file(o, 0, conflict_info->pair1->one->sha1,
1381+
conflict_info->pair1->one->mode, src);
1382+
}
1383+
conflict_rename_rename_1to2(o, conflict_info->pair1,
1384+
conflict_info->branch1,
1385+
conflict_info->pair2,
1386+
conflict_info->branch2);
1387+
conflict_info->dst_entry2->processed = 1;
1388+
break;
1389+
default:
1390+
entry->processed = 0;
1391+
break;
1392+
}
13681393
} else if (!o_sha && !!a_sha != !!b_sha) {
13691394
/* directory -> (directory, file) */
13701395
const char *add_branch;

t/t6022-merge-rename.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ test_expect_success 'setup rename of one file to two, with directories in the wa
652652
git commit -m "Put one/file in the way, rename to two"
653653
'
654654

655-
test_expect_failure 'check handling of differently renamed file with D/F conflicts' '
655+
test_expect_success 'check handling of differently renamed file with D/F conflicts' '
656656
git checkout -q first-rename^0 &&
657657
test_must_fail git merge --strategy=recursive second-rename &&
658658

0 commit comments

Comments
 (0)