git-p4: fix typos
[git/gitster.git] / t / t6427-diff3-conflict-markers.sh
bloba13271b34902bcca25cb78e273233d1300ee0a27
1 #!/bin/sh
3 test_description='recursive merge diff3 style conflict markers'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 # Setup:
12 # L1
13 # \
14 # ?
15 # /
16 # R1
18 # Where:
19 # L1 and R1 both have a file named 'content' but have no common history
22 test_expect_success 'setup no merge base' '
23 git init no_merge_base &&
25 cd no_merge_base &&
27 git checkout -b L &&
28 test_commit A content A &&
30 git checkout --orphan R &&
31 test_commit B content B
35 test_expect_success 'check no merge base' '
37 cd no_merge_base &&
39 git checkout L^0 &&
41 test_must_fail git -c merge.conflictstyle=diff3 merge --allow-unrelated-histories -s recursive R^0 &&
43 grep "|||||| empty tree" content
47 # Setup:
48 # L1
49 # / \
50 # main ?
51 # \ /
52 # R1
54 # Where:
55 # L1 and R1 have modified the same file ('content') in conflicting ways
58 test_expect_success 'setup unique merge base' '
59 git init unique_merge_base &&
61 cd unique_merge_base &&
63 test_commit base content "1
68 " &&
70 git branch L &&
71 git branch R &&
73 git checkout L &&
74 test_commit L content "1
79 7" &&
81 git checkout R &&
82 git rm content &&
83 test_commit R renamed "1
88 six"
92 test_expect_success 'check unique merge base' '
94 cd unique_merge_base &&
96 git checkout L^0 &&
97 MAIN=$(git rev-parse --short main) &&
99 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 &&
101 grep "|||||| $MAIN:content" renamed
105 # Setup:
106 # L1---L2--L3
107 # / \ / \
108 # main X1 ?
109 # \ / \ /
110 # R1---R2--R3
112 # Where:
113 # commits L1 and R1 have modified the same file in non-conflicting ways
114 # X1 is an auto-generated merge-base used when merging L1 and R1
115 # commits L2 and R2 are merges of R1 and L1 into L1 and R1, respectively
116 # commits L3 and R3 both modify 'content' in conflicting ways
119 test_expect_success 'setup multiple merge bases' '
120 git init multiple_merge_bases &&
122 cd multiple_merge_bases &&
124 test_commit initial content "1
128 5" &&
130 git branch L &&
131 git branch R &&
133 # Create L1
134 git checkout L &&
135 test_commit L1 content "0
140 5" &&
142 # Create R1
143 git checkout R &&
144 test_commit R1 content "1
149 6" &&
151 # Create L2
152 git checkout L &&
153 git merge R1 &&
155 # Create R2
156 git checkout R &&
157 git merge L1 &&
159 # Create L3
160 git checkout L &&
161 test_commit L3 content "0
167 A" &&
169 # Create R3
170 git checkout R &&
171 git rm content &&
172 test_commit R3 renamed "0
177 six"
181 test_expect_success 'check multiple merge bases' '
183 cd multiple_merge_bases &&
185 git checkout L^0 &&
187 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 &&
189 grep "|||||| merged common ancestors:content" renamed
193 test_expect_success 'rebase --merge describes parent of commit being picked' '
194 git init rebase &&
196 cd rebase &&
197 test_commit base file &&
198 test_commit main file &&
199 git checkout -b side HEAD^ &&
200 test_commit side file &&
201 test_must_fail git -c merge.conflictstyle=diff3 rebase --merge main &&
202 grep "||||||| parent of" file
206 test_expect_success 'rebase --apply describes fake ancestor base' '
208 cd rebase &&
209 git rebase --abort &&
210 test_must_fail git -c merge.conflictstyle=diff3 rebase --apply main &&
211 grep "||||||| constructed merge base" file
215 test_setup_zdiff3 () {
216 git init zdiff3 &&
218 cd zdiff3 &&
220 test_write_lines 1 2 3 4 5 6 7 8 9 >basic &&
221 test_write_lines 1 2 3 AA 4 5 BB 6 7 8 >middle-common &&
222 test_write_lines 1 2 3 4 5 6 7 8 9 >interesting &&
223 test_write_lines 1 2 3 4 5 6 7 8 9 >evil &&
225 git add basic middle-common interesting evil &&
226 git commit -m base &&
228 git branch left &&
229 git branch right &&
231 git checkout left &&
232 test_write_lines 1 2 3 4 A B C D E 7 8 9 >basic &&
233 test_write_lines 1 2 3 CC 4 5 DD 6 7 8 >middle-common &&
234 test_write_lines 1 2 3 4 A B C D E F G H I J 7 8 9 >interesting &&
235 test_write_lines 1 2 3 4 X A B C 7 8 9 >evil &&
236 git add -u &&
237 git commit -m letters &&
239 git checkout right &&
240 test_write_lines 1 2 3 4 A X C Y E 7 8 9 >basic &&
241 test_write_lines 1 2 3 EE 4 5 FF 6 7 8 >middle-common &&
242 test_write_lines 1 2 3 4 A B C 5 6 G H I J 7 8 9 >interesting &&
243 test_write_lines 1 2 3 4 Y A B C B C 7 8 9 >evil &&
244 git add -u &&
245 git commit -m permuted
249 test_expect_success 'check zdiff3 markers' '
250 test_setup_zdiff3 &&
252 cd zdiff3 &&
254 git checkout left^0 &&
256 base=$(git rev-parse --short HEAD^1) &&
257 test_must_fail git -c merge.conflictstyle=zdiff3 merge -s recursive right^0 &&
259 test_write_lines 1 2 3 4 A \
260 "<<<<<<< HEAD" B C D \
261 "||||||| $base" 5 6 \
262 ======= X C Y \
263 ">>>>>>> right^0" \
264 E 7 8 9 \
265 >expect &&
266 test_cmp expect basic &&
268 test_write_lines 1 2 3 \
269 "<<<<<<< HEAD" CC \
270 "||||||| $base" AA \
271 ======= EE \
272 ">>>>>>> right^0" \
273 4 5 \
274 "<<<<<<< HEAD" DD \
275 "||||||| $base" BB \
276 ======= FF \
277 ">>>>>>> right^0" \
278 6 7 8 \
279 >expect &&
280 test_cmp expect middle-common &&
282 test_write_lines 1 2 3 4 A B C \
283 "<<<<<<< HEAD" D E F \
284 "||||||| $base" 5 6 \
285 ======= 5 6 \
286 ">>>>>>> right^0" \
287 G H I J 7 8 9 \
288 >expect &&
289 test_cmp expect interesting &&
291 # Not passing this one yet; the common "B C" lines is still
292 # being left in the conflict blocks on the left and right
293 # sides.
294 test_write_lines 1 2 3 4 \
295 "<<<<<<< HEAD" X A \
296 "||||||| $base" 5 6 \
297 ======= Y A B C \
298 ">>>>>>> right^0" \
299 B C 7 8 9 \
300 >expect &&
301 test_cmp expect evil
305 test_done