]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6023-merge-file.sh
Merge branch 'sb/userdiff-dts'
[thirdparty/git.git] / t / t6023-merge-file.sh
CommitLineData
ba1f5f35
JS
1#!/bin/sh
2
3test_description='RCS merge replacement: merge-file'
4. ./test-lib.sh
5
6cat > orig.txt << EOF
7Dominus regit me,
8et nihil mihi deerit.
9In loco pascuae ibi me collocavit,
10super aquam refectionis educavit me;
11animam meam convertit,
12deduxit me super semitas jusitiae,
13propter nomen suum.
14EOF
15
16cat > new1.txt << EOF
17Dominus regit me,
18et nihil mihi deerit.
19In loco pascuae ibi me collocavit,
20super aquam refectionis educavit me;
21animam meam convertit,
22deduxit me super semitas jusitiae,
23propter nomen suum.
24Nam et si ambulavero in medio umbrae mortis,
25non timebo mala, quoniam tu mecum es:
26virga tua et baculus tuus ipsa me consolata sunt.
27EOF
28
29cat > new2.txt << EOF
30Dominus regit me, et nihil mihi deerit.
31In loco pascuae ibi me collocavit,
32super aquam refectionis educavit me;
33animam meam convertit,
34deduxit me super semitas jusitiae,
35propter nomen suum.
36EOF
37
38cat > new3.txt << EOF
39DOMINUS regit me,
40et nihil mihi deerit.
41In loco pascuae ibi me collocavit,
42super aquam refectionis educavit me;
43animam meam convertit,
44deduxit me super semitas jusitiae,
45propter nomen suum.
46EOF
47
48cat > new4.txt << EOF
49Dominus regit me, et nihil mihi deerit.
50In loco pascuae ibi me collocavit,
51super aquam refectionis educavit me;
52animam meam convertit,
53deduxit me super semitas jusitiae,
54EOF
2aad957a 55printf "propter nomen suum." >> new4.txt
ba1f5f35 56
5719db91 57test_expect_success 'merge with no changes' '
1cd12926
CB
58 cp orig.txt test.txt &&
59 git merge-file test.txt orig.txt orig.txt &&
60 test_cmp test.txt orig.txt
61'
62
ba1f5f35
JS
63cp new1.txt test.txt
64test_expect_success "merge without conflict" \
5be60078 65 "git merge-file test.txt orig.txt new2.txt"
ba1f5f35 66
55846b9a
TR
67test_expect_success 'works in subdirectory' '
68 mkdir dir &&
69 cp new1.txt dir/a.txt &&
70 cp orig.txt dir/o.txt &&
71 cp new2.txt dir/b.txt &&
204a8ffe
ABG
72 ( cd dir && git merge-file a.txt o.txt b.txt ) &&
73 test_path_is_missing a.txt
55846b9a
TR
74'
75
3fdcdbdf
JS
76cp new1.txt test.txt
77test_expect_success "merge without conflict (--quiet)" \
78 "git merge-file --quiet test.txt orig.txt new2.txt"
79
ba1f5f35 80cp new1.txt test2.txt
6d49de41
MK
81test_expect_failure "merge without conflict (missing LF at EOF)" \
82 "git merge-file test2.txt orig.txt new4.txt"
ba1f5f35 83
6d49de41 84test_expect_failure "merge result added missing LF" \
3af82863 85 "test_cmp test.txt test2.txt"
ba1f5f35 86
ba311807
MK
87cp new4.txt test3.txt
88test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \
89 "git merge-file --quiet test3.txt new2.txt new3.txt"
90
91cat > expect.txt << EOF
92DOMINUS regit me,
93et nihil mihi deerit.
94In loco pascuae ibi me collocavit,
95super aquam refectionis educavit me;
96animam meam convertit,
97deduxit me super semitas jusitiae,
98EOF
99printf "propter nomen suum." >> expect.txt
100
101test_expect_success "merge does not add LF away of change" \
dcbaa0b3 102 "test_cmp expect.txt test3.txt"
ba311807 103
ba1f5f35 104cp test.txt backup.txt
41ac414e 105test_expect_success "merge with conflicts" \
d492b31c 106 "test_must_fail git merge-file test.txt orig.txt new3.txt"
ba1f5f35
JS
107
108cat > expect.txt << EOF
109<<<<<<< test.txt
110Dominus regit me, et nihil mihi deerit.
111=======
112DOMINUS regit me,
113et nihil mihi deerit.
114>>>>>>> new3.txt
115In loco pascuae ibi me collocavit,
116super aquam refectionis educavit me;
117animam meam convertit,
118deduxit me super semitas jusitiae,
119propter nomen suum.
120Nam et si ambulavero in medio umbrae mortis,
121non timebo mala, quoniam tu mecum es:
122virga tua et baculus tuus ipsa me consolata sunt.
123EOF
124
dcbaa0b3 125test_expect_success "expected conflict markers" "test_cmp expect.txt test.txt"
ba1f5f35
JS
126
127cp backup.txt test.txt
ba311807
MK
128
129cat > expect.txt << EOF
130Dominus regit me, et nihil mihi deerit.
131In loco pascuae ibi me collocavit,
132super aquam refectionis educavit me;
133animam meam convertit,
134deduxit me super semitas jusitiae,
135propter nomen suum.
136Nam et si ambulavero in medio umbrae mortis,
137non timebo mala, quoniam tu mecum es:
138virga tua et baculus tuus ipsa me consolata sunt.
139EOF
140test_expect_success "merge conflicting with --ours" \
dcbaa0b3 141 "git merge-file --ours test.txt orig.txt new3.txt && test_cmp expect.txt test.txt"
ba311807
MK
142cp backup.txt test.txt
143
144cat > expect.txt << EOF
145DOMINUS regit me,
146et nihil mihi deerit.
147In loco pascuae ibi me collocavit,
148super aquam refectionis educavit me;
149animam meam convertit,
150deduxit me super semitas jusitiae,
151propter nomen suum.
152Nam et si ambulavero in medio umbrae mortis,
153non timebo mala, quoniam tu mecum es:
154virga tua et baculus tuus ipsa me consolata sunt.
155EOF
156test_expect_success "merge conflicting with --theirs" \
dcbaa0b3 157 "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp expect.txt test.txt"
ba311807
MK
158cp backup.txt test.txt
159
160cat > expect.txt << EOF
161Dominus regit me, et nihil mihi deerit.
162DOMINUS regit me,
163et nihil mihi deerit.
164In loco pascuae ibi me collocavit,
165super aquam refectionis educavit me;
166animam meam convertit,
167deduxit me super semitas jusitiae,
168propter nomen suum.
169Nam et si ambulavero in medio umbrae mortis,
170non timebo mala, quoniam tu mecum es:
171virga tua et baculus tuus ipsa me consolata sunt.
172EOF
173test_expect_success "merge conflicting with --union" \
dcbaa0b3 174 "git merge-file --union test.txt orig.txt new3.txt && test_cmp expect.txt test.txt"
ba311807
MK
175cp backup.txt test.txt
176
41ac414e 177test_expect_success "merge with conflicts, using -L" \
d492b31c 178 "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt"
ba1f5f35
JS
179
180cat > expect.txt << EOF
181<<<<<<< 1
182Dominus regit me, et nihil mihi deerit.
183=======
184DOMINUS regit me,
185et nihil mihi deerit.
186>>>>>>> new3.txt
187In loco pascuae ibi me collocavit,
188super aquam refectionis educavit me;
189animam meam convertit,
190deduxit me super semitas jusitiae,
191propter nomen suum.
192Nam et si ambulavero in medio umbrae mortis,
193non timebo mala, quoniam tu mecum es:
194virga tua et baculus tuus ipsa me consolata sunt.
195EOF
196
197test_expect_success "expected conflict markers, with -L" \
dcbaa0b3 198 "test_cmp expect.txt test.txt"
ba1f5f35 199
5d6b151f 200sed "s/ tu / TU /" < new1.txt > new5.txt
41ac414e 201test_expect_success "conflict in removed tail" \
d492b31c 202 "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out"
5d6b151f
JS
203
204cat > expect << EOF
205Dominus regit me,
206et nihil mihi deerit.
207In loco pascuae ibi me collocavit,
208super aquam refectionis educavit me;
209animam meam convertit,
210deduxit me super semitas jusitiae,
211propter nomen suum.
212<<<<<<< orig.txt
213=======
214Nam et si ambulavero in medio umbrae mortis,
215non timebo mala, quoniam TU mecum es:
216virga tua et baculus tuus ipsa me consolata sunt.
217>>>>>>> new5.txt
218EOF
219
3af82863 220test_expect_success "expected conflict markers" "test_cmp expect out"
5d6b151f 221
5771907a 222test_expect_success 'binary files cannot be merged' '
d492b31c 223 test_must_fail git merge-file -p \
b5967f82 224 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
5771907a
JS
225 grep "Cannot merge binary files" merge.err
226'
227
9524cf29
SB
228sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt
229sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt
f407f14d
JS
230
231test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
232
d492b31c 233 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
f407f14d
JS
234 test 1 = $(grep ======= < output | wc -l)
235
236'
237
10708a99
AL
238sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
239sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
ee95ec5d
JS
240
241test_expect_success 'ZEALOUS_ALNUM' '
242
d492b31c
SB
243 test_must_fail git merge-file -p \
244 new8.txt new5.txt new9.txt > merge.out &&
ee95ec5d
JS
245 test 1 = $(grep ======= < merge.out | wc -l)
246
247'
248
e0af48e4
JH
249cat >expect <<\EOF
250Dominus regit me,
251<<<<<<< new8.txt
252et nihil mihi deerit;
253
254
255
256
257In loco pascuae ibi me collocavit;
258super aquam refectionis educavit me.
4bb09362 259||||||| new5.txt
e0af48e4
JH
260et nihil mihi deerit.
261In loco pascuae ibi me collocavit,
262super aquam refectionis educavit me;
263=======
264et nihil mihi deerit,
265
266
267
268
269In loco pascuae ibi me collocavit --
270super aquam refectionis educavit me,
271>>>>>>> new9.txt
272animam meam convertit,
273deduxit me super semitas jusitiae,
274propter nomen suum.
275Nam et si ambulavero in medio umbrae mortis,
276non timebo mala, quoniam TU mecum es:
277virga tua et baculus tuus ipsa me consolata sunt.
278EOF
279
b5412484 280test_expect_success '"diff3 -m" style output (1)' '
e0af48e4
JH
281 test_must_fail git merge-file -p --diff3 \
282 new8.txt new5.txt new9.txt >actual &&
283 test_cmp expect actual
284'
285
b5412484
JH
286test_expect_success '"diff3 -m" style output (2)' '
287 git config merge.conflictstyle diff3 &&
288 test_must_fail git merge-file -p \
289 new8.txt new5.txt new9.txt >actual &&
290 test_cmp expect actual
291'
292
11f3aa23
BW
293cat >expect <<\EOF
294Dominus regit me,
295<<<<<<<<<< new8.txt
296et nihil mihi deerit;
297
298
299
300
301In loco pascuae ibi me collocavit;
302super aquam refectionis educavit me.
4bb09362 303|||||||||| new5.txt
11f3aa23
BW
304et nihil mihi deerit.
305In loco pascuae ibi me collocavit,
306super aquam refectionis educavit me;
307==========
308et nihil mihi deerit,
309
310
311
312
313In loco pascuae ibi me collocavit --
314super aquam refectionis educavit me,
315>>>>>>>>>> new9.txt
316animam meam convertit,
317deduxit me super semitas jusitiae,
318propter nomen suum.
319Nam et si ambulavero in medio umbrae mortis,
320non timebo mala, quoniam TU mecum es:
321virga tua et baculus tuus ipsa me consolata sunt.
322EOF
323
324test_expect_success 'marker size' '
325 test_must_fail git merge-file -p --marker-size=10 \
326 new8.txt new5.txt new9.txt >actual &&
327 test_cmp expect actual
328'
329
ba311807
MK
330printf "line1\nline2\nline3" >nolf-orig.txt
331printf "line1\nline2\nline3x" >nolf-diff1.txt
332printf "line1\nline2\nline3y" >nolf-diff2.txt
333
334test_expect_success 'conflict at EOF without LF resolved by --ours' \
335 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
336 printf "line1\nline2\nline3x" >expect.txt &&
337 test_cmp expect.txt output.txt'
338
339test_expect_success 'conflict at EOF without LF resolved by --theirs' \
340 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
341 printf "line1\nline2\nline3y" >expect.txt &&
342 test_cmp expect.txt output.txt'
343
344test_expect_success 'conflict at EOF without LF resolved by --union' \
345 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
346 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
347 test_cmp expect.txt output.txt'
348
15980dea 349test_expect_success 'conflict sections match existing line endings' '
86efa215
JS
350 printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
351 printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
352 printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
353 test_must_fail git -c core.eol=crlf merge-file -p \
354 crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
355 test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
15980dea 356 test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
86efa215
JS
357 test_must_fail git -c core.eol=crlf merge-file -p \
358 nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
359 test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0
360'
361
ba1f5f35 362test_done