]>
Commit | Line | Data |
---|---|---|
885b9810 JH |
1 | #!/bin/sh |
2 | ||
3 | test_description='merge-recursive backend test' | |
4 | ||
5 | . ./test-lib.sh | |
6 | ||
7 | test_expect_success 'setup 1' ' | |
8 | ||
9 | echo hello >a && | |
10 | o0=$(git hash-object a) && | |
11 | cp a b && | |
744747ef | 12 | cp a c && |
885b9810 JH |
13 | mkdir d && |
14 | cp a d/e && | |
15 | ||
16 | test_tick && | |
744747ef | 17 | git add a b c d/e && |
885b9810 JH |
18 | git commit -m initial && |
19 | c0=$(git rev-parse --verify HEAD) && | |
20 | git branch side && | |
21 | git branch df-1 && | |
22 | git branch df-2 && | |
23 | git branch df-3 && | |
24 | git branch remove && | |
7d82b06d | 25 | git branch submod && |
d5af5105 SK |
26 | git branch copy && |
27 | git branch rename && | |
bba56042 | 28 | git branch rename-ln && |
885b9810 JH |
29 | |
30 | echo hello >>a && | |
31 | cp a d/e && | |
32 | o1=$(git hash-object a) && | |
33 | ||
34 | git add a d/e && | |
35 | ||
36 | test_tick && | |
37 | git commit -m "master modifies a and d/e" && | |
38 | c1=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 39 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 40 | ( |
b6c32f63 ES |
41 | echo "100644 blob $o1 a" && |
42 | echo "100644 blob $o0 b" && | |
43 | echo "100644 blob $o0 c" && | |
44 | echo "100644 blob $o1 d/e" && | |
45 | echo "100644 $o1 0 a" && | |
46 | echo "100644 $o0 0 b" && | |
47 | echo "100644 $o0 0 c" && | |
885b9810 JH |
48 | echo "100644 $o1 0 d/e" |
49 | ) >expected && | |
3af82863 | 50 | test_cmp expected actual |
885b9810 JH |
51 | ' |
52 | ||
53 | test_expect_success 'setup 2' ' | |
54 | ||
744747ef | 55 | rm -rf [abcd] && |
885b9810 | 56 | git checkout side && |
b6c32f63 | 57 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 58 | ( |
b6c32f63 ES |
59 | echo "100644 blob $o0 a" && |
60 | echo "100644 blob $o0 b" && | |
61 | echo "100644 blob $o0 c" && | |
62 | echo "100644 blob $o0 d/e" && | |
63 | echo "100644 $o0 0 a" && | |
64 | echo "100644 $o0 0 b" && | |
65 | echo "100644 $o0 0 c" && | |
885b9810 JH |
66 | echo "100644 $o0 0 d/e" |
67 | ) >expected && | |
3af82863 | 68 | test_cmp expected actual && |
885b9810 JH |
69 | |
70 | echo goodbye >>a && | |
71 | o2=$(git hash-object a) && | |
72 | ||
73 | git add a && | |
74 | ||
75 | test_tick && | |
76 | git commit -m "side modifies a" && | |
77 | c2=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 78 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 79 | ( |
b6c32f63 ES |
80 | echo "100644 blob $o2 a" && |
81 | echo "100644 blob $o0 b" && | |
82 | echo "100644 blob $o0 c" && | |
83 | echo "100644 blob $o0 d/e" && | |
84 | echo "100644 $o2 0 a" && | |
85 | echo "100644 $o0 0 b" && | |
86 | echo "100644 $o0 0 c" && | |
885b9810 JH |
87 | echo "100644 $o0 0 d/e" |
88 | ) >expected && | |
3af82863 | 89 | test_cmp expected actual |
885b9810 JH |
90 | ' |
91 | ||
92 | test_expect_success 'setup 3' ' | |
93 | ||
744747ef | 94 | rm -rf [abcd] && |
885b9810 | 95 | git checkout df-1 && |
b6c32f63 | 96 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 97 | ( |
b6c32f63 ES |
98 | echo "100644 blob $o0 a" && |
99 | echo "100644 blob $o0 b" && | |
100 | echo "100644 blob $o0 c" && | |
101 | echo "100644 blob $o0 d/e" && | |
102 | echo "100644 $o0 0 a" && | |
103 | echo "100644 $o0 0 b" && | |
104 | echo "100644 $o0 0 c" && | |
885b9810 JH |
105 | echo "100644 $o0 0 d/e" |
106 | ) >expected && | |
3af82863 | 107 | test_cmp expected actual && |
885b9810 JH |
108 | |
109 | rm -f b && mkdir b && echo df-1 >b/c && git add b/c && | |
110 | o3=$(git hash-object b/c) && | |
111 | ||
112 | test_tick && | |
113 | git commit -m "df-1 makes b/c" && | |
114 | c3=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 115 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 116 | ( |
b6c32f63 ES |
117 | echo "100644 blob $o0 a" && |
118 | echo "100644 blob $o3 b/c" && | |
119 | echo "100644 blob $o0 c" && | |
120 | echo "100644 blob $o0 d/e" && | |
121 | echo "100644 $o0 0 a" && | |
122 | echo "100644 $o3 0 b/c" && | |
123 | echo "100644 $o0 0 c" && | |
885b9810 JH |
124 | echo "100644 $o0 0 d/e" |
125 | ) >expected && | |
3af82863 | 126 | test_cmp expected actual |
885b9810 JH |
127 | ' |
128 | ||
129 | test_expect_success 'setup 4' ' | |
130 | ||
744747ef | 131 | rm -rf [abcd] && |
885b9810 | 132 | git checkout df-2 && |
b6c32f63 | 133 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 134 | ( |
b6c32f63 ES |
135 | echo "100644 blob $o0 a" && |
136 | echo "100644 blob $o0 b" && | |
137 | echo "100644 blob $o0 c" && | |
138 | echo "100644 blob $o0 d/e" && | |
139 | echo "100644 $o0 0 a" && | |
140 | echo "100644 $o0 0 b" && | |
141 | echo "100644 $o0 0 c" && | |
885b9810 JH |
142 | echo "100644 $o0 0 d/e" |
143 | ) >expected && | |
3af82863 | 144 | test_cmp expected actual && |
885b9810 JH |
145 | |
146 | rm -f a && mkdir a && echo df-2 >a/c && git add a/c && | |
147 | o4=$(git hash-object a/c) && | |
148 | ||
149 | test_tick && | |
150 | git commit -m "df-2 makes a/c" && | |
151 | c4=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 152 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 153 | ( |
b6c32f63 ES |
154 | echo "100644 blob $o4 a/c" && |
155 | echo "100644 blob $o0 b" && | |
156 | echo "100644 blob $o0 c" && | |
157 | echo "100644 blob $o0 d/e" && | |
158 | echo "100644 $o4 0 a/c" && | |
159 | echo "100644 $o0 0 b" && | |
160 | echo "100644 $o0 0 c" && | |
885b9810 JH |
161 | echo "100644 $o0 0 d/e" |
162 | ) >expected && | |
3af82863 | 163 | test_cmp expected actual |
885b9810 JH |
164 | ' |
165 | ||
166 | test_expect_success 'setup 5' ' | |
167 | ||
744747ef | 168 | rm -rf [abcd] && |
885b9810 | 169 | git checkout remove && |
b6c32f63 | 170 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 171 | ( |
b6c32f63 ES |
172 | echo "100644 blob $o0 a" && |
173 | echo "100644 blob $o0 b" && | |
174 | echo "100644 blob $o0 c" && | |
175 | echo "100644 blob $o0 d/e" && | |
176 | echo "100644 $o0 0 a" && | |
177 | echo "100644 $o0 0 b" && | |
178 | echo "100644 $o0 0 c" && | |
885b9810 JH |
179 | echo "100644 $o0 0 d/e" |
180 | ) >expected && | |
3af82863 | 181 | test_cmp expected actual && |
885b9810 JH |
182 | |
183 | rm -f b && | |
184 | echo remove-conflict >a && | |
185 | ||
186 | git add a && | |
187 | git rm b && | |
188 | o5=$(git hash-object a) && | |
189 | ||
190 | test_tick && | |
191 | git commit -m "remove removes b and modifies a" && | |
192 | c5=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 193 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 194 | ( |
b6c32f63 ES |
195 | echo "100644 blob $o5 a" && |
196 | echo "100644 blob $o0 c" && | |
197 | echo "100644 blob $o0 d/e" && | |
198 | echo "100644 $o5 0 a" && | |
199 | echo "100644 $o0 0 c" && | |
885b9810 JH |
200 | echo "100644 $o0 0 d/e" |
201 | ) >expected && | |
3af82863 | 202 | test_cmp expected actual |
885b9810 JH |
203 | |
204 | ' | |
205 | ||
206 | test_expect_success 'setup 6' ' | |
207 | ||
744747ef | 208 | rm -rf [abcd] && |
885b9810 | 209 | git checkout df-3 && |
b6c32f63 | 210 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 211 | ( |
b6c32f63 ES |
212 | echo "100644 blob $o0 a" && |
213 | echo "100644 blob $o0 b" && | |
214 | echo "100644 blob $o0 c" && | |
215 | echo "100644 blob $o0 d/e" && | |
216 | echo "100644 $o0 0 a" && | |
217 | echo "100644 $o0 0 b" && | |
218 | echo "100644 $o0 0 c" && | |
885b9810 JH |
219 | echo "100644 $o0 0 d/e" |
220 | ) >expected && | |
3af82863 | 221 | test_cmp expected actual && |
885b9810 JH |
222 | |
223 | rm -fr d && echo df-3 >d && git add d && | |
224 | o6=$(git hash-object d) && | |
225 | ||
226 | test_tick && | |
227 | git commit -m "df-3 makes d" && | |
228 | c6=$(git rev-parse --verify HEAD) && | |
b6c32f63 | 229 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
885b9810 | 230 | ( |
b6c32f63 ES |
231 | echo "100644 blob $o0 a" && |
232 | echo "100644 blob $o0 b" && | |
233 | echo "100644 blob $o0 c" && | |
234 | echo "100644 blob $o6 d" && | |
235 | echo "100644 $o0 0 a" && | |
236 | echo "100644 $o0 0 b" && | |
237 | echo "100644 $o0 0 c" && | |
885b9810 JH |
238 | echo "100644 $o6 0 d" |
239 | ) >expected && | |
3af82863 | 240 | test_cmp expected actual |
885b9810 JH |
241 | ' |
242 | ||
7d82b06d JS |
243 | test_expect_success 'setup 7' ' |
244 | ||
245 | git checkout submod && | |
246 | git rm d/e && | |
247 | test_tick && | |
248 | git commit -m "remove d/e" && | |
249 | git update-index --add --cacheinfo 160000 $c1 d && | |
250 | test_tick && | |
251 | git commit -m "make d/ a submodule" | |
252 | ' | |
253 | ||
d5af5105 SK |
254 | test_expect_success 'setup 8' ' |
255 | git checkout rename && | |
256 | git mv a e && | |
257 | git add e && | |
258 | test_tick && | |
8a1c0d32 | 259 | git commit -m "rename a->e" && |
29d9af58 | 260 | c7=$(git rev-parse --verify HEAD) && |
bba56042 JS |
261 | git checkout rename-ln && |
262 | git mv a e && | |
263 | test_ln_s_add e a && | |
264 | test_tick && | |
265 | git commit -m "rename a->e, symlink a->e" && | |
85aea1e7 | 266 | oln=$(printf e | git hash-object --stdin) |
d5af5105 SK |
267 | ' |
268 | ||
269 | test_expect_success 'setup 9' ' | |
270 | git checkout copy && | |
271 | cp a e && | |
272 | git add e && | |
273 | test_tick && | |
274 | git commit -m "copy a->e" | |
275 | ' | |
276 | ||
885b9810 JH |
277 | test_expect_success 'merge-recursive simple' ' |
278 | ||
744747ef | 279 | rm -fr [abcd] && |
885b9810 JH |
280 | git checkout -f "$c2" && |
281 | ||
67b6afe1 | 282 | test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1" |
885b9810 JH |
283 | ' |
284 | ||
285 | test_expect_success 'merge-recursive result' ' | |
286 | ||
287 | git ls-files -s >actual && | |
288 | ( | |
b6c32f63 ES |
289 | echo "100644 $o0 1 a" && |
290 | echo "100644 $o2 2 a" && | |
291 | echo "100644 $o1 3 a" && | |
292 | echo "100644 $o0 0 b" && | |
293 | echo "100644 $o0 0 c" && | |
885b9810 JH |
294 | echo "100644 $o1 0 d/e" |
295 | ) >expected && | |
3af82863 | 296 | test_cmp expected actual |
885b9810 JH |
297 | |
298 | ' | |
299 | ||
f2c8c800 | 300 | test_expect_success 'fail if the index has unresolved entries' ' |
446247db JH |
301 | |
302 | rm -fr [abcd] && | |
303 | git checkout -f "$c1" && | |
304 | ||
305 | test_must_fail git merge "$c5" && | |
306 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 307 | test_i18ngrep "not possible because you have unmerged files" out && |
d38a30df MM |
308 | git add -u && |
309 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 310 | test_i18ngrep "You have not concluded your merge" out && |
c8c562a2 CB |
311 | rm -f .git/MERGE_HEAD && |
312 | test_must_fail git merge "$c5" 2> out && | |
f2c8c800 | 313 | test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out |
446247db JH |
314 | ' |
315 | ||
885b9810 JH |
316 | test_expect_success 'merge-recursive remove conflict' ' |
317 | ||
744747ef | 318 | rm -fr [abcd] && |
885b9810 JH |
319 | git checkout -f "$c1" && |
320 | ||
67b6afe1 | 321 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5" |
885b9810 JH |
322 | ' |
323 | ||
324 | test_expect_success 'merge-recursive remove conflict' ' | |
325 | ||
326 | git ls-files -s >actual && | |
327 | ( | |
b6c32f63 ES |
328 | echo "100644 $o0 1 a" && |
329 | echo "100644 $o1 2 a" && | |
330 | echo "100644 $o5 3 a" && | |
331 | echo "100644 $o0 0 c" && | |
885b9810 JH |
332 | echo "100644 $o1 0 d/e" |
333 | ) >expected && | |
3af82863 | 334 | test_cmp expected actual |
885b9810 JH |
335 | |
336 | ' | |
337 | ||
338 | test_expect_success 'merge-recursive d/f simple' ' | |
744747ef | 339 | rm -fr [abcd] && |
885b9810 JH |
340 | git reset --hard && |
341 | git checkout -f "$c1" && | |
342 | ||
0cb0e143 | 343 | git merge-recursive "$c0" -- "$c1" "$c3" |
885b9810 JH |
344 | ' |
345 | ||
346 | test_expect_success 'merge-recursive result' ' | |
347 | ||
348 | git ls-files -s >actual && | |
349 | ( | |
b6c32f63 ES |
350 | echo "100644 $o1 0 a" && |
351 | echo "100644 $o3 0 b/c" && | |
352 | echo "100644 $o0 0 c" && | |
885b9810 JH |
353 | echo "100644 $o1 0 d/e" |
354 | ) >expected && | |
3af82863 | 355 | test_cmp expected actual |
885b9810 JH |
356 | |
357 | ' | |
358 | ||
359 | test_expect_success 'merge-recursive d/f conflict' ' | |
360 | ||
744747ef | 361 | rm -fr [abcd] && |
885b9810 JH |
362 | git reset --hard && |
363 | git checkout -f "$c1" && | |
364 | ||
67b6afe1 | 365 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4" |
885b9810 JH |
366 | ' |
367 | ||
368 | test_expect_success 'merge-recursive d/f conflict result' ' | |
369 | ||
370 | git ls-files -s >actual && | |
371 | ( | |
b6c32f63 ES |
372 | echo "100644 $o0 1 a" && |
373 | echo "100644 $o1 2 a" && | |
374 | echo "100644 $o4 0 a/c" && | |
375 | echo "100644 $o0 0 b" && | |
376 | echo "100644 $o0 0 c" && | |
885b9810 JH |
377 | echo "100644 $o1 0 d/e" |
378 | ) >expected && | |
3af82863 | 379 | test_cmp expected actual |
885b9810 JH |
380 | |
381 | ' | |
382 | ||
383 | test_expect_success 'merge-recursive d/f conflict the other way' ' | |
384 | ||
744747ef | 385 | rm -fr [abcd] && |
885b9810 JH |
386 | git reset --hard && |
387 | git checkout -f "$c4" && | |
388 | ||
67b6afe1 | 389 | test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1" |
885b9810 JH |
390 | ' |
391 | ||
392 | test_expect_success 'merge-recursive d/f conflict result the other way' ' | |
393 | ||
394 | git ls-files -s >actual && | |
395 | ( | |
b6c32f63 ES |
396 | echo "100644 $o0 1 a" && |
397 | echo "100644 $o1 3 a" && | |
398 | echo "100644 $o4 0 a/c" && | |
399 | echo "100644 $o0 0 b" && | |
400 | echo "100644 $o0 0 c" && | |
885b9810 JH |
401 | echo "100644 $o1 0 d/e" |
402 | ) >expected && | |
3af82863 | 403 | test_cmp expected actual |
885b9810 JH |
404 | |
405 | ' | |
406 | ||
407 | test_expect_success 'merge-recursive d/f conflict' ' | |
408 | ||
744747ef | 409 | rm -fr [abcd] && |
885b9810 JH |
410 | git reset --hard && |
411 | git checkout -f "$c1" && | |
412 | ||
67b6afe1 | 413 | test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6" |
885b9810 JH |
414 | ' |
415 | ||
416 | test_expect_success 'merge-recursive d/f conflict result' ' | |
417 | ||
418 | git ls-files -s >actual && | |
419 | ( | |
b6c32f63 ES |
420 | echo "100644 $o1 0 a" && |
421 | echo "100644 $o0 0 b" && | |
422 | echo "100644 $o0 0 c" && | |
423 | echo "100644 $o6 3 d" && | |
424 | echo "100644 $o0 1 d/e" && | |
885b9810 JH |
425 | echo "100644 $o1 2 d/e" |
426 | ) >expected && | |
3af82863 | 427 | test_cmp expected actual |
885b9810 JH |
428 | |
429 | ' | |
430 | ||
431 | test_expect_success 'merge-recursive d/f conflict' ' | |
432 | ||
744747ef | 433 | rm -fr [abcd] && |
885b9810 JH |
434 | git reset --hard && |
435 | git checkout -f "$c6" && | |
436 | ||
67b6afe1 | 437 | test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1" |
885b9810 JH |
438 | ' |
439 | ||
440 | test_expect_success 'merge-recursive d/f conflict result' ' | |
441 | ||
442 | git ls-files -s >actual && | |
443 | ( | |
b6c32f63 ES |
444 | echo "100644 $o1 0 a" && |
445 | echo "100644 $o0 0 b" && | |
446 | echo "100644 $o0 0 c" && | |
447 | echo "100644 $o6 2 d" && | |
448 | echo "100644 $o0 1 d/e" && | |
885b9810 JH |
449 | echo "100644 $o1 3 d/e" |
450 | ) >expected && | |
3af82863 | 451 | test_cmp expected actual |
885b9810 JH |
452 | |
453 | ' | |
454 | ||
455 | test_expect_success 'reset and 3-way merge' ' | |
456 | ||
457 | git reset --hard "$c2" && | |
458 | git read-tree -m "$c0" "$c2" "$c1" | |
459 | ||
460 | ' | |
461 | ||
462 | test_expect_success 'reset and bind merge' ' | |
463 | ||
464 | git reset --hard master && | |
465 | git read-tree --prefix=M/ master && | |
466 | git ls-files -s >actual && | |
467 | ( | |
b6c32f63 ES |
468 | echo "100644 $o1 0 M/a" && |
469 | echo "100644 $o0 0 M/b" && | |
470 | echo "100644 $o0 0 M/c" && | |
471 | echo "100644 $o1 0 M/d/e" && | |
472 | echo "100644 $o1 0 a" && | |
473 | echo "100644 $o0 0 b" && | |
474 | echo "100644 $o0 0 c" && | |
885b9810 JH |
475 | echo "100644 $o1 0 d/e" |
476 | ) >expected && | |
3af82863 | 477 | test_cmp expected actual && |
885b9810 JH |
478 | |
479 | git read-tree --prefix=a1/ master && | |
480 | git ls-files -s >actual && | |
481 | ( | |
b6c32f63 ES |
482 | echo "100644 $o1 0 M/a" && |
483 | echo "100644 $o0 0 M/b" && | |
484 | echo "100644 $o0 0 M/c" && | |
485 | echo "100644 $o1 0 M/d/e" && | |
486 | echo "100644 $o1 0 a" && | |
487 | echo "100644 $o1 0 a1/a" && | |
488 | echo "100644 $o0 0 a1/b" && | |
489 | echo "100644 $o0 0 a1/c" && | |
490 | echo "100644 $o1 0 a1/d/e" && | |
491 | echo "100644 $o0 0 b" && | |
492 | echo "100644 $o0 0 c" && | |
885b9810 JH |
493 | echo "100644 $o1 0 d/e" |
494 | ) >expected && | |
a48fcd83 | 495 | test_cmp expected actual && |
885b9810 JH |
496 | |
497 | git read-tree --prefix=z/ master && | |
498 | git ls-files -s >actual && | |
499 | ( | |
b6c32f63 ES |
500 | echo "100644 $o1 0 M/a" && |
501 | echo "100644 $o0 0 M/b" && | |
502 | echo "100644 $o0 0 M/c" && | |
503 | echo "100644 $o1 0 M/d/e" && | |
504 | echo "100644 $o1 0 a" && | |
505 | echo "100644 $o1 0 a1/a" && | |
506 | echo "100644 $o0 0 a1/b" && | |
507 | echo "100644 $o0 0 a1/c" && | |
508 | echo "100644 $o1 0 a1/d/e" && | |
509 | echo "100644 $o0 0 b" && | |
510 | echo "100644 $o0 0 c" && | |
511 | echo "100644 $o1 0 d/e" && | |
512 | echo "100644 $o1 0 z/a" && | |
513 | echo "100644 $o0 0 z/b" && | |
514 | echo "100644 $o0 0 z/c" && | |
885b9810 JH |
515 | echo "100644 $o1 0 z/d/e" |
516 | ) >expected && | |
3af82863 | 517 | test_cmp expected actual |
885b9810 JH |
518 | |
519 | ' | |
520 | ||
6e2068ae | 521 | test_expect_success 'merge-recursive w/ empty work tree - ours has rename' ' |
29d9af58 BK |
522 | ( |
523 | GIT_WORK_TREE="$PWD/ours-has-rename-work" && | |
524 | export GIT_WORK_TREE && | |
525 | GIT_INDEX_FILE="$PWD/ours-has-rename-index" && | |
526 | export GIT_INDEX_FILE && | |
527 | mkdir "$GIT_WORK_TREE" && | |
40dc533f SG |
528 | git read-tree -i -m $c7 2>actual-err && |
529 | test_must_be_empty actual-err && | |
530 | git update-index --ignore-missing --refresh 2>actual-err && | |
531 | test_must_be_empty actual-err && | |
532 | git merge-recursive $c0 -- $c7 $c3 2>actual-err && | |
533 | test_must_be_empty actual-err && | |
534 | git ls-files -s >actual-files 2>actual-err && | |
535 | test_must_be_empty actual-err | |
536 | ) && | |
29d9af58 BK |
537 | cat >expected-files <<-EOF && |
538 | 100644 $o3 0 b/c | |
539 | 100644 $o0 0 c | |
540 | 100644 $o0 0 d/e | |
541 | 100644 $o0 0 e | |
542 | EOF | |
40dc533f | 543 | test_cmp expected-files actual-files |
29d9af58 BK |
544 | ' |
545 | ||
546 | test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' ' | |
547 | ( | |
548 | GIT_WORK_TREE="$PWD/theirs-has-rename-work" && | |
549 | export GIT_WORK_TREE && | |
550 | GIT_INDEX_FILE="$PWD/theirs-has-rename-index" && | |
551 | export GIT_INDEX_FILE && | |
552 | mkdir "$GIT_WORK_TREE" && | |
40dc533f SG |
553 | git read-tree -i -m $c3 2>actual-err && |
554 | test_must_be_empty actual-err && | |
555 | git update-index --ignore-missing --refresh 2>actual-err && | |
556 | test_must_be_empty actual-err && | |
557 | git merge-recursive $c0 -- $c3 $c7 2>actual-err && | |
558 | test_must_be_empty actual-err && | |
559 | git ls-files -s >actual-files 2>actual-err && | |
560 | test_must_be_empty actual-err | |
561 | ) && | |
29d9af58 BK |
562 | cat >expected-files <<-EOF && |
563 | 100644 $o3 0 b/c | |
564 | 100644 $o0 0 c | |
565 | 100644 $o0 0 d/e | |
566 | 100644 $o0 0 e | |
567 | EOF | |
40dc533f | 568 | test_cmp expected-files actual-files |
29d9af58 BK |
569 | ' |
570 | ||
41f13af5 AR |
571 | test_expect_success 'merge removes empty directories' ' |
572 | ||
573 | git reset --hard master && | |
574 | git checkout -b rm && | |
575 | git rm d/e && | |
576 | git commit -mremoved-d/e && | |
577 | git checkout master && | |
578 | git merge -s recursive rm && | |
579 | test_must_fail test -d d | |
580 | ' | |
581 | ||
5423d2e7 | 582 | test_expect_success 'merge-recursive simple w/submodule' ' |
7d82b06d JS |
583 | |
584 | git checkout submod && | |
585 | git merge remove | |
586 | ' | |
587 | ||
5423d2e7 | 588 | test_expect_success 'merge-recursive simple w/submodule result' ' |
7d82b06d JS |
589 | |
590 | git ls-files -s >actual && | |
591 | ( | |
b6c32f63 ES |
592 | echo "100644 $o5 0 a" && |
593 | echo "100644 $o0 0 c" && | |
7d82b06d JS |
594 | echo "160000 $c1 0 d" |
595 | ) >expected && | |
596 | test_cmp expected actual | |
597 | ' | |
598 | ||
d5af5105 SK |
599 | test_expect_success 'merge-recursive copy vs. rename' ' |
600 | git checkout -f copy && | |
601 | git merge rename && | |
602 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && | |
603 | ( | |
b6c32f63 ES |
604 | echo "100644 blob $o0 b" && |
605 | echo "100644 blob $o0 c" && | |
606 | echo "100644 blob $o0 d/e" && | |
607 | echo "100644 blob $o0 e" && | |
608 | echo "100644 $o0 0 b" && | |
609 | echo "100644 $o0 0 c" && | |
610 | echo "100644 $o0 0 d/e" && | |
d5af5105 SK |
611 | echo "100644 $o0 0 e" |
612 | ) >expected && | |
613 | test_cmp expected actual | |
614 | ' | |
615 | ||
bba56042 JS |
616 | test_expect_failure 'merge-recursive rename vs. rename/symlink' ' |
617 | ||
618 | git checkout -f rename && | |
619 | git merge rename-ln && | |
b6c32f63 | 620 | ( git ls-tree -r HEAD && git ls-files -s ) >actual && |
bba56042 | 621 | ( |
b6c32f63 ES |
622 | echo "120000 blob $oln a" && |
623 | echo "100644 blob $o0 b" && | |
624 | echo "100644 blob $o0 c" && | |
625 | echo "100644 blob $o0 d/e" && | |
626 | echo "100644 blob $o0 e" && | |
627 | echo "120000 $oln 0 a" && | |
628 | echo "100644 $o0 0 b" && | |
629 | echo "100644 $o0 0 c" && | |
630 | echo "100644 $o0 0 d/e" && | |
bba56042 JS |
631 | echo "100644 $o0 0 e" |
632 | ) >expected && | |
633 | test_cmp expected actual | |
634 | ' | |
8a1c0d32 | 635 | |
6f50833e JK |
636 | test_expect_success 'merging with triple rename across D/F conflict' ' |
637 | git reset --hard HEAD && | |
638 | git checkout -b main && | |
639 | git rm -rf . && | |
640 | ||
641 | echo "just a file" >sub1 && | |
642 | mkdir -p sub2 && | |
643 | echo content1 >sub2/file1 && | |
644 | echo content2 >sub2/file2 && | |
645 | echo content3 >sub2/file3 && | |
646 | mkdir simple && | |
647 | echo base >simple/bar && | |
648 | git add -A && | |
649 | test_tick && | |
650 | git commit -m base && | |
651 | ||
652 | git checkout -b other && | |
653 | echo more >>simple/bar && | |
654 | test_tick && | |
655 | git commit -a -m changesimplefile && | |
656 | ||
657 | git checkout main && | |
658 | git rm sub1 && | |
659 | git mv sub2 sub1 && | |
660 | test_tick && | |
661 | git commit -m changefiletodir && | |
662 | ||
663 | test_tick && | |
664 | git merge other | |
665 | ' | |
8a1c0d32 | 666 | |
a2571653 RS |
667 | test_expect_success 'merge-recursive remembers the names of all base trees' ' |
668 | git reset --hard HEAD && | |
669 | ||
670 | # more trees than static slots used by oid_to_hex() | |
671 | for commit in $c0 $c2 $c4 $c5 $c6 $c7 | |
672 | do | |
673 | git rev-parse "$commit^{tree}" | |
674 | done >trees && | |
675 | ||
676 | # ignore the return code -- it only fails because the input is weird | |
677 | test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out && | |
678 | ||
679 | # merge-recursive prints in reverse order, but we do not care | |
680 | sort <trees >expect && | |
681 | sed -n "s/^virtual //p" out | sort >actual && | |
682 | test_cmp expect actual | |
683 | ' | |
684 | ||
f309e8e7 JH |
685 | test_expect_success 'merge-recursive internal merge resolves to the sameness' ' |
686 | git reset --hard HEAD && | |
687 | ||
688 | # We are going to create a history leading to two criss-cross | |
689 | # branches A and B. The common ancestor at the bottom, O0, | |
690 | # has two child commits O1 and O2, both of which will be merge | |
691 | # base between A and B, like so: | |
692 | # | |
693 | # O1---A | |
694 | # / \ / | |
695 | # O0 . | |
696 | # \ / \ | |
697 | # O2---B | |
698 | # | |
699 | # The recently added "check to see if the index is different from | |
700 | # the tree into which something else is getting merged" check must | |
701 | # NOT kick in when an inner merge between O1 and O2 is made. Both | |
702 | # O1 and O2 happen to have the same tree as O0 in this test to | |
703 | # trigger the bug---whether the inner merge is made by merging O2 | |
704 | # into O1 or O1 into O2, their common ancestor O0 and the branch | |
705 | # being merged have the same tree. We should not trigger the "is | |
706 | # the index dirty?" check in this case. | |
707 | ||
708 | echo "zero" >file && | |
709 | git add file && | |
710 | test_tick && | |
711 | git commit -m "O0" && | |
712 | O0=$(git rev-parse HEAD) && | |
713 | ||
714 | test_tick && | |
715 | git commit --allow-empty -m "O1" && | |
716 | O1=$(git rev-parse HEAD) && | |
717 | ||
718 | git reset --hard $O0 && | |
719 | test_tick && | |
720 | git commit --allow-empty -m "O2" && | |
721 | O2=$(git rev-parse HEAD) && | |
722 | ||
723 | test_tick && | |
724 | git merge -s ours $O1 && | |
725 | B=$(git rev-parse HEAD) && | |
726 | ||
727 | git reset --hard $O1 && | |
728 | test_tick && | |
729 | git merge -s ours $O2 && | |
730 | A=$(git rev-parse HEAD) && | |
731 | ||
732 | git merge $B | |
733 | ' | |
734 | ||
885b9810 | 735 | test_done |