]>
Commit | Line | Data |
---|---|---|
ba1f5f35 JS |
1 | #!/bin/sh |
2 | ||
3 | test_description='RCS merge replacement: merge-file' | |
4 | . ./test-lib.sh | |
5 | ||
6 | cat > orig.txt << EOF | |
7 | Dominus regit me, | |
8 | et nihil mihi deerit. | |
9 | In loco pascuae ibi me collocavit, | |
10 | super aquam refectionis educavit me; | |
11 | animam meam convertit, | |
12 | deduxit me super semitas jusitiae, | |
13 | propter nomen suum. | |
14 | EOF | |
15 | ||
16 | cat > new1.txt << EOF | |
17 | Dominus regit me, | |
18 | et nihil mihi deerit. | |
19 | In loco pascuae ibi me collocavit, | |
20 | super aquam refectionis educavit me; | |
21 | animam meam convertit, | |
22 | deduxit me super semitas jusitiae, | |
23 | propter nomen suum. | |
24 | Nam et si ambulavero in medio umbrae mortis, | |
25 | non timebo mala, quoniam tu mecum es: | |
26 | virga tua et baculus tuus ipsa me consolata sunt. | |
27 | EOF | |
28 | ||
29 | cat > new2.txt << EOF | |
30 | Dominus regit me, et nihil mihi deerit. | |
31 | In loco pascuae ibi me collocavit, | |
32 | super aquam refectionis educavit me; | |
33 | animam meam convertit, | |
34 | deduxit me super semitas jusitiae, | |
35 | propter nomen suum. | |
36 | EOF | |
37 | ||
38 | cat > new3.txt << EOF | |
39 | DOMINUS regit me, | |
40 | et nihil mihi deerit. | |
41 | In loco pascuae ibi me collocavit, | |
42 | super aquam refectionis educavit me; | |
43 | animam meam convertit, | |
44 | deduxit me super semitas jusitiae, | |
45 | propter nomen suum. | |
46 | EOF | |
47 | ||
48 | cat > new4.txt << EOF | |
49 | Dominus regit me, et nihil mihi deerit. | |
50 | In loco pascuae ibi me collocavit, | |
51 | super aquam refectionis educavit me; | |
52 | animam meam convertit, | |
53 | deduxit me super semitas jusitiae, | |
54 | EOF | |
2aad957a | 55 | printf "propter nomen suum." >> new4.txt |
ba1f5f35 | 56 | |
5719db91 | 57 | test_expect_success 'merge with no changes' ' |
1cd12926 CB |
58 | cp orig.txt test.txt && |
59 | git merge-file test.txt orig.txt orig.txt && | |
60 | test_cmp test.txt orig.txt | |
61 | ' | |
62 | ||
ba1f5f35 JS |
63 | cp new1.txt test.txt |
64 | test_expect_success "merge without conflict" \ | |
5be60078 | 65 | "git merge-file test.txt orig.txt new2.txt" |
ba1f5f35 | 66 | |
55846b9a TR |
67 | test_expect_success 'works in subdirectory' ' |
68 | mkdir dir && | |
69 | cp new1.txt dir/a.txt && | |
70 | cp orig.txt dir/o.txt && | |
71 | cp new2.txt dir/b.txt && | |
204a8ffe ABG |
72 | ( cd dir && git merge-file a.txt o.txt b.txt ) && |
73 | test_path_is_missing a.txt | |
55846b9a TR |
74 | ' |
75 | ||
3fdcdbdf JS |
76 | cp new1.txt test.txt |
77 | test_expect_success "merge without conflict (--quiet)" \ | |
78 | "git merge-file --quiet test.txt orig.txt new2.txt" | |
79 | ||
ba1f5f35 | 80 | cp new1.txt test2.txt |
6d49de41 MK |
81 | test_expect_failure "merge without conflict (missing LF at EOF)" \ |
82 | "git merge-file test2.txt orig.txt new4.txt" | |
ba1f5f35 | 83 | |
6d49de41 | 84 | test_expect_failure "merge result added missing LF" \ |
3af82863 | 85 | "test_cmp test.txt test2.txt" |
ba1f5f35 | 86 | |
ba311807 MK |
87 | cp new4.txt test3.txt |
88 | test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \ | |
89 | "git merge-file --quiet test3.txt new2.txt new3.txt" | |
90 | ||
91 | cat > expect.txt << EOF | |
92 | DOMINUS regit me, | |
93 | et nihil mihi deerit. | |
94 | In loco pascuae ibi me collocavit, | |
95 | super aquam refectionis educavit me; | |
96 | animam meam convertit, | |
97 | deduxit me super semitas jusitiae, | |
98 | EOF | |
99 | printf "propter nomen suum." >> expect.txt | |
100 | ||
101 | test_expect_success "merge does not add LF away of change" \ | |
102 | "test_cmp test3.txt expect.txt" | |
103 | ||
ba1f5f35 | 104 | cp test.txt backup.txt |
41ac414e | 105 | test_expect_success "merge with conflicts" \ |
d492b31c | 106 | "test_must_fail git merge-file test.txt orig.txt new3.txt" |
ba1f5f35 JS |
107 | |
108 | cat > expect.txt << EOF | |
109 | <<<<<<< test.txt | |
110 | Dominus regit me, et nihil mihi deerit. | |
111 | ======= | |
112 | DOMINUS regit me, | |
113 | et nihil mihi deerit. | |
114 | >>>>>>> new3.txt | |
115 | In loco pascuae ibi me collocavit, | |
116 | super aquam refectionis educavit me; | |
117 | animam meam convertit, | |
118 | deduxit me super semitas jusitiae, | |
119 | propter nomen suum. | |
120 | Nam et si ambulavero in medio umbrae mortis, | |
121 | non timebo mala, quoniam tu mecum es: | |
122 | virga tua et baculus tuus ipsa me consolata sunt. | |
123 | EOF | |
124 | ||
3af82863 | 125 | test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt" |
ba1f5f35 JS |
126 | |
127 | cp backup.txt test.txt | |
ba311807 MK |
128 | |
129 | cat > expect.txt << EOF | |
130 | Dominus regit me, et nihil mihi deerit. | |
131 | In loco pascuae ibi me collocavit, | |
132 | super aquam refectionis educavit me; | |
133 | animam meam convertit, | |
134 | deduxit me super semitas jusitiae, | |
135 | propter nomen suum. | |
136 | Nam et si ambulavero in medio umbrae mortis, | |
137 | non timebo mala, quoniam tu mecum es: | |
138 | virga tua et baculus tuus ipsa me consolata sunt. | |
139 | EOF | |
140 | test_expect_success "merge conflicting with --ours" \ | |
141 | "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
142 | cp backup.txt test.txt | |
143 | ||
144 | cat > expect.txt << EOF | |
145 | DOMINUS regit me, | |
146 | 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, | |
151 | propter nomen suum. | |
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. | |
155 | EOF | |
156 | test_expect_success "merge conflicting with --theirs" \ | |
157 | "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
158 | cp backup.txt test.txt | |
159 | ||
160 | cat > expect.txt << EOF | |
161 | Dominus regit me, et nihil mihi deerit. | |
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 | test_expect_success "merge conflicting with --union" \ | |
174 | "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
175 | cp backup.txt test.txt | |
176 | ||
41ac414e | 177 | test_expect_success "merge with conflicts, using -L" \ |
d492b31c | 178 | "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt" |
ba1f5f35 JS |
179 | |
180 | cat > expect.txt << EOF | |
181 | <<<<<<< 1 | |
182 | Dominus regit me, et nihil mihi deerit. | |
183 | ======= | |
184 | DOMINUS regit me, | |
185 | et nihil mihi deerit. | |
186 | >>>>>>> new3.txt | |
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 | test_expect_success "expected conflict markers, with -L" \ | |
3af82863 | 198 | "test_cmp test.txt expect.txt" |
ba1f5f35 | 199 | |
5d6b151f | 200 | sed "s/ tu / TU /" < new1.txt > new5.txt |
41ac414e | 201 | test_expect_success "conflict in removed tail" \ |
d492b31c | 202 | "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out" |
5d6b151f JS |
203 | |
204 | cat > expect << EOF | |
205 | Dominus regit me, | |
206 | et nihil mihi deerit. | |
207 | In loco pascuae ibi me collocavit, | |
208 | super aquam refectionis educavit me; | |
209 | animam meam convertit, | |
210 | deduxit me super semitas jusitiae, | |
211 | propter nomen suum. | |
212 | <<<<<<< orig.txt | |
213 | ======= | |
214 | Nam et si ambulavero in medio umbrae mortis, | |
215 | non timebo mala, quoniam TU mecum es: | |
216 | virga tua et baculus tuus ipsa me consolata sunt. | |
217 | >>>>>>> new5.txt | |
218 | EOF | |
219 | ||
3af82863 | 220 | test_expect_success "expected conflict markers" "test_cmp expect out" |
5d6b151f | 221 | |
5771907a | 222 | test_expect_success 'binary files cannot be merged' ' |
d492b31c | 223 | test_must_fail git merge-file -p \ |
b5967f82 | 224 | orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err && |
5771907a JS |
225 | grep "Cannot merge binary files" merge.err |
226 | ' | |
227 | ||
9524cf29 SB |
228 | sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt |
229 | sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt | |
f407f14d JS |
230 | |
231 | test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' ' | |
232 | ||
d492b31c | 233 | test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output && |
f407f14d JS |
234 | test 1 = $(grep ======= < output | wc -l) |
235 | ||
236 | ' | |
237 | ||
10708a99 AL |
238 | sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt |
239 | sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt | |
ee95ec5d JS |
240 | |
241 | test_expect_success 'ZEALOUS_ALNUM' ' | |
242 | ||
d492b31c SB |
243 | test_must_fail git merge-file -p \ |
244 | new8.txt new5.txt new9.txt > merge.out && | |
ee95ec5d JS |
245 | test 1 = $(grep ======= < merge.out | wc -l) |
246 | ||
247 | ' | |
248 | ||
e0af48e4 JH |
249 | cat >expect <<\EOF |
250 | Dominus regit me, | |
251 | <<<<<<< new8.txt | |
252 | et nihil mihi deerit; | |
253 | ||
254 | ||
255 | ||
256 | ||
257 | In loco pascuae ibi me collocavit; | |
258 | super aquam refectionis educavit me. | |
4bb09362 | 259 | ||||||| new5.txt |
e0af48e4 JH |
260 | et nihil mihi deerit. |
261 | In loco pascuae ibi me collocavit, | |
262 | super aquam refectionis educavit me; | |
263 | ======= | |
264 | et nihil mihi deerit, | |
265 | ||
266 | ||
267 | ||
268 | ||
269 | In loco pascuae ibi me collocavit -- | |
270 | super aquam refectionis educavit me, | |
271 | >>>>>>> new9.txt | |
272 | animam meam convertit, | |
273 | deduxit me super semitas jusitiae, | |
274 | propter nomen suum. | |
275 | Nam et si ambulavero in medio umbrae mortis, | |
276 | non timebo mala, quoniam TU mecum es: | |
277 | virga tua et baculus tuus ipsa me consolata sunt. | |
278 | EOF | |
279 | ||
b5412484 | 280 | test_expect_success '"diff3 -m" style output (1)' ' |
e0af48e4 JH |
281 | test_must_fail git merge-file -p --diff3 \ |
282 | new8.txt new5.txt new9.txt >actual && | |
283 | test_cmp expect actual | |
284 | ' | |
285 | ||
b5412484 JH |
286 | test_expect_success '"diff3 -m" style output (2)' ' |
287 | git config merge.conflictstyle diff3 && | |
288 | test_must_fail git merge-file -p \ | |
289 | new8.txt new5.txt new9.txt >actual && | |
290 | test_cmp expect actual | |
291 | ' | |
292 | ||
11f3aa23 BW |
293 | cat >expect <<\EOF |
294 | Dominus regit me, | |
295 | <<<<<<<<<< new8.txt | |
296 | et nihil mihi deerit; | |
297 | ||
298 | ||
299 | ||
300 | ||
301 | In loco pascuae ibi me collocavit; | |
302 | super aquam refectionis educavit me. | |
4bb09362 | 303 | |||||||||| new5.txt |
11f3aa23 BW |
304 | et nihil mihi deerit. |
305 | In loco pascuae ibi me collocavit, | |
306 | super aquam refectionis educavit me; | |
307 | ========== | |
308 | et nihil mihi deerit, | |
309 | ||
310 | ||
311 | ||
312 | ||
313 | In loco pascuae ibi me collocavit -- | |
314 | super aquam refectionis educavit me, | |
315 | >>>>>>>>>> new9.txt | |
316 | animam meam convertit, | |
317 | deduxit me super semitas jusitiae, | |
318 | propter nomen suum. | |
319 | Nam et si ambulavero in medio umbrae mortis, | |
320 | non timebo mala, quoniam TU mecum es: | |
321 | virga tua et baculus tuus ipsa me consolata sunt. | |
322 | EOF | |
323 | ||
324 | test_expect_success 'marker size' ' | |
325 | test_must_fail git merge-file -p --marker-size=10 \ | |
326 | new8.txt new5.txt new9.txt >actual && | |
327 | test_cmp expect actual | |
328 | ' | |
329 | ||
ba311807 MK |
330 | printf "line1\nline2\nline3" >nolf-orig.txt |
331 | printf "line1\nline2\nline3x" >nolf-diff1.txt | |
332 | printf "line1\nline2\nline3y" >nolf-diff2.txt | |
333 | ||
334 | test_expect_success 'conflict at EOF without LF resolved by --ours' \ | |
335 | 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
336 | printf "line1\nline2\nline3x" >expect.txt && | |
337 | test_cmp expect.txt output.txt' | |
338 | ||
339 | test_expect_success 'conflict at EOF without LF resolved by --theirs' \ | |
340 | 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
341 | printf "line1\nline2\nline3y" >expect.txt && | |
342 | test_cmp expect.txt output.txt' | |
343 | ||
344 | test_expect_success 'conflict at EOF without LF resolved by --union' \ | |
345 | 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
346 | printf "line1\nline2\nline3x\nline3y" >expect.txt && | |
347 | test_cmp expect.txt output.txt' | |
348 | ||
15980dea | 349 | test_expect_success 'conflict sections match existing line endings' ' |
86efa215 JS |
350 | printf "1\\r\\n2\\r\\n3" >crlf-orig.txt && |
351 | printf "1\\r\\n2\\r\\n4" >crlf-diff1.txt && | |
352 | printf "1\\r\\n2\\r\\n5" >crlf-diff2.txt && | |
353 | test_must_fail git -c core.eol=crlf merge-file -p \ | |
354 | crlf-diff1.txt crlf-orig.txt crlf-diff2.txt >crlf.txt && | |
355 | test $(tr "\015" Q <crlf.txt | grep "^[<=>].*Q$" | wc -l) = 3 && | |
15980dea | 356 | test $(tr "\015" Q <crlf.txt | grep "[345]Q$" | wc -l) = 3 && |
86efa215 JS |
357 | test_must_fail git -c core.eol=crlf merge-file -p \ |
358 | nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >nolf.txt && | |
359 | test $(tr "\015" Q <nolf.txt | grep "^[<=>].*Q$" | wc -l) = 0 | |
360 | ' | |
361 | ||
ba1f5f35 | 362 | test_done |