]>
Commit | Line | Data |
---|---|---|
ba1f5f35 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='RCS merge replacement: merge-file' | |
e72e12cc ÆAB |
4 | |
5 | TEST_PASSES_SANITIZE_LEAK=true | |
ba1f5f35 JS |
6 | . ./test-lib.sh |
7 | ||
42d180dd EN |
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 | |
18 | ||
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 | |
31 | ||
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 | |
40 | ||
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 | |
50 | ||
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 | |
58 | ||
59 | printf "propter nomen suum." >>new4.txt | |
60 | ' | |
ba1f5f35 | 61 | |
5719db91 | 62 | test_expect_success 'merge with no changes' ' |
1cd12926 CB |
63 | cp orig.txt test.txt && |
64 | git merge-file test.txt orig.txt orig.txt && | |
65 | test_cmp test.txt orig.txt | |
66 | ' | |
67 | ||
42d180dd EN |
68 | test_expect_success "merge without conflict" ' |
69 | cp new1.txt test.txt && | |
70 | git merge-file test.txt orig.txt new2.txt | |
71 | ' | |
ba1f5f35 | 72 | |
55846b9a TR |
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 && | |
204a8ffe ABG |
78 | ( cd dir && git merge-file a.txt o.txt b.txt ) && |
79 | test_path_is_missing a.txt | |
55846b9a TR |
80 | ' |
81 | ||
42d180dd EN |
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 | |
85 | ' | |
86 | ||
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 | |
90 | ' | |
91 | ||
92 | test_expect_failure "merge result added missing LF" ' | |
93 | test_cmp test.txt test2.txt | |
94 | ' | |
95 | ||
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 | |
99 | ' | |
100 | ||
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, | |
109 | EOF | |
110 | printf "propter nomen suum." >>expect.txt && | |
111 | ||
112 | test_cmp expect.txt test3.txt | |
113 | ' | |
114 | ||
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 | |
118 | ' | |
119 | ||
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. | |
136 | EOF | |
137 | ||
138 | test_cmp expect.txt test.txt | |
139 | ' | |
140 | ||
141 | test_expect_success "merge conflicting with --ours" ' | |
142 | cp backup.txt test.txt && | |
143 | ||
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. | |
154 | EOF | |
155 | ||
156 | git merge-file --ours test.txt orig.txt new3.txt && | |
157 | test_cmp expect.txt test.txt | |
158 | ' | |
159 | ||
160 | test_expect_success "merge conflicting with --theirs" ' | |
161 | cp backup.txt test.txt && | |
162 | ||
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. | |
174 | EOF | |
175 | ||
176 | git merge-file --theirs test.txt orig.txt new3.txt && | |
177 | test_cmp expect.txt test.txt | |
178 | ' | |
179 | ||
180 | test_expect_success "merge conflicting with --union" ' | |
181 | cp backup.txt test.txt && | |
182 | ||
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. | |
195 | EOF | |
196 | ||
197 | git merge-file --union test.txt orig.txt new3.txt && | |
198 | test_cmp expect.txt test.txt | |
199 | ' | |
200 | ||
201 | test_expect_success "merge with conflicts, using -L" ' | |
202 | cp backup.txt test.txt && | |
203 | ||
204 | test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt | |
205 | ' | |
206 | ||
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. | |
223 | EOF | |
224 | ||
225 | test_cmp expect.txt test.txt | |
226 | ' | |
227 | ||
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 | |
231 | ' | |
232 | ||
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 | |
248 | EOF | |
249 | ||
250 | test_cmp expect out | |
251 | ' | |
5d6b151f | 252 | |
5771907a | 253 | test_expect_success 'binary files cannot be merged' ' |
d492b31c | 254 | test_must_fail git merge-file -p \ |
b5967f82 | 255 | orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err && |
5771907a JS |
256 | grep "Cannot merge binary files" merge.err |
257 | ' | |
258 | ||
f407f14d | 259 | test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' ' |
42d180dd EN |
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 && | |
f407f14d | 262 | |
d492b31c | 263 | test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output && |
42d180dd | 264 | test 1 = $(grep ======= <output | wc -l) |
f407f14d JS |
265 | ' |
266 | ||
ee95ec5d | 267 | test_expect_success 'ZEALOUS_ALNUM' ' |
42d180dd EN |
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 && | |
ee95ec5d | 270 | |
d492b31c | 271 | test_must_fail git merge-file -p \ |
42d180dd EN |
272 | new8.txt new5.txt new9.txt >merge.out && |
273 | test 1 = $(grep ======= <merge.out | wc -l) | |
ee95ec5d JS |
274 | ' |
275 | ||
42d180dd EN |
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; | |
e0af48e4 JH |
281 | |
282 | ||
283 | ||
284 | ||
42d180dd EN |
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, | |
e0af48e4 JH |
293 | |
294 | ||
295 | ||
296 | ||
42d180dd EN |
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. | |
306 | EOF | |
e0af48e4 | 307 | |
e0af48e4 JH |
308 | test_must_fail git merge-file -p --diff3 \ |
309 | new8.txt new5.txt new9.txt >actual && | |
310 | test_cmp expect actual | |
311 | ' | |
312 | ||
b5412484 JH |
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 | |
318 | ' | |
319 | ||
42d180dd EN |
320 | test_expect_success 'marker size' ' |
321 | cat >expect <<-\EOF && | |
322 | Dominus regit me, | |
323 | <<<<<<<<<< new8.txt | |
324 | et nihil mihi deerit; | |
11f3aa23 BW |
325 | |
326 | ||
327 | ||
328 | ||
42d180dd EN |
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, | |
11f3aa23 BW |
337 | |
338 | ||
339 | ||
340 | ||
42d180dd EN |
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. | |
350 | EOF | |
11f3aa23 | 351 | |
11f3aa23 BW |
352 | test_must_fail git merge-file -p --marker-size=10 \ |
353 | new8.txt new5.txt new9.txt >actual && | |
354 | test_cmp expect actual | |
355 | ' | |
356 | ||
42d180dd EN |
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 && | |
ba311807 | 361 | |
42d180dd EN |
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 | |
365 | ' | |
ba311807 | 366 | |
42d180dd EN |
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 | |
371 | ' | |
ba311807 | 372 | |
42d180dd EN |
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 | |
377 | ' | |
ba311807 | 378 | |
15980dea | 379 | test_expect_success 'conflict sections match existing line endings' ' |
86efa215 JS |
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 && | |
15980dea | 386 | test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 && |
86efa215 JS |
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 | |
390 | ' | |
391 | ||
ba1f5f35 | 392 | test_done |