]>
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 && | |
72 | ( cd dir && git merge-file a.txt o.txt b.txt ) | |
73 | ' | |
74 | ||
3fdcdbdf JS |
75 | cp new1.txt test.txt |
76 | test_expect_success "merge without conflict (--quiet)" \ | |
77 | "git merge-file --quiet test.txt orig.txt new2.txt" | |
78 | ||
ba1f5f35 | 79 | cp new1.txt test2.txt |
6d49de41 MK |
80 | test_expect_failure "merge without conflict (missing LF at EOF)" \ |
81 | "git merge-file test2.txt orig.txt new4.txt" | |
ba1f5f35 | 82 | |
6d49de41 | 83 | test_expect_failure "merge result added missing LF" \ |
3af82863 | 84 | "test_cmp test.txt test2.txt" |
ba1f5f35 | 85 | |
ba311807 MK |
86 | cp new4.txt test3.txt |
87 | test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \ | |
88 | "git merge-file --quiet test3.txt new2.txt new3.txt" | |
89 | ||
90 | cat > expect.txt << EOF | |
91 | DOMINUS regit me, | |
92 | et nihil mihi deerit. | |
93 | In loco pascuae ibi me collocavit, | |
94 | super aquam refectionis educavit me; | |
95 | animam meam convertit, | |
96 | deduxit me super semitas jusitiae, | |
97 | EOF | |
98 | printf "propter nomen suum." >> expect.txt | |
99 | ||
100 | test_expect_success "merge does not add LF away of change" \ | |
101 | "test_cmp test3.txt expect.txt" | |
102 | ||
ba1f5f35 | 103 | cp test.txt backup.txt |
41ac414e | 104 | test_expect_success "merge with conflicts" \ |
d492b31c | 105 | "test_must_fail git merge-file test.txt orig.txt new3.txt" |
ba1f5f35 JS |
106 | |
107 | cat > expect.txt << EOF | |
108 | <<<<<<< test.txt | |
109 | Dominus regit me, et nihil mihi deerit. | |
110 | ======= | |
111 | DOMINUS regit me, | |
112 | et nihil mihi deerit. | |
113 | >>>>>>> new3.txt | |
114 | In loco pascuae ibi me collocavit, | |
115 | super aquam refectionis educavit me; | |
116 | animam meam convertit, | |
117 | deduxit me super semitas jusitiae, | |
118 | propter nomen suum. | |
119 | Nam et si ambulavero in medio umbrae mortis, | |
120 | non timebo mala, quoniam tu mecum es: | |
121 | virga tua et baculus tuus ipsa me consolata sunt. | |
122 | EOF | |
123 | ||
3af82863 | 124 | test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt" |
ba1f5f35 JS |
125 | |
126 | cp backup.txt test.txt | |
ba311807 MK |
127 | |
128 | cat > expect.txt << EOF | |
129 | Dominus regit me, et nihil mihi deerit. | |
130 | In loco pascuae ibi me collocavit, | |
131 | super aquam refectionis educavit me; | |
132 | animam meam convertit, | |
133 | deduxit me super semitas jusitiae, | |
134 | propter nomen suum. | |
135 | Nam et si ambulavero in medio umbrae mortis, | |
136 | non timebo mala, quoniam tu mecum es: | |
137 | virga tua et baculus tuus ipsa me consolata sunt. | |
138 | EOF | |
139 | test_expect_success "merge conflicting with --ours" \ | |
140 | "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
141 | cp backup.txt test.txt | |
142 | ||
143 | cat > expect.txt << EOF | |
144 | DOMINUS regit me, | |
145 | 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 | test_expect_success "merge conflicting with --theirs" \ | |
156 | "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
157 | cp backup.txt test.txt | |
158 | ||
159 | cat > expect.txt << EOF | |
160 | Dominus regit me, et nihil mihi deerit. | |
161 | DOMINUS regit me, | |
162 | et nihil mihi deerit. | |
163 | In loco pascuae ibi me collocavit, | |
164 | super aquam refectionis educavit me; | |
165 | animam meam convertit, | |
166 | deduxit me super semitas jusitiae, | |
167 | propter nomen suum. | |
168 | Nam et si ambulavero in medio umbrae mortis, | |
169 | non timebo mala, quoniam tu mecum es: | |
170 | virga tua et baculus tuus ipsa me consolata sunt. | |
171 | EOF | |
172 | test_expect_success "merge conflicting with --union" \ | |
173 | "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" | |
174 | cp backup.txt test.txt | |
175 | ||
41ac414e | 176 | test_expect_success "merge with conflicts, using -L" \ |
d492b31c | 177 | "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt" |
ba1f5f35 JS |
178 | |
179 | cat > expect.txt << EOF | |
180 | <<<<<<< 1 | |
181 | Dominus regit me, et nihil mihi deerit. | |
182 | ======= | |
183 | DOMINUS regit me, | |
184 | et nihil mihi deerit. | |
185 | >>>>>>> new3.txt | |
186 | In loco pascuae ibi me collocavit, | |
187 | super aquam refectionis educavit me; | |
188 | animam meam convertit, | |
189 | deduxit me super semitas jusitiae, | |
190 | propter nomen suum. | |
191 | Nam et si ambulavero in medio umbrae mortis, | |
192 | non timebo mala, quoniam tu mecum es: | |
193 | virga tua et baculus tuus ipsa me consolata sunt. | |
194 | EOF | |
195 | ||
196 | test_expect_success "expected conflict markers, with -L" \ | |
3af82863 | 197 | "test_cmp test.txt expect.txt" |
ba1f5f35 | 198 | |
5d6b151f | 199 | sed "s/ tu / TU /" < new1.txt > new5.txt |
41ac414e | 200 | test_expect_success "conflict in removed tail" \ |
d492b31c | 201 | "test_must_fail git merge-file -p orig.txt new1.txt new5.txt > out" |
5d6b151f JS |
202 | |
203 | cat > expect << EOF | |
204 | Dominus regit me, | |
205 | et nihil mihi deerit. | |
206 | In loco pascuae ibi me collocavit, | |
207 | super aquam refectionis educavit me; | |
208 | animam meam convertit, | |
209 | deduxit me super semitas jusitiae, | |
210 | propter nomen suum. | |
211 | <<<<<<< orig.txt | |
212 | ======= | |
213 | Nam et si ambulavero in medio umbrae mortis, | |
214 | non timebo mala, quoniam TU mecum es: | |
215 | virga tua et baculus tuus ipsa me consolata sunt. | |
216 | >>>>>>> new5.txt | |
217 | EOF | |
218 | ||
3af82863 | 219 | test_expect_success "expected conflict markers" "test_cmp expect out" |
5d6b151f | 220 | |
5771907a | 221 | test_expect_success 'binary files cannot be merged' ' |
d492b31c | 222 | test_must_fail git merge-file -p \ |
b5967f82 | 223 | orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err && |
5771907a JS |
224 | grep "Cannot merge binary files" merge.err |
225 | ' | |
226 | ||
9524cf29 SB |
227 | sed -e "s/deerit.\$/deerit;/" -e "s/me;\$/me./" < new5.txt > new6.txt |
228 | sed -e "s/deerit.\$/deerit,/" -e "s/me;\$/me,/" < new5.txt > new7.txt | |
f407f14d JS |
229 | |
230 | test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' ' | |
231 | ||
d492b31c | 232 | test_must_fail git merge-file -p new6.txt new5.txt new7.txt > output && |
f407f14d JS |
233 | test 1 = $(grep ======= < output | wc -l) |
234 | ||
235 | ' | |
236 | ||
10708a99 AL |
237 | sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt |
238 | sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt | |
ee95ec5d JS |
239 | |
240 | test_expect_success 'ZEALOUS_ALNUM' ' | |
241 | ||
d492b31c SB |
242 | test_must_fail git merge-file -p \ |
243 | new8.txt new5.txt new9.txt > merge.out && | |
ee95ec5d JS |
244 | test 1 = $(grep ======= < merge.out | wc -l) |
245 | ||
246 | ' | |
247 | ||
e0af48e4 JH |
248 | cat >expect <<\EOF |
249 | Dominus regit me, | |
250 | <<<<<<< new8.txt | |
251 | et nihil mihi deerit; | |
252 | ||
253 | ||
254 | ||
255 | ||
256 | In loco pascuae ibi me collocavit; | |
257 | super aquam refectionis educavit me. | |
4bb09362 | 258 | ||||||| new5.txt |
e0af48e4 JH |
259 | et nihil mihi deerit. |
260 | In loco pascuae ibi me collocavit, | |
261 | super aquam refectionis educavit me; | |
262 | ======= | |
263 | et nihil mihi deerit, | |
264 | ||
265 | ||
266 | ||
267 | ||
268 | In loco pascuae ibi me collocavit -- | |
269 | super aquam refectionis educavit me, | |
270 | >>>>>>> new9.txt | |
271 | animam meam convertit, | |
272 | deduxit me super semitas jusitiae, | |
273 | propter nomen suum. | |
274 | Nam et si ambulavero in medio umbrae mortis, | |
275 | non timebo mala, quoniam TU mecum es: | |
276 | virga tua et baculus tuus ipsa me consolata sunt. | |
277 | EOF | |
278 | ||
b5412484 | 279 | test_expect_success '"diff3 -m" style output (1)' ' |
e0af48e4 JH |
280 | test_must_fail git merge-file -p --diff3 \ |
281 | new8.txt new5.txt new9.txt >actual && | |
282 | test_cmp expect actual | |
283 | ' | |
284 | ||
b5412484 JH |
285 | test_expect_success '"diff3 -m" style output (2)' ' |
286 | git config merge.conflictstyle diff3 && | |
287 | test_must_fail git merge-file -p \ | |
288 | new8.txt new5.txt new9.txt >actual && | |
289 | test_cmp expect actual | |
290 | ' | |
291 | ||
11f3aa23 BW |
292 | cat >expect <<\EOF |
293 | Dominus regit me, | |
294 | <<<<<<<<<< new8.txt | |
295 | et nihil mihi deerit; | |
296 | ||
297 | ||
298 | ||
299 | ||
300 | In loco pascuae ibi me collocavit; | |
301 | super aquam refectionis educavit me. | |
4bb09362 | 302 | |||||||||| new5.txt |
11f3aa23 BW |
303 | et nihil mihi deerit. |
304 | In loco pascuae ibi me collocavit, | |
305 | super aquam refectionis educavit me; | |
306 | ========== | |
307 | et nihil mihi deerit, | |
308 | ||
309 | ||
310 | ||
311 | ||
312 | In loco pascuae ibi me collocavit -- | |
313 | super aquam refectionis educavit me, | |
314 | >>>>>>>>>> new9.txt | |
315 | animam meam convertit, | |
316 | deduxit me super semitas jusitiae, | |
317 | propter nomen suum. | |
318 | Nam et si ambulavero in medio umbrae mortis, | |
319 | non timebo mala, quoniam TU mecum es: | |
320 | virga tua et baculus tuus ipsa me consolata sunt. | |
321 | EOF | |
322 | ||
323 | test_expect_success 'marker size' ' | |
324 | test_must_fail git merge-file -p --marker-size=10 \ | |
325 | new8.txt new5.txt new9.txt >actual && | |
326 | test_cmp expect actual | |
327 | ' | |
328 | ||
ba311807 MK |
329 | printf "line1\nline2\nline3" >nolf-orig.txt |
330 | printf "line1\nline2\nline3x" >nolf-diff1.txt | |
331 | printf "line1\nline2\nline3y" >nolf-diff2.txt | |
332 | ||
333 | test_expect_success 'conflict at EOF without LF resolved by --ours' \ | |
334 | 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
335 | printf "line1\nline2\nline3x" >expect.txt && | |
336 | test_cmp expect.txt output.txt' | |
337 | ||
338 | test_expect_success 'conflict at EOF without LF resolved by --theirs' \ | |
339 | 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
340 | printf "line1\nline2\nline3y" >expect.txt && | |
341 | test_cmp expect.txt output.txt' | |
342 | ||
343 | test_expect_success 'conflict at EOF without LF resolved by --union' \ | |
344 | 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && | |
345 | printf "line1\nline2\nline3x\nline3y" >expect.txt && | |
346 | test_cmp expect.txt output.txt' | |
347 | ||
ba1f5f35 | 348 | test_done |