3 test_description
='RCS merge replacement: merge-file'
5 TEST_PASSES_SANITIZE_LEAK
=true
8 test_expect_success
'setup' '
9 cat >orig.txt <<-\EOF &&
12 In loco pascuae ibi me collocavit,
13 super aquam refectionis educavit me;
14 animam meam convertit,
15 deduxit me super semitas jusitiae,
19 cat >new1.txt <<-\EOF &&
22 In loco pascuae ibi me collocavit,
23 super aquam refectionis educavit me;
24 animam meam convertit,
25 deduxit me super semitas jusitiae,
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.
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,
41 cat >new3.txt <<-\EOF &&
44 In loco pascuae ibi me collocavit,
45 super aquam refectionis educavit me;
46 animam meam convertit,
47 deduxit me super semitas jusitiae,
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,
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' '
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' '
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 &&
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 &&
142 Dominus regit me, et nihil mihi deerit.
145 et nihil mihi deerit.
147 In loco pascuae ibi me collocavit,
148 super aquam refectionis educavit me;
149 animam meam convertit,
150 deduxit me super semitas jusitiae,
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,
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 &&
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,
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.
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,
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 &&
254 Dominus regit me, et nihil mihi deerit.
257 et nihil mihi deerit.
259 In loco pascuae ibi me collocavit,
260 super aquam refectionis educavit me;
261 animam meam convertit,
262 deduxit me super semitas jusitiae,
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 &&
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,
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.
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 &&
332 et nihil mihi deerit;
337 In loco pascuae ibi me collocavit;
338 super aquam refectionis educavit me.
340 et nihil mihi deerit.
341 In loco pascuae ibi me collocavit,
342 super aquam refectionis educavit me;
344 et nihil mihi deerit,
349 In loco pascuae ibi me collocavit --
350 super aquam refectionis educavit me,
352 animam meam convertit,
353 deduxit me super semitas jusitiae,
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 &&
376 et nihil mihi deerit;
381 In loco pascuae ibi me collocavit;
382 super aquam refectionis educavit me.
384 et nihil mihi deerit.
385 In loco pascuae ibi me collocavit,
386 super aquam refectionis educavit me;
388 et nihil mihi deerit,
393 In loco pascuae ibi me collocavit --
394 super aquam refectionis educavit me,
396 animam meam convertit,
397 deduxit me super semitas jusitiae,
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