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
18 # L1 and R1 both have a file named 'content' but have no common history
21 test_expect_success
'setup no merge base' '
22 test_create_repo no_merge_base &&
27 test_commit A content A &&
29 git checkout --orphan R &&
30 test_commit B content B
34 test_expect_success
'check no merge base' '
40 test_must_fail git -c merge.conflictstyle=diff3 merge --allow-unrelated-histories -s recursive R^0 &&
42 grep "|||||| empty tree" content
54 # L1 and R1 have modified the same file ('content') in conflicting ways
57 test_expect_success
'setup unique merge base' '
58 test_create_repo unique_merge_base &&
60 cd unique_merge_base &&
62 test_commit base content "1
73 test_commit L content "1
82 test_commit R renamed "1
91 test_expect_success
'check unique merge base' '
93 cd unique_merge_base &&
96 MAIN=$(git rev-parse --short main) &&
98 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 &&
100 grep "|||||| $MAIN:content" renamed
112 # commits L1 and R1 have modified the same file in non-conflicting ways
113 # X1 is an auto-generated merge-base used when merging L1 and R1
114 # commits L2 and R2 are merges of R1 and L1 into L1 and R1, respectively
115 # commits L3 and R3 both modify 'content' in conflicting ways
118 test_expect_success
'setup multiple merge bases' '
119 test_create_repo multiple_merge_bases &&
121 cd multiple_merge_bases &&
123 test_commit initial content "1
134 test_commit L1 content "0
143 test_commit R1 content "1
160 test_commit L3 content "0
171 test_commit R3 renamed "0
180 test_expect_success
'check multiple merge bases' '
182 cd multiple_merge_bases &&
186 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 &&
188 grep "|||||| merged common ancestors:content" renamed
192 test_expect_success
'rebase --merge describes parent of commit being picked' '
193 test_create_repo rebase &&
196 test_commit base file &&
197 test_commit main file &&
198 git checkout -b side HEAD^ &&
199 test_commit side file &&
200 test_must_fail git -c merge.conflictstyle=diff3 rebase --merge main &&
201 grep "||||||| parent of" file
205 test_expect_success
'rebase --apply describes fake ancestor base' '
208 git rebase --abort &&
209 test_must_fail git -c merge.conflictstyle=diff3 rebase --apply main &&
210 grep "||||||| constructed merge base" file
214 test_setup_zdiff3
() {
215 test_create_repo zdiff3
&&
219 test_write_lines
1 2 3 4 5 6 7 8 9 >basic
&&
220 test_write_lines
1 2 3 AA
4 5 BB
6 7 8 >middle-common
&&
221 test_write_lines
1 2 3 4 5 6 7 8 9 >interesting
&&
222 test_write_lines
1 2 3 4 5 6 7 8 9 >evil
&&
224 git add basic middle-common interesting evil
&&
225 git commit
-m base
&&
231 test_write_lines
1 2 3 4 A B C D E
7 8 9 >basic
&&
232 test_write_lines
1 2 3 CC
4 5 DD
6 7 8 >middle-common
&&
233 test_write_lines
1 2 3 4 A B C D E F G H I J
7 8 9 >interesting
&&
234 test_write_lines
1 2 3 4 X A B C
7 8 9 >evil
&&
236 git commit
-m letters
&&
238 git checkout right
&&
239 test_write_lines
1 2 3 4 A X C Y E
7 8 9 >basic
&&
240 test_write_lines
1 2 3 EE
4 5 FF
6 7 8 >middle-common
&&
241 test_write_lines
1 2 3 4 A B C
5 6 G H I J
7 8 9 >interesting
&&
242 test_write_lines
1 2 3 4 Y A B C B C
7 8 9 >evil
&&
244 git commit
-m permuted
248 test_expect_success
'check zdiff3 markers' '
253 git checkout left^0 &&
255 base=$(git rev-parse --short HEAD^1) &&
256 test_must_fail git -c merge.conflictstyle=zdiff3 merge -s recursive right^0 &&
258 test_write_lines 1 2 3 4 A \
259 "<<<<<<< HEAD" B C D \
260 "||||||| $base" 5 6 \
265 test_cmp expect basic &&
267 test_write_lines 1 2 3 \
279 test_cmp expect middle-common &&
281 test_write_lines 1 2 3 4 A B C \
282 "<<<<<<< HEAD" D E F \
283 "||||||| $base" 5 6 \
288 test_cmp expect interesting &&
290 # Not passing this one yet; the common "B C" lines is still
291 # being left in the conflict blocks on the left and right
293 test_write_lines 1 2 3 4 \
295 "||||||| $base" 5 6 \