Skip to content

Commit bf74106

Browse files
cxreggitster
authored andcommitted
merge-recursive: never leave index unmerged while recursing
When you are trying to come up with the final result (i.e. depth=0), you want to record how the conflict arose by registering the state of the common ancestor, your branch and the other branch in the index, hence you want to do update_stages(). When you are merging with positive depth, that is because of a criss-cross merge situation. In such a case, you would need to record the tentative result, with conflict markers and all, as if the merge went cleanly, even if there are conflicts, in order to write it out as a tree object later to be used as a common ancestor tree. update_file() calls update_file_flags() with update_cache=1 to signal that the result needs to be written to the index at stage #0 (i.e. merged), and the code should not clobber the index further by calling update_stages(). The codepath to deal with rename/delete conflict in a recursive merge however left the index unmerged. Signed-off-by: Dave Olszewski <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a48f5d7 commit bf74106

File tree

2 files changed

+101
-5
lines changed

2 files changed

+101
-5
lines changed

merge-recursive.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,12 @@ static int process_renames(struct merge_options *o,
934934
ren1_src, ren1_dst, branch1,
935935
branch2);
936936
update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
937-
update_stages(ren1_dst, NULL,
938-
branch1 == o->branch1 ?
939-
ren1->pair->two : NULL,
940-
branch1 == o->branch1 ?
941-
NULL : ren1->pair->two, 1);
937+
if (!o->call_depth)
938+
update_stages(ren1_dst, NULL,
939+
branch1 == o->branch1 ?
940+
ren1->pair->two : NULL,
941+
branch1 == o->branch1 ?
942+
NULL : ren1->pair->two, 1);
942943
} else if (!sha_eq(dst_other.sha1, null_sha1)) {
943944
const char *new_path;
944945
clean_merge = 0;

t/t3031-merge-criscross.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
3+
test_description='merge-recursive backend test'
4+
5+
. ./test-lib.sh
6+
7+
# A <- create some files
8+
# / \
9+
# B C <- cause rename/delete conflicts between B and C
10+
# / \
11+
# |\ /|
12+
# | D E |
13+
# | \ / |
14+
# | X |
15+
# | / \ |
16+
# | / \ |
17+
# |/ \|
18+
# F G <- merge E into B, D into C
19+
# \ /
20+
# \ /
21+
# \ /
22+
# H <- recursive merge crashes
23+
#
24+
25+
# initialize
26+
test_expect_success 'setup repo with criss-cross history' '
27+
mkdir data &&
28+
29+
# create a bunch of files
30+
n=1 &&
31+
while test $n -le 10
32+
do
33+
echo $n > data/$n &&
34+
n=$(($n+1)) ||
35+
break
36+
done &&
37+
38+
# check them in
39+
git add data &&
40+
git commit -m A &&
41+
git branch A &&
42+
43+
# a file in one branch
44+
git checkout -b B A &&
45+
git rm data/9 &&
46+
git add data &&
47+
git commit -m B &&
48+
49+
# with a branch off of it
50+
git branch D &&
51+
52+
# put some commits on D
53+
git checkout D &&
54+
echo testD > data/testD &&
55+
git add data &&
56+
git commit -m D &&
57+
58+
# back up to the top, create another branch and cause
59+
# a rename conflict with the file we deleted earlier
60+
git checkout -b C A &&
61+
git mv data/9 data/new-9 &&
62+
git add data &&
63+
git commit -m C &&
64+
65+
# with a branch off of it
66+
git branch E &&
67+
68+
# put a commit on E
69+
git checkout E &&
70+
echo testE > data/testE &&
71+
git add data &&
72+
git commit -m E &&
73+
74+
# now, merge E into B
75+
git checkout B &&
76+
test_must_fail git merge E &&
77+
# force-resolve
78+
git add data &&
79+
git commit -m F &&
80+
git branch F &&
81+
82+
# and merge D into C
83+
git checkout C &&
84+
test_must_fail git merge D &&
85+
# force-resolve
86+
git add data &&
87+
git commit -m G &&
88+
git branch G
89+
'
90+
91+
test_expect_success 'recursive merge between F and G, causes segfault' '
92+
git merge F
93+
'
94+
95+
test_done

0 commit comments

Comments
 (0)