Skip to content

Commit 2a669c3

Browse files
newrengitster
authored andcommitted
merge-recursive: Avoid doubly merging rename/add conflict contents
When a commit moves A to B while another commit created B (or moved C to B), and these two different commits serve as different merge-bases for a later merge, c94736a (merge-recursive: don't segfault while handling rename clashes 2009-07-30) added some special code to avoid segfaults. Since that commit, the two versions of B are merged in place (which could be potentially conflicting) and the intermediate result is used as the virtual ancestor. However, right before this special merge, try_merge was turned on, meaning that process_renames() would try an alternative merge that ignores the 'add' part of the conflict, and, if the merge is clean, store that as the new virtual ancestor. This could cause incorrect merging of criss-cross merges; it would typically result in just recording a slightly confusing merge base, but in some cases it could cause silent acceptance of one side of a merge as the final resolution when a conflict should have been flagged. When we do a special merge for such a rename/add conflict between merge-bases, turn try_merge off to avoid an inappropriate second merge. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 61b8bca commit 2a669c3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

merge-recursive.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ static int process_renames(struct merge_options *o,
10611061
mfi.sha,
10621062
mfi.mode,
10631063
ren1_dst);
1064+
try_merge = 0;
10641065
} else {
10651066
new_path = unique_path(o, ren1_dst, branch2);
10661067
output(o, 1, "Adding as %s instead", new_path);

t/t6036-recursive-corner-cases.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ test_expect_success 'setup criss-cross + rename merges with basic modification'
120120
git tag R2
121121
'
122122

123-
test_expect_failure 'merge criss-cross + rename merges with basic modification' '
123+
test_expect_success 'merge criss-cross + rename merges with basic modification' '
124124
git reset --hard &&
125125
git checkout L2^0 &&
126126
@@ -202,7 +202,7 @@ test_expect_success 'setup differently handled merges of rename/add conflict' '
202202
git tag E
203203
'
204204

205-
test_expect_failure 'git detects differently handled merges conflict' '
205+
test_expect_success 'git detects differently handled merges conflict' '
206206
git reset --hard &&
207207
git checkout D^0 &&
208208

0 commit comments

Comments
 (0)