Merge branch 'ab/make-sparse-for-real'
[git/debian.git] / t / t6403-merge-file.sh
blob2f421d967abefbef96eb6f2c0d1201184b9b5d57
1 #!/bin/sh
3 test_description='RCS merge replacement: merge-file'
4 . ./test-lib.sh
6 test_expect_success 'setup' '
7 cat >orig.txt <<-\EOF &&
8 Dominus regit me,
9 et nihil mihi deerit.
10 In loco pascuae ibi me collocavit,
11 super aquam refectionis educavit me;
12 animam meam convertit,
13 deduxit me super semitas jusitiae,
14 propter nomen suum.
15 EOF
17 cat >new1.txt <<-\EOF &&
18 Dominus regit me,
19 et nihil mihi deerit.
20 In loco pascuae ibi me collocavit,
21 super aquam refectionis educavit me;
22 animam meam convertit,
23 deduxit me super semitas jusitiae,
24 propter nomen suum.
25 Nam et si ambulavero in medio umbrae mortis,
26 non timebo mala, quoniam tu mecum es:
27 virga tua et baculus tuus ipsa me consolata sunt.
28 EOF
30 cat >new2.txt <<-\EOF &&
31 Dominus regit me, et nihil mihi deerit.
32 In loco pascuae ibi me collocavit,
33 super aquam refectionis educavit me;
34 animam meam convertit,
35 deduxit me super semitas jusitiae,
36 propter nomen suum.
37 EOF
39 cat >new3.txt <<-\EOF &&
40 DOMINUS regit me,
41 et nihil mihi deerit.
42 In loco pascuae ibi me collocavit,
43 super aquam refectionis educavit me;
44 animam meam convertit,
45 deduxit me super semitas jusitiae,
46 propter nomen suum.
47 EOF
49 cat >new4.txt <<-\EOF &&
50 Dominus regit me, et nihil mihi deerit.
51 In loco pascuae ibi me collocavit,
52 super aquam refectionis educavit me;
53 animam meam convertit,
54 deduxit me super semitas jusitiae,
55 EOF
57 printf "propter nomen suum." >>new4.txt
60 test_expect_success 'merge with no changes' '
61 cp orig.txt test.txt &&
62 git merge-file test.txt orig.txt orig.txt &&
63 test_cmp test.txt orig.txt
66 test_expect_success "merge without conflict" '
67 cp new1.txt test.txt &&
68 git merge-file test.txt orig.txt new2.txt
71 test_expect_success 'works in subdirectory' '
72 mkdir dir &&
73 cp new1.txt dir/a.txt &&
74 cp orig.txt dir/o.txt &&
75 cp new2.txt dir/b.txt &&
76 ( cd dir && git merge-file a.txt o.txt b.txt ) &&
77 test_path_is_missing a.txt
80 test_expect_success "merge without conflict (--quiet)" '
81 cp new1.txt test.txt &&
82 git merge-file --quiet test.txt orig.txt new2.txt
85 test_expect_failure "merge without conflict (missing LF at EOF)" '
86 cp new1.txt test2.txt &&
87 git merge-file test2.txt orig.txt new4.txt
90 test_expect_failure "merge result added missing LF" '
91 test_cmp test.txt test2.txt
94 test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" '
95 cp new4.txt test3.txt &&
96 git merge-file --quiet test3.txt new2.txt new3.txt
99 test_expect_success "merge does not add LF away of change" '
100 cat >expect.txt <<-\EOF &&
101 DOMINUS regit me,
102 et nihil mihi deerit.
103 In loco pascuae ibi me collocavit,
104 super aquam refectionis educavit me;
105 animam meam convertit,
106 deduxit me super semitas jusitiae,
108 printf "propter nomen suum." >>expect.txt &&
110 test_cmp expect.txt test3.txt
113 test_expect_success "merge with conflicts" '
114 cp test.txt backup.txt &&
115 test_must_fail git merge-file test.txt orig.txt new3.txt
118 test_expect_success "expected conflict markers" '
119 cat >expect.txt <<-\EOF &&
120 <<<<<<< test.txt
121 Dominus regit me, et nihil mihi deerit.
122 =======
123 DOMINUS regit me,
124 et nihil mihi deerit.
125 >>>>>>> new3.txt
126 In loco pascuae ibi me collocavit,
127 super aquam refectionis educavit me;
128 animam meam convertit,
129 deduxit me super semitas jusitiae,
130 propter nomen suum.
131 Nam et si ambulavero in medio umbrae mortis,
132 non timebo mala, quoniam tu mecum es:
133 virga tua et baculus tuus ipsa me consolata sunt.
136 test_cmp expect.txt test.txt
139 test_expect_success "merge conflicting with --ours" '
140 cp backup.txt test.txt &&
142 cat >expect.txt <<-\EOF &&
143 Dominus regit me, et nihil mihi deerit.
144 In loco pascuae ibi me collocavit,
145 super aquam refectionis educavit me;
146 animam meam convertit,
147 deduxit me super semitas jusitiae,
148 propter nomen suum.
149 Nam et si ambulavero in medio umbrae mortis,
150 non timebo mala, quoniam tu mecum es:
151 virga tua et baculus tuus ipsa me consolata sunt.
154 git merge-file --ours test.txt orig.txt new3.txt &&
155 test_cmp expect.txt test.txt
158 test_expect_success "merge conflicting with --theirs" '
159 cp backup.txt test.txt &&
161 cat >expect.txt <<-\EOF &&
162 DOMINUS regit me,
163 et nihil mihi deerit.
164 In loco pascuae ibi me collocavit,
165 super aquam refectionis educavit me;
166 animam meam convertit,
167 deduxit me super semitas jusitiae,
168 propter nomen suum.
169 Nam et si ambulavero in medio umbrae mortis,
170 non timebo mala, quoniam tu mecum es:
171 virga tua et baculus tuus ipsa me consolata sunt.
174 git merge-file --theirs test.txt orig.txt new3.txt &&
175 test_cmp expect.txt test.txt
178 test_expect_success "merge conflicting with --union" '
179 cp backup.txt test.txt &&
181 cat >expect.txt <<-\EOF &&
182 Dominus regit me, et nihil mihi deerit.
183 DOMINUS regit me,
184 et nihil mihi deerit.
185 In loco pascuae ibi me collocavit,
186 super aquam refectionis educavit me;
187 animam meam convertit,
188 deduxit me super semitas jusitiae,
189 propter nomen suum.
190 Nam et si ambulavero in medio umbrae mortis,
191 non timebo mala, quoniam tu mecum es:
192 virga tua et baculus tuus ipsa me consolata sunt.
195 git merge-file --union test.txt orig.txt new3.txt &&
196 test_cmp expect.txt test.txt
199 test_expect_success "merge with conflicts, using -L" '
200 cp backup.txt test.txt &&
202 test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt
205 test_expect_success "expected conflict markers, with -L" '
206 cat >expect.txt <<-\EOF &&
207 <<<<<<< 1
208 Dominus regit me, et nihil mihi deerit.
209 =======
210 DOMINUS regit me,
211 et nihil mihi deerit.
212 >>>>>>> new3.txt
213 In loco pascuae ibi me collocavit,
214 super aquam refectionis educavit me;
215 animam meam convertit,
216 deduxit me super semitas jusitiae,
217 propter nomen suum.
218 Nam et si ambulavero in medio umbrae mortis,
219 non timebo mala, quoniam tu mecum es:
220 virga tua et baculus tuus ipsa me consolata sunt.
223 test_cmp expect.txt test.txt
226 test_expect_success "conflict in removed tail" '
227 sed "s/ tu / TU /" <new1.txt >new5.txt &&
228 test_must_fail git merge-file -p orig.txt new1.txt new5.txt >out
231 test_expect_success "expected conflict markers" '
232 cat >expect <<-\EOF &&
233 Dominus regit me,
234 et nihil mihi deerit.
235 In loco pascuae ibi me collocavit,
236 super aquam refectionis educavit me;
237 animam meam convertit,
238 deduxit me super semitas jusitiae,
239 propter nomen suum.
240 <<<<<<< orig.txt
241 =======
242 Nam et si ambulavero in medio umbrae mortis,
243 non timebo mala, quoniam TU mecum es:
244 virga tua et baculus tuus ipsa me consolata sunt.
245 >>>>>>> new5.txt
248 test_cmp expect out
251 test_expect_success 'binary files cannot be merged' '
252 test_must_fail git merge-file -p \
253 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
254 grep "Cannot merge binary files" merge.err
257 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
258 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" <new5.txt >new6.txt &&
259 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" <new5.txt >new7.txt &&
261 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
262 test 1 = $(grep ======= <output | wc -l)
265 test_expect_success 'ZEALOUS_ALNUM' '
266 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit;/" <new6.txt | tr % "\012" >new8.txt &&
267 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit --/" <new7.txt | tr % "\012" >new9.txt &&
269 test_must_fail git merge-file -p \
270 new8.txt new5.txt new9.txt >merge.out &&
271 test 1 = $(grep ======= <merge.out | wc -l)
274 test_expect_success '"diff3 -m" style output (1)' '
275 cat >expect <<-\EOF &&
276 Dominus regit me,
277 <<<<<<< new8.txt
278 et nihil mihi deerit;
283 In loco pascuae ibi me collocavit;
284 super aquam refectionis educavit me.
285 ||||||| new5.txt
286 et nihil mihi deerit.
287 In loco pascuae ibi me collocavit,
288 super aquam refectionis educavit me;
289 =======
290 et nihil mihi deerit,
295 In loco pascuae ibi me collocavit --
296 super aquam refectionis educavit me,
297 >>>>>>> new9.txt
298 animam meam convertit,
299 deduxit me super semitas jusitiae,
300 propter nomen suum.
301 Nam et si ambulavero in medio umbrae mortis,
302 non timebo mala, quoniam TU mecum es:
303 virga tua et baculus tuus ipsa me consolata sunt.
306 test_must_fail git merge-file -p --diff3 \
307 new8.txt new5.txt new9.txt >actual &&
308 test_cmp expect actual
311 test_expect_success '"diff3 -m" style output (2)' '
312 git config merge.conflictstyle diff3 &&
313 test_must_fail git merge-file -p \
314 new8.txt new5.txt new9.txt >actual &&
315 test_cmp expect actual
318 test_expect_success 'marker size' '
319 cat >expect <<-\EOF &&
320 Dominus regit me,
321 <<<<<<<<<< new8.txt
322 et nihil mihi deerit;
327 In loco pascuae ibi me collocavit;
328 super aquam refectionis educavit me.
329 |||||||||| new5.txt
330 et nihil mihi deerit.
331 In loco pascuae ibi me collocavit,
332 super aquam refectionis educavit me;
333 ==========
334 et nihil mihi deerit,
339 In loco pascuae ibi me collocavit --
340 super aquam refectionis educavit me,
341 >>>>>>>>>> new9.txt
342 animam meam convertit,
343 deduxit me super semitas jusitiae,
344 propter nomen suum.
345 Nam et si ambulavero in medio umbrae mortis,
346 non timebo mala, quoniam TU mecum es:
347 virga tua et baculus tuus ipsa me consolata sunt.
350 test_must_fail git merge-file -p --marker-size=10 \
351 new8.txt new5.txt new9.txt >actual &&
352 test_cmp expect actual
355 test_expect_success 'conflict at EOF without LF resolved by --ours' '
356 printf "line1\nline2\nline3" >nolf-orig.txt &&
357 printf "line1\nline2\nline3x" >nolf-diff1.txt &&
358 printf "line1\nline2\nline3y" >nolf-diff2.txt &&
360 git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
361 printf "line1\nline2\nline3x" >expect.txt &&
362 test_cmp expect.txt output.txt
365 test_expect_success 'conflict at EOF without LF resolved by --theirs' '
366 git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
367 printf "line1\nline2\nline3y" >expect.txt &&
368 test_cmp expect.txt output.txt
371 test_expect_success 'conflict at EOF without LF resolved by --union' '
372 git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
373 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
374 test_cmp expect.txt output.txt
377 test_expect_success 'conflict sections match existing line endings' '
378 printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
379 printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
380 printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
381 test_must_fail git -c core.eol=crlf merge-file -p \
382 crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
383 test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
384 test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
385 test_must_fail git -c core.eol=crlf merge-file -p \
386 nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
387 test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0
390 test_done