Skip to content

Commit febb3a8

Browse files
newrengitster
authored andcommitted
merge-recursive: avoid spurious rename/rename conflict from dir renames
If a file on one side of history was renamed, and merely modified on the other side, then applying a directory rename to the modified side gives us a rename/rename(1to2) conflict. We should only apply directory renames to pairs representing either adds or renames. Making this change means that a directory rename testcase that was previously reported as a rename/delete conflict will now be reported as a modify/delete conflict. Reviewed-by: Stefan Beller <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f581e3 commit febb3a8

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

merge-recursive.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1982,7 +1982,7 @@ static void compute_collisions(struct hashmap *collisions,
19821982
char *new_path;
19831983
struct diff_filepair *pair = pairs->queue[i];
19841984

1985-
if (pair->status == 'D')
1985+
if (pair->status != 'A' && pair->status != 'R')
19861986
continue;
19871987
dir_rename_ent = check_dir_renamed(pair->two->path,
19881988
dir_renames);
@@ -2209,7 +2209,7 @@ static struct string_list *get_renames(struct merge_options *o,
22092209
struct diff_filepair *pair = pairs->queue[i];
22102210
char *new_path; /* non-NULL only with directory renames */
22112211

2212-
if (pair->status == 'D') {
2212+
if (pair->status != 'A' && pair->status != 'R') {
22132213
diff_free_filepair(pair);
22142214
continue;
22152215
}

t/t6043-merge-rename-directories.sh

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,18 +2078,23 @@ test_expect_success '8b-check: Dual-directory rename, one into the others way, w
20782078
)
20792079
'
20802080

2081-
# Testcase 8c, rename+modify/delete
2082-
# (Related to testcases 5b and 8d)
2081+
# Testcase 8c, modify/delete or rename+modify/delete?
2082+
# (Related to testcases 5b, 8d, and 9h)
20832083
# Commit O: z/{b,c,d}
20842084
# Commit A: y/{b,c}
20852085
# Commit B: z/{b,c,d_modified,e}
2086-
# Expected: y/{b,c,e}, CONFLICT(rename+modify/delete: x/d -> y/d or deleted)
2086+
# Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
20872087
#
2088-
# Note: This testcase doesn't present any concerns for me...until you
2089-
# compare it with testcases 5b and 8d. See notes in 8d for more
2090-
# details.
2091-
2092-
test_expect_success '8c-setup: rename+modify/delete' '
2088+
# Note: It could easily be argued that the correct resolution here is
2089+
# y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2090+
# and that the modifed version of d should be present in y/ after
2091+
# the merge, just marked as conflicted. Indeed, I previously did
2092+
# argue that. But applying directory renames to the side of
2093+
# history where a file is merely modified results in spurious
2094+
# rename/rename(1to2) conflicts -- see testcase 9h. See also
2095+
# notes in 8d.
2096+
2097+
test_expect_success '8c-setup: modify/delete or rename+modify/delete?' '
20932098
test_create_repo 8c &&
20942099
(
20952100
cd 8c &&
@@ -2122,32 +2127,32 @@ test_expect_success '8c-setup: rename+modify/delete' '
21222127
)
21232128
'
21242129

2125-
test_expect_success '8c-check: rename+modify/delete' '
2130+
test_expect_success '8c-check: modify/delete or rename+modify/delete' '
21262131
(
21272132
cd 8c &&
21282133
21292134
git checkout A^0 &&
21302135
21312136
test_must_fail git merge -s recursive B^0 >out &&
2132-
test_i18ngrep "CONFLICT (rename/delete).* z/d.*y/d" out &&
2137+
test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
21332138
21342139
git ls-files -s >out &&
2135-
test_line_count = 4 out &&
2140+
test_line_count = 5 out &&
21362141
git ls-files -u >out &&
2137-
test_line_count = 1 out &&
2142+
test_line_count = 2 out &&
21382143
git ls-files -o >out &&
21392144
test_line_count = 1 out &&
21402145
21412146
git rev-parse >actual \
2142-
:0:y/b :0:y/c :0:y/e :3:y/d &&
2147+
:0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
21432148
git rev-parse >expect \
2144-
O:z/b O:z/c B:z/e B:z/d &&
2149+
O:z/b O:z/c B:z/e O:z/d B:z/d &&
21452150
test_cmp expect actual &&
21462151
2147-
test_must_fail git rev-parse :1:y/d &&
2148-
test_must_fail git rev-parse :2:y/d &&
2149-
git ls-files -s y/d | grep ^100755 &&
2150-
test_path_is_file y/d
2152+
test_must_fail git rev-parse :2:z/d &&
2153+
git ls-files -s z/d | grep ^100755 &&
2154+
test_path_is_file z/d &&
2155+
test_path_is_missing y/d
21512156
)
21522157
'
21532158

@@ -2161,16 +2166,6 @@ test_expect_success '8c-check: rename+modify/delete' '
21612166
#
21622167
# Note: It would also be somewhat reasonable to resolve this as
21632168
# y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2164-
# The logic being that the only difference between this testcase and 8c
2165-
# is that there is no modification to d. That suggests that instead of a
2166-
# rename/modify vs. delete conflict, we should just have a rename/delete
2167-
# conflict, otherwise we are being inconsistent.
2168-
#
2169-
# However...as far as consistency goes, we didn't report a conflict for
2170-
# path d_1 in testcase 5b due to a different file being in the way. So,
2171-
# we seem to be forced to have cases where users can change things
2172-
# slightly and get what they may perceive as inconsistent results. It
2173-
# would be nice to avoid that, but I'm not sure I see how.
21742169
#
21752170
# In this case, I'm leaning towards: commit A was the one that deleted z/d
21762171
# and it did the rename of z to y, so the two "conflicts" (rename vs.
@@ -2915,7 +2910,7 @@ test_expect_success '9h-setup: Avoid dir rename on merely modified path' '
29152910
)
29162911
'
29172912

2918-
test_expect_failure '9h-check: Avoid dir rename on merely modified path' '
2913+
test_expect_success '9h-check: Avoid dir rename on merely modified path' '
29192914
(
29202915
cd 9h &&
29212916
@@ -3959,7 +3954,7 @@ test_expect_success '12c-setup: Moving one directory hierarchy into another w/ c
39593954
)
39603955
'
39613956

3962-
test_expect_failure '12c-check: Moving one directory hierarchy into another w/ content merge' '
3957+
test_expect_success '12c-check: Moving one directory hierarchy into another w/ content merge' '
39633958
(
39643959
cd 12c &&
39653960

0 commit comments

Comments
 (0)