]>
Commit | Line | Data |
---|---|---|
ba1f5f35 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='RCS merge replacement: merge-file' | |
4 | . ./test-lib.sh | |
5 | ||
42d180dd EN |
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 | |
16 | ||
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 | |
29 | ||
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 | |
38 | ||
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 | |
48 | ||
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 | |
56 | ||
57 | printf "propter nomen suum." >>new4.txt | |
58 | ' | |
ba1f5f35 | 59 | |
5719db91 | 60 | test_expect_success 'merge with no changes' ' |
1cd12926 CB |
61 | cp orig.txt test.txt && |
62 | git merge-file test.txt orig.txt orig.txt && | |
63 | test_cmp test.txt orig.txt | |
64 | ' | |
65 | ||
42d180dd EN |
66 | test_expect_success "merge without conflict" ' |
67 | cp new1.txt test.txt && | |
68 | git merge-file test.txt orig.txt new2.txt | |
69 | ' | |
ba1f5f35 | 70 | |
55846b9a TR |
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 && | |
204a8ffe ABG |
76 | ( cd dir && git merge-file a.txt o.txt b.txt ) && |
77 | test_path_is_missing a.txt | |
55846b9a TR |
78 | ' |
79 | ||
42d180dd EN |
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 | |
83 | ' | |
84 | ||
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 | |
88 | ' | |
89 | ||
90 | test_expect_failure "merge result added missing LF" ' | |
91 | test_cmp test.txt test2.txt | |
92 | ' | |
93 | ||
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 | |
97 | ' | |
98 | ||
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, | |
107 | EOF | |
108 | printf "propter nomen suum." >>expect.txt && | |
109 | ||
110 | test_cmp expect.txt test3.txt | |
111 | ' | |
112 | ||
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 | |
116 | ' | |
117 | ||
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. | |
134 | EOF | |
135 | ||
136 | test_cmp expect.txt test.txt | |
137 | ' | |
138 | ||
139 | test_expect_success "merge conflicting with --ours" ' | |
140 | cp backup.txt test.txt && | |
141 | ||
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. | |
152 | EOF | |
153 | ||
154 | git merge-file --ours test.txt orig.txt new3.txt && | |
155 | test_cmp expect.txt test.txt | |
156 | ' | |
157 | ||
158 | test_expect_success "merge conflicting with --theirs" ' | |
159 | cp backup.txt test.txt && | |
160 | ||
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. | |
172 | EOF | |
173 | ||
174 | git merge-file --theirs test.txt orig.txt new3.txt && | |
175 | test_cmp expect.txt test.txt | |
176 | ' | |
177 | ||
178 | test_expect_success "merge conflicting with --union" ' | |
179 | cp backup.txt test.txt && | |
180 | ||
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. | |
193 | EOF | |
194 | ||
195 | git merge-file --union test.txt orig.txt new3.txt && | |
196 | test_cmp expect.txt test.txt | |
197 | ' | |
198 | ||
199 | test_expect_success "merge with conflicts, using -L" ' | |
200 | cp backup.txt test.txt && | |
201 | ||
202 | test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt | |
203 | ' | |
204 | ||
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. | |
221 | EOF | |
222 | ||
223 | test_cmp expect.txt test.txt | |
224 | ' | |
225 | ||
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 | |
229 | ' | |
230 | ||
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 | |
246 | EOF | |
247 | ||
248 | test_cmp expect out | |
249 | ' | |
5d6b151f | 250 | |
5771907a | 251 | test_expect_success 'binary files cannot be merged' ' |
d492b31c | 252 | test_must_fail git merge-file -p \ |
b5967f82 | 253 | orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err && |
5771907a JS |
254 | grep "Cannot merge binary files" merge.err |
255 | ' | |
256 | ||
f407f14d | 257 | test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' ' |
42d180dd EN |
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 && | |
f407f14d | 260 | |
d492b31c | 261 | test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output && |
42d180dd | 262 | test 1 = $(grep ======= <output | wc -l) |
f407f14d JS |
263 | ' |
264 | ||
ee95ec5d | 265 | test_expect_success 'ZEALOUS_ALNUM' ' |
42d180dd EN |
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 && | |
ee95ec5d | 268 | |
d492b31c | 269 | test_must_fail git merge-file -p \ |
42d180dd EN |
270 | new8.txt new5.txt new9.txt >merge.out && |
271 | test 1 = $(grep ======= <merge.out | wc -l) | |
ee95ec5d JS |
272 | ' |
273 | ||
42d180dd EN |
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; | |
e0af48e4 JH |
279 | |
280 | ||
281 | ||
282 | ||
42d180dd EN |
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, | |
e0af48e4 JH |
291 | |
292 | ||
293 | ||
294 | ||
42d180dd EN |
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. | |
304 | EOF | |
e0af48e4 | 305 | |
e0af48e4 JH |
306 | test_must_fail git merge-file -p --diff3 \ |
307 | new8.txt new5.txt new9.txt >actual && | |
308 | test_cmp expect actual | |
309 | ' | |
310 | ||
b5412484 JH |
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 | |
316 | ' | |
317 | ||
42d180dd EN |
318 | test_expect_success 'marker size' ' |
319 | cat >expect <<-\EOF && | |
320 | Dominus regit me, | |
321 | <<<<<<<<<< new8.txt | |
322 | et nihil mihi deerit; | |
11f3aa23 BW |
323 | |
324 | ||
325 | ||
326 | ||
42d180dd EN |
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, | |
11f3aa23 BW |
335 | |
336 | ||
337 | ||
338 | ||
42d180dd EN |
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. | |
348 | EOF | |
11f3aa23 | 349 | |
11f3aa23 BW |
350 | test_must_fail git merge-file -p --marker-size=10 \ |
351 | new8.txt new5.txt new9.txt >actual && | |
352 | test_cmp expect actual | |
353 | ' | |
354 | ||
42d180dd EN |
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 && | |
ba311807 | 359 | |
42d180dd EN |
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 | |
363 | ' | |
ba311807 | 364 | |
42d180dd EN |
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 | |
369 | ' | |
ba311807 | 370 | |
42d180dd EN |
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 | |
375 | ' | |
ba311807 | 376 | |
15980dea | 377 | test_expect_success 'conflict sections match existing line endings' ' |
86efa215 JS |
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 && | |
15980dea | 384 | test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 && |
86efa215 JS |
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 | |
388 | ' | |
389 | ||
ba1f5f35 | 390 | test_done |