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
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 &&
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' '
41 test_must_fail git -c merge.conflictstyle=diff3 merge --allow-unrelated-histories -s recursive R^0 &&
43 grep "|||||| empty tree" content
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
74 test_commit L content "1
83 test_commit R renamed "1
92 test_expect_success
'check unique merge base' '
94 cd unique_merge_base &&
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
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
135 test_commit L1 content "0
144 test_commit R1 content "1
161 test_commit L3 content "0
172 test_commit R3 renamed "0
181 test_expect_success
'check multiple merge bases' '
183 cd multiple_merge_bases &&
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' '
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' '
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
() {
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
&&
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
&&
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
&&
245 git commit
-m permuted
249 test_expect_success
'check zdiff3 markers' '
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 \
266 test_cmp expect basic &&
268 test_write_lines 1 2 3 \
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 \
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
294 test_write_lines 1 2 3 4 \
296 "||||||| $base" 5 6 \