Skip to content

Commit 751e165

Browse files
newrengitster
authored andcommitted
merge-ort: fix issue with dual rename and add/add conflict
There is code in both merge-recursive and merge-ort for avoiding doubly transitive renames (i.e. one side renames directory A/ -> B/, and the other side renames directory B/ -> C/), because this combination would otherwise make a mess for new files added to A/ on the first side and wondering which directory they end up in -- especially if there were even more renames such as the first side renaming C/ -> D/. In such cases, it just turns "off" directory rename detection for the higher order transitive cases. The testcases added in t6423 a couple commits ago are slightly different but similar in principle. They involve a similar case of paired renaming but instead of A/ -> B/ and B/ -> C/, the second side renames a leading directory of B/ to C/. And both sides add a new file somewhere under the directory that the other side will rename. While the new files added start within different directories and thus could logically end up within different directories, it is weird for a file on one side to end up where the other one started and not move along with it. So, let's just turn off directory rename detection in this case as well. Another way to look at this is that if the source name involved in a directory rename on one side is the target name of a directory rename operation for a file from the other side, then we avoid the doubly transitive rename. (More concretely, if a directory rename on side D wants to rename a file on side E from OLD_NAME -> NEW_NAME, and side D already had a file named NEW_NAME, and a directory rename on side E wants to rename side D's NEW_NAME -> NEWER_NAME, then we turn off the directory rename detection for NEW_NAME to prevent the NEW_NAME -> NEWER_NAME rename, and instead end up with an add/add conflict on NEW_NAME.) Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ffbe5a commit 751e165

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

merge-ort.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,10 +2292,16 @@ static char *check_for_directory_rename(struct merge_options *opt,
22922292
struct strmap_entry *rename_info;
22932293
struct strmap_entry *otherinfo;
22942294
const char *new_dir;
2295+
int other_side = 3 - side_index;
22952296

2296-
/* Cases where we don't have a directory rename for this path */
2297+
/*
2298+
* Cases where we don't have or don't want a directory rename for
2299+
* this path.
2300+
*/
22972301
if (strmap_empty(dir_renames))
22982302
return NULL;
2303+
if (strmap_get(&collisions[other_side], path))
2304+
return NULL;
22992305
rename_info = check_dir_renamed(path, dir_renames);
23002306
if (!rename_info)
23012307
return NULL;

t/t6423-merge-rename-directories.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5250,7 +5250,7 @@ test_setup_12l () {
52505250
)
52515251
}
52525252

5253-
test_expect_merge_algorithm failure failure '12l (B into A): Rename into each other + add/add conflict' '
5253+
test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' '
52545254
test_setup_12l BintoA &&
52555255
(
52565256
cd 12l_BintoA &&
@@ -5277,7 +5277,7 @@ test_expect_merge_algorithm failure failure '12l (B into A): Rename into each ot
52775277
)
52785278
'
52795279

5280-
test_expect_merge_algorithm failure failure '12l (A into B): Rename into each other + add/add conflict' '
5280+
test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' '
52815281
test_setup_12l AintoB &&
52825282
(
52835283
cd 12l_AintoB &&

0 commit comments

Comments
 (0)