repack: fix generating multi-pack-index with only non-local packs
[alt-git.git] / t / t6403-merge-file.sh
blob1a7082323dddfce66b2d419efe60c87314c5f8e1
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 without conflict" '
69 cp new1.txt test.txt &&
70 git merge-file test.txt orig.txt new2.txt
73 test_expect_success 'works in subdirectory' '
74 mkdir dir &&
75 cp new1.txt dir/a.txt &&
76 cp orig.txt dir/o.txt &&
77 cp new2.txt dir/b.txt &&
78 ( cd dir && git merge-file a.txt o.txt b.txt ) &&
79 test_path_is_missing a.txt
82 test_expect_success "merge without conflict (--quiet)" '
83 cp new1.txt test.txt &&
84 git merge-file --quiet test.txt orig.txt new2.txt
87 test_expect_failure "merge without conflict (missing LF at EOF)" '
88 cp new1.txt test2.txt &&
89 git merge-file test2.txt orig.txt new4.txt
92 test_expect_failure "merge result added missing LF" '
93 test_cmp test.txt test2.txt
96 test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" '
97 cp new4.txt test3.txt &&
98 git merge-file --quiet test3.txt new2.txt new3.txt
101 test_expect_success "merge does not add LF away of change" '
102 cat >expect.txt <<-\EOF &&
103 DOMINUS regit me,
104 et nihil mihi deerit.
105 In loco pascuae ibi me collocavit,
106 super aquam refectionis educavit me;
107 animam meam convertit,
108 deduxit me super semitas jusitiae,
110 printf "propter nomen suum." >>expect.txt &&
112 test_cmp expect.txt test3.txt
115 test_expect_success "merge with conflicts" '
116 cp test.txt backup.txt &&
117 test_must_fail git merge-file test.txt orig.txt new3.txt
120 test_expect_success "expected conflict markers" '
121 cat >expect.txt <<-\EOF &&
122 <<<<<<< test.txt
123 Dominus regit me, et nihil mihi deerit.
124 =======
125 DOMINUS regit me,
126 et nihil mihi deerit.
127 >>>>>>> new3.txt
128 In loco pascuae ibi me collocavit,
129 super aquam refectionis educavit me;
130 animam meam convertit,
131 deduxit me super semitas jusitiae,
132 propter nomen suum.
133 Nam et si ambulavero in medio umbrae mortis,
134 non timebo mala, quoniam tu mecum es:
135 virga tua et baculus tuus ipsa me consolata sunt.
138 test_cmp expect.txt test.txt
141 test_expect_success "merge conflicting with --ours" '
142 cp backup.txt test.txt &&
144 cat >expect.txt <<-\EOF &&
145 Dominus regit me, et nihil mihi deerit.
146 In loco pascuae ibi me collocavit,
147 super aquam refectionis educavit me;
148 animam meam convertit,
149 deduxit me super semitas jusitiae,
150 propter nomen suum.
151 Nam et si ambulavero in medio umbrae mortis,
152 non timebo mala, quoniam tu mecum es:
153 virga tua et baculus tuus ipsa me consolata sunt.
156 git merge-file --ours test.txt orig.txt new3.txt &&
157 test_cmp expect.txt test.txt
160 test_expect_success "merge conflicting with --theirs" '
161 cp backup.txt test.txt &&
163 cat >expect.txt <<-\EOF &&
164 DOMINUS regit me,
165 et nihil mihi deerit.
166 In loco pascuae ibi me collocavit,
167 super aquam refectionis educavit me;
168 animam meam convertit,
169 deduxit me super semitas jusitiae,
170 propter nomen suum.
171 Nam et si ambulavero in medio umbrae mortis,
172 non timebo mala, quoniam tu mecum es:
173 virga tua et baculus tuus ipsa me consolata sunt.
176 git merge-file --theirs test.txt orig.txt new3.txt &&
177 test_cmp expect.txt test.txt
180 test_expect_success "merge conflicting with --union" '
181 cp backup.txt test.txt &&
183 cat >expect.txt <<-\EOF &&
184 Dominus regit me, et nihil mihi deerit.
185 DOMINUS regit me,
186 et nihil mihi deerit.
187 In loco pascuae ibi me collocavit,
188 super aquam refectionis educavit me;
189 animam meam convertit,
190 deduxit me super semitas jusitiae,
191 propter nomen suum.
192 Nam et si ambulavero in medio umbrae mortis,
193 non timebo mala, quoniam tu mecum es:
194 virga tua et baculus tuus ipsa me consolata sunt.
197 git merge-file --union test.txt orig.txt new3.txt &&
198 test_cmp expect.txt test.txt
201 test_expect_success "merge with conflicts, using -L" '
202 cp backup.txt test.txt &&
204 test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt
207 test_expect_success "expected conflict markers, with -L" '
208 cat >expect.txt <<-\EOF &&
209 <<<<<<< 1
210 Dominus regit me, et nihil mihi deerit.
211 =======
212 DOMINUS regit me,
213 et nihil mihi deerit.
214 >>>>>>> new3.txt
215 In loco pascuae ibi me collocavit,
216 super aquam refectionis educavit me;
217 animam meam convertit,
218 deduxit me super semitas jusitiae,
219 propter nomen suum.
220 Nam et si ambulavero in medio umbrae mortis,
221 non timebo mala, quoniam tu mecum es:
222 virga tua et baculus tuus ipsa me consolata sunt.
225 test_cmp expect.txt test.txt
228 test_expect_success "conflict in removed tail" '
229 sed "s/ tu / TU /" <new1.txt >new5.txt &&
230 test_must_fail git merge-file -p orig.txt new1.txt new5.txt >out
233 test_expect_success "expected conflict markers" '
234 cat >expect <<-\EOF &&
235 Dominus regit me,
236 et nihil mihi deerit.
237 In loco pascuae ibi me collocavit,
238 super aquam refectionis educavit me;
239 animam meam convertit,
240 deduxit me super semitas jusitiae,
241 propter nomen suum.
242 <<<<<<< orig.txt
243 =======
244 Nam et si ambulavero in medio umbrae mortis,
245 non timebo mala, quoniam TU mecum es:
246 virga tua et baculus tuus ipsa me consolata sunt.
247 >>>>>>> new5.txt
250 test_cmp expect out
253 test_expect_success 'binary files cannot be merged' '
254 test_must_fail git merge-file -p \
255 orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err &&
256 grep "Cannot merge binary files" merge.err
259 test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
260 sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" <new5.txt >new6.txt &&
261 sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" <new5.txt >new7.txt &&
263 test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output &&
264 test 1 = $(grep ======= <output | wc -l)
267 test_expect_success 'ZEALOUS_ALNUM' '
268 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit;/" <new6.txt | tr % "\012" >new8.txt &&
269 sed -e "s/deerit./&%%%%/" -e "s/locavit,/locavit --/" <new7.txt | tr % "\012" >new9.txt &&
271 test_must_fail git merge-file -p \
272 new8.txt new5.txt new9.txt >merge.out &&
273 test 1 = $(grep ======= <merge.out | wc -l)
276 test_expect_success '"diff3 -m" style output (1)' '
277 cat >expect <<-\EOF &&
278 Dominus regit me,
279 <<<<<<< new8.txt
280 et nihil mihi deerit;
285 In loco pascuae ibi me collocavit;
286 super aquam refectionis educavit me.
287 ||||||| new5.txt
288 et nihil mihi deerit.
289 In loco pascuae ibi me collocavit,
290 super aquam refectionis educavit me;
291 =======
292 et nihil mihi deerit,
297 In loco pascuae ibi me collocavit --
298 super aquam refectionis educavit me,
299 >>>>>>> new9.txt
300 animam meam convertit,
301 deduxit me super semitas jusitiae,
302 propter nomen suum.
303 Nam et si ambulavero in medio umbrae mortis,
304 non timebo mala, quoniam TU mecum es:
305 virga tua et baculus tuus ipsa me consolata sunt.
308 test_must_fail git merge-file -p --diff3 \
309 new8.txt new5.txt new9.txt >actual &&
310 test_cmp expect actual
313 test_expect_success '"diff3 -m" style output (2)' '
314 git config merge.conflictstyle diff3 &&
315 test_must_fail git merge-file -p \
316 new8.txt new5.txt new9.txt >actual &&
317 test_cmp expect actual
320 test_expect_success 'marker size' '
321 cat >expect <<-\EOF &&
322 Dominus regit me,
323 <<<<<<<<<< new8.txt
324 et nihil mihi deerit;
329 In loco pascuae ibi me collocavit;
330 super aquam refectionis educavit me.
331 |||||||||| new5.txt
332 et nihil mihi deerit.
333 In loco pascuae ibi me collocavit,
334 super aquam refectionis educavit me;
335 ==========
336 et nihil mihi deerit,
341 In loco pascuae ibi me collocavit --
342 super aquam refectionis educavit me,
343 >>>>>>>>>> new9.txt
344 animam meam convertit,
345 deduxit me super semitas jusitiae,
346 propter nomen suum.
347 Nam et si ambulavero in medio umbrae mortis,
348 non timebo mala, quoniam TU mecum es:
349 virga tua et baculus tuus ipsa me consolata sunt.
352 test_must_fail git merge-file -p --marker-size=10 \
353 new8.txt new5.txt new9.txt >actual &&
354 test_cmp expect actual
357 test_expect_success 'conflict at EOF without LF resolved by --ours' '
358 printf "line1\nline2\nline3" >nolf-orig.txt &&
359 printf "line1\nline2\nline3x" >nolf-diff1.txt &&
360 printf "line1\nline2\nline3y" >nolf-diff2.txt &&
362 git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
363 printf "line1\nline2\nline3x" >expect.txt &&
364 test_cmp expect.txt output.txt
367 test_expect_success 'conflict at EOF without LF resolved by --theirs' '
368 git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
369 printf "line1\nline2\nline3y" >expect.txt &&
370 test_cmp expect.txt output.txt
373 test_expect_success 'conflict at EOF without LF resolved by --union' '
374 git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt &&
375 printf "line1\nline2\nline3x\nline3y" >expect.txt &&
376 test_cmp expect.txt output.txt
379 test_expect_success 'conflict sections match existing line endings' '
380 printf "1\\r\\n2\\r\\n3" >crlf-orig.txt &&
381 printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt &&
382 printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt &&
383 test_must_fail git -c core.eol=crlf merge-file -p \
384 crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt &&
385 test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 &&
386 test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 &&
387 test_must_fail git -c core.eol=crlf merge-file -p \
388 nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt &&
389 test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0
392 test_done