Skip to content

Commit 5c44cc9

Browse files
committed
Merge branch 'do/maint-merge-recursive-fix' into maint
* do/maint-merge-recursive-fix: merge-recursive: never leave index unmerged while recursing
2 parents 4176537 + bf74106 commit 5c44cc9

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
@@ -933,11 +933,12 @@ static int process_renames(struct merge_options *o,
933933
ren1_src, ren1_dst, branch1,
934934
branch2);
935935
update_file(o, 0, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
936-
update_stages(ren1_dst, NULL,
937-
branch1 == o->branch1 ?
938-
ren1->pair->two : NULL,
939-
branch1 == o->branch1 ?
940-
NULL : ren1->pair->two, 1);
936+
if (!o->call_depth)
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);
941942
} else if (!sha_eq(dst_other.sha1, null_sha1)) {
942943
const char *new_path;
943944
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)