Merge branch 'ps/ref-tests-update-more' into maint-2.43
[git.git] / t / t6403-merge-file.sh
blob2c92209ecabf5b17477522a328e64ac0c5e62ee1
1 #!/bin/sh
3 test_description='RCS merge replacement: merge-file'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_expect_success 'setup' '
9 cat >orig.txt <<-\EOF &&
10 Dominus regit me,
11 et nihil mihi deerit.
12 In loco pascuae ibi me collocavit,
13 super aquam refectionis educavit me;
14 animam meam convertit,
15 deduxit me super semitas jusitiae,
16 propter nomen suum.
17 EOF
19 cat >new1.txt <<-\EOF &&
20 Dominus regit me,
21 et nihil mihi deerit.
22 In loco pascuae ibi me collocavit,
23 super aquam refectionis educavit me;
24 animam meam convertit,
25 deduxit me super semitas jusitiae,
26 propter nomen suum.
27 Nam et si ambulavero in medio umbrae mortis,
28 non timebo mala, quoniam tu mecum es:
29 virga tua et baculus tuus ipsa me consolata sunt.
30 EOF
32 cat >new2.txt <<-\EOF &&
33 Dominus regit me, et nihil mihi deerit.
34 In loco pascuae ibi me collocavit,
35 super aquam refectionis educavit me;
36 animam meam convertit,
37 deduxit me super semitas jusitiae,
38 propter nomen suum.
39 EOF
41 cat >new3.txt <<-\EOF &&
42 DOMINUS regit me,
43 et nihil mihi deerit.
44 In loco pascuae ibi me collocavit,
45 super aquam refectionis educavit me;
46 animam meam convertit,
47 deduxit me super semitas jusitiae,
48 propter nomen suum.
49 EOF
51 cat >new4.txt <<-\EOF &&
52 Dominus regit me, et nihil mihi deerit.
53 In loco pascuae ibi me collocavit,
54 super aquam refectionis educavit me;
55 animam meam convertit,
56 deduxit me super semitas jusitiae,
57 EOF
59 printf "propter nomen suum." >>new4.txt
62 test_expect_success 'merge with no changes' '
63 cp orig.txt test.txt &&
64 git merge-file test.txt orig.txt orig.txt &&
65 test_cmp test.txt orig.txt
68 test_expect_success 'merge with no changes with --object-id' '
69 git add orig.txt &&
70 git merge-file -p --object-id :orig.txt :orig.txt :orig.txt >actual &&
71 test_cmp actual orig.txt
74 test_expect_success "merge without conflict" '
75 cp new1.txt test.txt &&
76 git merge-file test.txt orig.txt new2.txt
79 test_expect_success 'merge without conflict with --object-id' '
80 git add orig.txt new2.txt &&
81 git merge-file --object-id :orig.txt :orig.txt :new2.txt >actual &&
82 git rev-parse :new2.txt >expected &&
83 test_cmp actual expected
86 test_expect_success 'can accept object ID with --object-id' '
87 git merge-file --object-id $(test_oid empty_blob) $(test_oid empty_blob) :new2.txt >actual &&
88 git rev-parse :new2.txt >expected &&
89 test_cmp actual expected
92 test_expect_success 'works in subdirectory' '
93 mkdir dir &&
94 cp new1.txt dir/a.txt &&
95 cp orig.txt dir/o.txt &&
96 cp new2.txt dir/b.txt &&
97 ( cd dir && git merge-file a.txt o.txt b.txt ) &&
98 test_path_is_missing a.txt
101 test_expect_success "merge without conflict (--quiet)" '
102 cp new1.txt test.txt &&
103 git merge-file --quiet test.txt orig.txt new2.txt
106 test_expect_failure "merge without conflict (missing LF at EOF)" '
107 cp new1.txt test2.txt &&
108 git merge-file test2.txt orig.txt new4.txt
111 test_expect_failure "merge result added missing LF" '
112 test_cmp test.txt test2.txt
115 test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" '
116 cp new4.txt test3.txt &&
117 git merge-file --quiet test3.txt new2.txt new3.txt
120 test_expect_success "merge does not add LF away of change" '
121 cat >expect.txt <<-\EOF &&
122 DOMINUS regit me,
123 et nihil mihi deerit.
124 In loco pascuae ibi me collocavit,
125 super aquam refectionis educavit me;
126 animam meam convertit,
127 deduxit me super semitas jusitiae,
129 printf "propter nomen suum." >>expect.txt &&
131 test_cmp expect.txt test3.txt
134 test_expect_success "merge with conflicts" '
135 cp test.txt backup.txt &&
136 test_must_fail git merge-file test.txt orig.txt new3.txt
139 test_expect_success "expected conflict markers" '
140 cat >expect.txt <<-\EOF &&
141 <<<<<<< test.txt
142 Dominus regit me, et nihil mihi deerit.
143 =======
144 DOMINUS regit me,
145 et nihil mihi deerit.
146 >>>>>>> new3.txt
147 In loco pascuae ibi me collocavit,
148 super aquam refectionis educavit me;
149 animam meam convertit,
150 deduxit me super semitas jusitiae,
151 propter nomen suum.
152 Nam et si ambulavero in medio umbrae mortis,
153 non timebo mala, quoniam tu mecum es:
154 virga tua et baculus tuus ipsa me consolata sunt.
157 test_cmp expect.txt test.txt
160 test_expect_success "merge with conflicts with --object-id" '
161 git add backup.txt orig.txt new3.txt &&
162 test_must_fail git merge-file -p --object-id :backup.txt :orig.txt :new3.txt >actual &&
163 sed -e "s/<< test.txt/<< :backup.txt/" \
164 -e "s/>> new3.txt/>> :new3.txt/" \
165 expect.txt >expect &&
166 test_cmp expect actual &&
167 test_must_fail git merge-file --object-id :backup.txt :orig.txt :new3.txt >oid &&
168 git cat-file blob "$(cat oid)" >actual &&
169 test_cmp expect actual
172 test_expect_success "merge with conflicts with --object-id with labels" '
173 git add backup.txt orig.txt new3.txt &&
174 test_must_fail git merge-file -p --object-id \
175 -L test.txt -L orig.txt -L new3.txt \
176 :backup.txt :orig.txt :new3.txt >actual &&
177 test_cmp expect.txt actual &&
178 test_must_fail git merge-file --object-id \
179 -L test.txt -L orig.txt -L new3.txt \
180 :backup.txt :orig.txt :new3.txt >oid &&
181 git cat-file blob "$(cat oid)" >actual &&
182 test_cmp expect.txt actual
185 test_expect_success "merge conflicting with --ours" '
186 cp backup.txt test.txt &&
188 cat >expect.txt <<-\EOF &&
189 Dominus regit me, et nihil mihi deerit.
190 In loco pascuae ibi me collocavit,
191 super aquam refectionis educavit me;
192 animam meam convertit,
193 deduxit me super semitas jusitiae,
194 propter nomen suum.
195 Nam et si ambulavero in medio umbrae mortis,
196 non timebo mala, quoniam tu mecum es:
197 virga tua et baculus tuus ipsa me consolata sunt.
200 git merge-file --ours test.txt orig.txt new3.txt &&
201 test_cmp expect.txt test.txt
204 test_expect_success "merge conflicting with --theirs" '
205 cp backup.txt test.txt &&
207 cat >expect.txt <<-\EOF &&
208 DOMINUS regit me,
209 et nihil mihi deerit.
210 In loco pascuae ibi me collocavit,
211 super aquam refectionis educavit me;
212 animam meam convertit,
213 deduxit me super semitas jusitiae,
214 propter nomen suum.
215 Nam et si ambulavero in medio umbrae mortis,
216 non timebo mala, quoniam tu mecum es:
217 virga tua et baculus tuus ipsa me consolata sunt.
220 git merge-file --theirs test.txt orig.txt new3.txt &&
221 test_cmp expect.txt test.txt
224 test_expect_success "merge conflicting with --union" '
225 cp backup.txt test.txt &&
227 cat >expect.txt <<-\EOF &&
228 Dominus regit me, et nihil mihi deerit.
229 DOMINUS regit me,
230 et nihil mihi deerit.
231 In loco pascuae ibi me collocavit,
232 super aquam refectionis educavit me;
233 animam meam convertit,
234 deduxit me super semitas jusitiae,
235 propter nomen suum.
236 Nam et si ambulavero in medio umbrae mortis,
237 non timebo mala, quoniam tu mecum es:
238 virga tua et baculus tuus ipsa me consolata sunt.
241 git merge-file --union test.txt orig.txt new3.txt &&
242 test_cmp expect.txt test.txt
245 test_expect_success "merge with conflicts, using -L" '
246 cp backup.txt test.txt &&
248 test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt
251 test_expect_success "expected conflict markers, with -L" '
252 cat >expect.txt <<-\EOF &&
253 <<<<<<< 1
254 Dominus regit me, et nihil mihi deerit.
255 =======
256 DOMINUS regit me,
257 et nihil mihi deerit.
258 >>>>>>> new3.txt
259 In loco pascuae ibi me collocavit,
260 super aquam refectionis educavit me;
261 animam meam convertit,
262 deduxit me super semitas jusitiae,
263 propter nomen suum.
264 Nam et si ambulavero in medio umbrae mortis,
265 non timebo mala, quoniam tu mecum es:
266 virga tua et baculus tuus ipsa me consolata sunt.
269 test_cmp expect.txt test.txt
272 test_expect_success "conflict in removed tail" '
273 sed "s/ tu / TU /" <new1.txt >new5.txt &&
274 test_must_fail git merge-file -p orig.txt new1.txt new5.txt >out
277 test_expect_success "expected conflict markers" '
278 cat >expect <<-\EOF &&
279 Dominus regit me,
280 et nihil mihi deerit.
281 In loco pascuae ibi me collocavit,
282 super aquam refectionis educavit me;
283 animam meam convertit,
284 deduxit me super semitas jusitiae,
285 propter nomen suum.
286 <<<<<<< orig.txt
287 =======
288 Nam et si ambulavero in medio umbrae mortis,
289 non timebo mala, quoniam TU mecum es:
290 virga tua et baculus tuus ipsa me consolata sunt.
291 >>>>>>> new5.txt
294 test_cmp expect out
297 test_expect_success 'binary files cannot be merged' '
298 test_must_fail git merge-file -p \
299 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
300 grep "Cannot merge binary files" merge.err
303 test_expect_success 'binary files cannot be merged with --object-id' '
304 cp "$TEST_DIRECTORY"/test-binary-1.png . &&
305 git add orig.txt new1.txt test-binary-1.png &&
306 test_must_fail git merge-file --object-id \
307 :orig.txt :test-binary-1.png :new1.txt 2> merge.err &&
308 grep "Cannot merge binary files" merge.err
311 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
312 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" <new5.txt >new6.txt &&
313 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" <new5.txt >new7.txt &&
315 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
316 test 1 = $(grep ======= <output | wc -l)
319 test_expect_success 'ZEALOUS_ALNUM' '
320 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit;/" <new6.txt | tr % "\012" >new8.txt &&
321 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit --/" <new7.txt | tr % "\012" >new9.txt &&
323 test_must_fail git merge-file -p \
324 new8.txt new5.txt new9.txt >merge.out &&
325 test 1 = $(grep ======= <merge.out | wc -l)
328 test_expect_success '"diff3 -m" style output (1)' '
329 cat >expect <<-\EOF &&
330 Dominus regit me,
331 <<<<<<< new8.txt
332 et nihil mihi deerit;
337 In loco pascuae ibi me collocavit;
338 super aquam refectionis educavit me.
339 ||||||| new5.txt
340 et nihil mihi deerit.
341 In loco pascuae ibi me collocavit,
342 super aquam refectionis educavit me;
343 =======
344 et nihil mihi deerit,
349 In loco pascuae ibi me collocavit --
350 super aquam refectionis educavit me,
351 >>>>>>> new9.txt
352 animam meam convertit,
353 deduxit me super semitas jusitiae,
354 propter nomen suum.
355 Nam et si ambulavero in medio umbrae mortis,
356 non timebo mala, quoniam TU mecum es:
357 virga tua et baculus tuus ipsa me consolata sunt.
360 test_must_fail git merge-file -p --diff3 \
361 new8.txt new5.txt new9.txt >actual &&
362 test_cmp expect actual
365 test_expect_success '"diff3 -m" style output (2)' '
366 git config merge.conflictstyle diff3 &&
367 test_must_fail git merge-file -p \
368 new8.txt new5.txt new9.txt >actual &&
369 test_cmp expect actual
372 test_expect_success 'marker size' '
373 cat >expect <<-\EOF &&
374 Dominus regit me,
375 <<<<<<<<<< new8.txt
376 et nihil mihi deerit;
381 In loco pascuae ibi me collocavit;
382 super aquam refectionis educavit me.
383 |||||||||| new5.txt
384 et nihil mihi deerit.
385 In loco pascuae ibi me collocavit,
386 super aquam refectionis educavit me;
387 ==========
388 et nihil mihi deerit,
393 In loco pascuae ibi me collocavit --
394 super aquam refectionis educavit me,
395 >>>>>>>>>> new9.txt
396 animam meam convertit,
397 deduxit me super semitas jusitiae,
398 propter nomen suum.
399 Nam et si ambulavero in medio umbrae mortis,
400 non timebo mala, quoniam TU mecum es:
401 virga tua et baculus tuus ipsa me consolata sunt.
404 test_must_fail git merge-file -p --marker-size=10 \
405 new8.txt new5.txt new9.txt >actual &&
406 test_cmp expect actual
409 test_expect_success 'conflict at EOF without LF resolved by --ours' '
410 printf "line1\nline2\nline3" >nolf-orig.txt &&
411 printf "line1\nline2\nline3x" >nolf-diff1.txt &&
412 printf "line1\nline2\nline3y" >nolf-diff2.txt &&
414 git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
415 printf "line1\nline2\nline3x" >expect.txt &&
416 test_cmp expect.txt output.txt
419 test_expect_success 'conflict at EOF without LF resolved by --theirs' '
420 git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
421 printf "line1\nline2\nline3y" >expect.txt &&
422 test_cmp expect.txt output.txt
425 test_expect_success 'conflict at EOF without LF resolved by --union' '
426 git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
427 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
428 test_cmp expect.txt output.txt
431 test_expect_success 'conflict sections match existing line endings' '
432 printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
433 printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
434 printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
435 test_must_fail git -c core.eol=crlf merge-file -p \
436 crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
437 test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
438 test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
439 test_must_fail git -c core.eol=crlf merge-file -p \
440 nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
441 test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0
444 test_expect_success '--object-id fails without repository' '
445 empty="$(test_oid empty_blob)" &&
446 nongit test_must_fail git merge-file --object-id $empty $empty $empty 2>err &&
447 grep "not a git repository" err
450 test_done