am --abort: keep unrelated commits since the last failure and warn
[git/mingw.git] / t / t3030-merge-recursive.sh
blobe66e550b2449e76435a0bf16c6a9889c0794f858
1 #!/bin/sh
3 test_description='merge-recursive backend test'
5 . ./test-lib.sh
7 test_expect_success 'setup 1' '
9 echo hello >a &&
10 o0=$(git hash-object a) &&
11 cp a b &&
12 cp a c &&
13 mkdir d &&
14 cp a d/e &&
16 test_tick &&
17 git add a b c d/e &&
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 &&
25 git branch submod &&
26 git branch copy &&
27 git branch rename &&
29 echo hello >>a &&
30 cp a d/e &&
31 o1=$(git hash-object a) &&
33 git add a d/e &&
35 test_tick &&
36 git commit -m "master modifies a and d/e" &&
37 c1=$(git rev-parse --verify HEAD) &&
38 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
40 echo "100644 blob $o1 a"
41 echo "100644 blob $o0 b"
42 echo "100644 blob $o0 c"
43 echo "100644 blob $o1 d/e"
44 echo "100644 $o1 0 a"
45 echo "100644 $o0 0 b"
46 echo "100644 $o0 0 c"
47 echo "100644 $o1 0 d/e"
48 ) >expected &&
49 test_cmp expected actual
52 test_expect_success 'setup 2' '
54 rm -rf [abcd] &&
55 git checkout side &&
56 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
58 echo "100644 blob $o0 a"
59 echo "100644 blob $o0 b"
60 echo "100644 blob $o0 c"
61 echo "100644 blob $o0 d/e"
62 echo "100644 $o0 0 a"
63 echo "100644 $o0 0 b"
64 echo "100644 $o0 0 c"
65 echo "100644 $o0 0 d/e"
66 ) >expected &&
67 test_cmp expected actual &&
69 echo goodbye >>a &&
70 o2=$(git hash-object a) &&
72 git add a &&
74 test_tick &&
75 git commit -m "side modifies a" &&
76 c2=$(git rev-parse --verify HEAD) &&
77 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
79 echo "100644 blob $o2 a"
80 echo "100644 blob $o0 b"
81 echo "100644 blob $o0 c"
82 echo "100644 blob $o0 d/e"
83 echo "100644 $o2 0 a"
84 echo "100644 $o0 0 b"
85 echo "100644 $o0 0 c"
86 echo "100644 $o0 0 d/e"
87 ) >expected &&
88 test_cmp expected actual
91 test_expect_success 'setup 3' '
93 rm -rf [abcd] &&
94 git checkout df-1 &&
95 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
97 echo "100644 blob $o0 a"
98 echo "100644 blob $o0 b"
99 echo "100644 blob $o0 c"
100 echo "100644 blob $o0 d/e"
101 echo "100644 $o0 0 a"
102 echo "100644 $o0 0 b"
103 echo "100644 $o0 0 c"
104 echo "100644 $o0 0 d/e"
105 ) >expected &&
106 test_cmp expected actual &&
108 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
109 o3=$(git hash-object b/c) &&
111 test_tick &&
112 git commit -m "df-1 makes b/c" &&
113 c3=$(git rev-parse --verify HEAD) &&
114 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
116 echo "100644 blob $o0 a"
117 echo "100644 blob $o3 b/c"
118 echo "100644 blob $o0 c"
119 echo "100644 blob $o0 d/e"
120 echo "100644 $o0 0 a"
121 echo "100644 $o3 0 b/c"
122 echo "100644 $o0 0 c"
123 echo "100644 $o0 0 d/e"
124 ) >expected &&
125 test_cmp expected actual
128 test_expect_success 'setup 4' '
130 rm -rf [abcd] &&
131 git checkout df-2 &&
132 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
134 echo "100644 blob $o0 a"
135 echo "100644 blob $o0 b"
136 echo "100644 blob $o0 c"
137 echo "100644 blob $o0 d/e"
138 echo "100644 $o0 0 a"
139 echo "100644 $o0 0 b"
140 echo "100644 $o0 0 c"
141 echo "100644 $o0 0 d/e"
142 ) >expected &&
143 test_cmp expected actual &&
145 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
146 o4=$(git hash-object a/c) &&
148 test_tick &&
149 git commit -m "df-2 makes a/c" &&
150 c4=$(git rev-parse --verify HEAD) &&
151 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
153 echo "100644 blob $o4 a/c"
154 echo "100644 blob $o0 b"
155 echo "100644 blob $o0 c"
156 echo "100644 blob $o0 d/e"
157 echo "100644 $o4 0 a/c"
158 echo "100644 $o0 0 b"
159 echo "100644 $o0 0 c"
160 echo "100644 $o0 0 d/e"
161 ) >expected &&
162 test_cmp expected actual
165 test_expect_success 'setup 5' '
167 rm -rf [abcd] &&
168 git checkout remove &&
169 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
171 echo "100644 blob $o0 a"
172 echo "100644 blob $o0 b"
173 echo "100644 blob $o0 c"
174 echo "100644 blob $o0 d/e"
175 echo "100644 $o0 0 a"
176 echo "100644 $o0 0 b"
177 echo "100644 $o0 0 c"
178 echo "100644 $o0 0 d/e"
179 ) >expected &&
180 test_cmp expected actual &&
182 rm -f b &&
183 echo remove-conflict >a &&
185 git add a &&
186 git rm b &&
187 o5=$(git hash-object a) &&
189 test_tick &&
190 git commit -m "remove removes b and modifies a" &&
191 c5=$(git rev-parse --verify HEAD) &&
192 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
194 echo "100644 blob $o5 a"
195 echo "100644 blob $o0 c"
196 echo "100644 blob $o0 d/e"
197 echo "100644 $o5 0 a"
198 echo "100644 $o0 0 c"
199 echo "100644 $o0 0 d/e"
200 ) >expected &&
201 test_cmp expected actual
205 test_expect_success 'setup 6' '
207 rm -rf [abcd] &&
208 git checkout df-3 &&
209 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
211 echo "100644 blob $o0 a"
212 echo "100644 blob $o0 b"
213 echo "100644 blob $o0 c"
214 echo "100644 blob $o0 d/e"
215 echo "100644 $o0 0 a"
216 echo "100644 $o0 0 b"
217 echo "100644 $o0 0 c"
218 echo "100644 $o0 0 d/e"
219 ) >expected &&
220 test_cmp expected actual &&
222 rm -fr d && echo df-3 >d && git add d &&
223 o6=$(git hash-object d) &&
225 test_tick &&
226 git commit -m "df-3 makes d" &&
227 c6=$(git rev-parse --verify HEAD) &&
228 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
230 echo "100644 blob $o0 a"
231 echo "100644 blob $o0 b"
232 echo "100644 blob $o0 c"
233 echo "100644 blob $o6 d"
234 echo "100644 $o0 0 a"
235 echo "100644 $o0 0 b"
236 echo "100644 $o0 0 c"
237 echo "100644 $o6 0 d"
238 ) >expected &&
239 test_cmp expected actual
242 test_expect_success 'setup 7' '
244 git checkout submod &&
245 git rm d/e &&
246 test_tick &&
247 git commit -m "remove d/e" &&
248 git update-index --add --cacheinfo 160000 $c1 d &&
249 test_tick &&
250 git commit -m "make d/ a submodule"
253 test_expect_success 'setup 8' '
254 git checkout rename &&
255 git mv a e &&
256 git add e &&
257 test_tick &&
258 git commit -m "rename a->e"
261 test_expect_success 'setup 9' '
262 git checkout copy &&
263 cp a e &&
264 git add e &&
265 test_tick &&
266 git commit -m "copy a->e"
269 test_expect_success 'merge-recursive simple' '
271 rm -fr [abcd] &&
272 git checkout -f "$c2" &&
274 git merge-recursive "$c0" -- "$c2" "$c1"
275 status=$?
276 case "$status" in
278 : happy
281 echo >&2 "why status $status!!!"
282 false
284 esac
287 test_expect_success 'merge-recursive result' '
289 git ls-files -s >actual &&
291 echo "100644 $o0 1 a"
292 echo "100644 $o2 2 a"
293 echo "100644 $o1 3 a"
294 echo "100644 $o0 0 b"
295 echo "100644 $o0 0 c"
296 echo "100644 $o1 0 d/e"
297 ) >expected &&
298 test_cmp expected actual
302 test_expect_success 'fail if the index has unresolved entries' '
304 rm -fr [abcd] &&
305 git checkout -f "$c1" &&
307 test_must_fail git merge "$c5" &&
308 test_must_fail git merge "$c5" 2> out &&
309 grep "not possible because you have unmerged files" out &&
310 git add -u &&
311 test_must_fail git merge "$c5" 2> out &&
312 grep "You have not concluded your merge" out &&
313 rm -f .git/MERGE_HEAD &&
314 test_must_fail git merge "$c5" 2> out &&
315 grep "Your local changes to the following files would be overwritten by merge:" out
318 test_expect_success 'merge-recursive remove conflict' '
320 rm -fr [abcd] &&
321 git checkout -f "$c1" &&
323 git merge-recursive "$c0" -- "$c1" "$c5"
324 status=$?
325 case "$status" in
327 : happy
330 echo >&2 "why status $status!!!"
331 false
333 esac
336 test_expect_success 'merge-recursive remove conflict' '
338 git ls-files -s >actual &&
340 echo "100644 $o0 1 a"
341 echo "100644 $o1 2 a"
342 echo "100644 $o5 3 a"
343 echo "100644 $o0 0 c"
344 echo "100644 $o1 0 d/e"
345 ) >expected &&
346 test_cmp expected actual
350 test_expect_success 'merge-recursive d/f simple' '
351 rm -fr [abcd] &&
352 git reset --hard &&
353 git checkout -f "$c1" &&
355 git merge-recursive "$c0" -- "$c1" "$c3"
358 test_expect_success 'merge-recursive result' '
360 git ls-files -s >actual &&
362 echo "100644 $o1 0 a"
363 echo "100644 $o3 0 b/c"
364 echo "100644 $o0 0 c"
365 echo "100644 $o1 0 d/e"
366 ) >expected &&
367 test_cmp expected actual
371 test_expect_success 'merge-recursive d/f conflict' '
373 rm -fr [abcd] &&
374 git reset --hard &&
375 git checkout -f "$c1" &&
377 git merge-recursive "$c0" -- "$c1" "$c4"
378 status=$?
379 case "$status" in
381 : happy
384 echo >&2 "why status $status!!!"
385 false
387 esac
390 test_expect_success 'merge-recursive d/f conflict result' '
392 git ls-files -s >actual &&
394 echo "100644 $o0 1 a"
395 echo "100644 $o1 2 a"
396 echo "100644 $o4 0 a/c"
397 echo "100644 $o0 0 b"
398 echo "100644 $o0 0 c"
399 echo "100644 $o1 0 d/e"
400 ) >expected &&
401 test_cmp expected actual
405 test_expect_success 'merge-recursive d/f conflict the other way' '
407 rm -fr [abcd] &&
408 git reset --hard &&
409 git checkout -f "$c4" &&
411 git merge-recursive "$c0" -- "$c4" "$c1"
412 status=$?
413 case "$status" in
415 : happy
418 echo >&2 "why status $status!!!"
419 false
421 esac
424 test_expect_success 'merge-recursive d/f conflict result the other way' '
426 git ls-files -s >actual &&
428 echo "100644 $o0 1 a"
429 echo "100644 $o1 3 a"
430 echo "100644 $o4 0 a/c"
431 echo "100644 $o0 0 b"
432 echo "100644 $o0 0 c"
433 echo "100644 $o1 0 d/e"
434 ) >expected &&
435 test_cmp expected actual
439 test_expect_success 'merge-recursive d/f conflict' '
441 rm -fr [abcd] &&
442 git reset --hard &&
443 git checkout -f "$c1" &&
445 git merge-recursive "$c0" -- "$c1" "$c6"
446 status=$?
447 case "$status" in
449 : happy
452 echo >&2 "why status $status!!!"
453 false
455 esac
458 test_expect_success 'merge-recursive d/f conflict result' '
460 git ls-files -s >actual &&
462 echo "100644 $o1 0 a"
463 echo "100644 $o0 0 b"
464 echo "100644 $o0 0 c"
465 echo "100644 $o6 3 d"
466 echo "100644 $o0 1 d/e"
467 echo "100644 $o1 2 d/e"
468 ) >expected &&
469 test_cmp expected actual
473 test_expect_success 'merge-recursive d/f conflict' '
475 rm -fr [abcd] &&
476 git reset --hard &&
477 git checkout -f "$c6" &&
479 git merge-recursive "$c0" -- "$c6" "$c1"
480 status=$?
481 case "$status" in
483 : happy
486 echo >&2 "why status $status!!!"
487 false
489 esac
492 test_expect_success 'merge-recursive d/f conflict result' '
494 git ls-files -s >actual &&
496 echo "100644 $o1 0 a"
497 echo "100644 $o0 0 b"
498 echo "100644 $o0 0 c"
499 echo "100644 $o6 2 d"
500 echo "100644 $o0 1 d/e"
501 echo "100644 $o1 3 d/e"
502 ) >expected &&
503 test_cmp expected actual
507 test_expect_success 'reset and 3-way merge' '
509 git reset --hard "$c2" &&
510 git read-tree -m "$c0" "$c2" "$c1"
514 test_expect_success 'reset and bind merge' '
516 git reset --hard master &&
517 git read-tree --prefix=M/ master &&
518 git ls-files -s >actual &&
520 echo "100644 $o1 0 M/a"
521 echo "100644 $o0 0 M/b"
522 echo "100644 $o0 0 M/c"
523 echo "100644 $o1 0 M/d/e"
524 echo "100644 $o1 0 a"
525 echo "100644 $o0 0 b"
526 echo "100644 $o0 0 c"
527 echo "100644 $o1 0 d/e"
528 ) >expected &&
529 test_cmp expected actual &&
531 git read-tree --prefix=a1/ master &&
532 git ls-files -s >actual &&
534 echo "100644 $o1 0 M/a"
535 echo "100644 $o0 0 M/b"
536 echo "100644 $o0 0 M/c"
537 echo "100644 $o1 0 M/d/e"
538 echo "100644 $o1 0 a"
539 echo "100644 $o1 0 a1/a"
540 echo "100644 $o0 0 a1/b"
541 echo "100644 $o0 0 a1/c"
542 echo "100644 $o1 0 a1/d/e"
543 echo "100644 $o0 0 b"
544 echo "100644 $o0 0 c"
545 echo "100644 $o1 0 d/e"
546 ) >expected &&
547 test_cmp expected actual
549 git read-tree --prefix=z/ master &&
550 git ls-files -s >actual &&
552 echo "100644 $o1 0 M/a"
553 echo "100644 $o0 0 M/b"
554 echo "100644 $o0 0 M/c"
555 echo "100644 $o1 0 M/d/e"
556 echo "100644 $o1 0 a"
557 echo "100644 $o1 0 a1/a"
558 echo "100644 $o0 0 a1/b"
559 echo "100644 $o0 0 a1/c"
560 echo "100644 $o1 0 a1/d/e"
561 echo "100644 $o0 0 b"
562 echo "100644 $o0 0 c"
563 echo "100644 $o1 0 d/e"
564 echo "100644 $o1 0 z/a"
565 echo "100644 $o0 0 z/b"
566 echo "100644 $o0 0 z/c"
567 echo "100644 $o1 0 z/d/e"
568 ) >expected &&
569 test_cmp expected actual
573 test_expect_success 'merge removes empty directories' '
575 git reset --hard master &&
576 git checkout -b rm &&
577 git rm d/e &&
578 git commit -mremoved-d/e &&
579 git checkout master &&
580 git merge -s recursive rm &&
581 test_must_fail test -d d
584 test_expect_failure 'merge-recursive simple w/submodule' '
586 git checkout submod &&
587 git merge remove
590 test_expect_failure 'merge-recursive simple w/submodule result' '
592 git ls-files -s >actual &&
594 echo "100644 $o5 0 a"
595 echo "100644 $o0 0 c"
596 echo "160000 $c1 0 d"
597 ) >expected &&
598 test_cmp expected actual
601 test_expect_success 'merge-recursive copy vs. rename' '
602 git checkout -f copy &&
603 git merge rename &&
604 ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
606 echo "100644 blob $o0 b"
607 echo "100644 blob $o0 c"
608 echo "100644 blob $o0 d/e"
609 echo "100644 blob $o0 e"
610 echo "100644 $o0 0 b"
611 echo "100644 $o0 0 c"
612 echo "100644 $o0 0 d/e"
613 echo "100644 $o0 0 e"
614 ) >expected &&
615 test_cmp expected actual
618 test_done