merge-recursive: Fix virtual merge base for rename/rename(1to2)/add-dest

Earlier in this series, the patch "merge-recursive: add handling for rename/rename/add-dest/add-dest" added code to handle the rename on each side of history also being involved in a rename/add conflict, but only did so in the non-recursive case. Add code for the recursive case, ensuring that the "added" files are not simply deleted. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Aug 11, 2011 at 23:20 UTC 6d63070cacf88cd03b4bc73fd64fea046accd450
2 files changed +22 -3
merge-recursive.c
+21 -2
@@ -1159,6 +1159,8 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1159 o->call_depth ? " (left unresolved)" : "");
1160 if (o->call_depth) {
1161 struct merge_file_info mfi;
1162 + struct diff_filespec other;
1163 + struct diff_filespec *add;
1164 mfi = merge_file(o, one->path,
1165 one->sha1, one->mode,
1166 a->sha1, a->mode,
@@ -1171,8 +1173,25 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
1173 * unique path, or use that unique path instead of src here.
1174 */
1175 update_file(o, 0, mfi.sha, mfi.mode, one->path);
1174 - remove_file_from_cache(a->path);
1175 - remove_file_from_cache(b->path);
1176 +
1177 + /*
1178 + * Above, we put the merged content at the merge-base's
1179 + * path. Now we usually need to delete both a->path and
1180 + * b->path. However, the rename on each side of the merge
1181 + * could also be involved in a rename/add conflict. In
1182 + * such cases, we should keep the added file around,
1183 + * resolving the conflict at that path in its favor.
1184 + */
1185 + add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1186 + if (add)
1187 + update_file(o, 0, add->sha1, add->mode, a->path);
1188 + else
1189 + remove_file_from_cache(a->path);
1190 + add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1191 + if (add)
1192 + update_file(o, 0, add->sha1, add->mode, b->path);
1193 + else
1194 + remove_file_from_cache(b->path);
1195 } else {
1196 handle_file(o, a, 2, ci);
1197 handle_file(o, b, 3, ci);
t/t6036-recursive-corner-cases.sh
+1 -1
@@ -760,7 +760,7 @@ test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' '
760 git tag E
761 '
762
763 -test_expect_failure 'virtual merge base handles rename/rename(1to2)/add-dest' '
763 +test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
764 git checkout D^0 &&
765
766 git merge -s recursive E^0 &&