Skip to content

Commit 138249a

Browse files
committed
test: Add test that demands 3-way apply
This test case has a specially crafted patch that will only apply correctly when a 3-way merge is performed.
1 parent 1a2e780 commit 138249a

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

t/t3402-pick-3way.sh

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#!/bin/sh
2+
test_description='Test pick that requires 3-way application'
3+
4+
. ./test-lib.sh
5+
6+
# The base version of the file has two identical sections.
7+
cat > file <<EOF
8+
1
9+
2
10+
3
11+
4
12+
5
13+
6
14+
7
15+
8
16+
17+
1
18+
2
19+
3
20+
4
21+
5
22+
6
23+
7
24+
8
25+
26+
EOF
27+
test_expect_success \
28+
'Setup master branch' '
29+
git add file &&
30+
git commit -m "Add file" &&
31+
stg init
32+
'
33+
34+
test_expect_success \
35+
'Make another branch' '
36+
stg branch --create pickle
37+
'
38+
39+
# The pickle branch adds prefix lines file has two identical sections.
40+
# These prefix lines will confuse a non-3-way merge by making the hunk
41+
# context look like it should go with the first "1-8" section.
42+
cat > file <<EOF
43+
101
44+
102
45+
103
46+
104
47+
105
48+
106
49+
107
50+
108
51+
52+
1
53+
2
54+
3
55+
4
56+
5
57+
6
58+
7
59+
8
60+
61+
1
62+
2
63+
3
64+
4
65+
5
66+
6
67+
7
68+
8
69+
70+
EOF
71+
test_expect_success \
72+
'Add prefix lines in pickle branch' '
73+
stg new -rm muddy &&
74+
stg branch master
75+
'
76+
77+
# The master branch gets a tricky patch that inserts into the second
78+
# of the identical "1-8" sections.
79+
cat > file <<EOF
80+
1
81+
2
82+
3
83+
4
84+
5
85+
6
86+
7
87+
8
88+
89+
1
90+
2
91+
3
92+
4
93+
tricky change
94+
5
95+
6
96+
7
97+
8
98+
99+
EOF
100+
test_expect_success \
101+
'Make patch with tricky diff' '
102+
stg new -rm tricky
103+
'
104+
105+
# A 3-way merge will reach this correct merge result. Without a 3-way merge,
106+
# the "tricky change" will be inserted in the first 1-8 section.
107+
cat > expected <<EOF
108+
101
109+
102
110+
103
111+
104
112+
105
113+
106
114+
107
115+
108
116+
117+
1
118+
2
119+
3
120+
4
121+
5
122+
6
123+
7
124+
8
125+
126+
1
127+
2
128+
3
129+
4
130+
tricky change
131+
5
132+
6
133+
7
134+
8
135+
136+
EOF
137+
test_expect_success \
138+
'Pick and apply tricky patch' '
139+
stg branch pickle &&
140+
stg pick -B master tricky &&
141+
test_cmp expected file
142+
'
143+
144+
test_done

0 commit comments

Comments
 (0)