unpack_trees: group error messages by type
[git/git.git] / t / t3030-merge-recursive.sh
CommitLineData
885b9810
JH
1#!/bin/sh
2
3test_description='merge-recursive backend test'
4
5. ./test-lib.sh
6
7test_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 &&
885b9810
JH
26
27 echo hello >>a &&
28 cp a d/e &&
29 o1=$(git hash-object a) &&
30
31 git add a d/e &&
32
33 test_tick &&
34 git commit -m "master modifies a and d/e" &&
35 c1=$(git rev-parse --verify HEAD) &&
36 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
37 (
885b9810
JH
38 echo "100644 blob $o1 a"
39 echo "100644 blob $o0 b"
744747ef 40 echo "100644 blob $o0 c"
885b9810 41 echo "100644 blob $o1 d/e"
885b9810
JH
42 echo "100644 $o1 0 a"
43 echo "100644 $o0 0 b"
744747ef 44 echo "100644 $o0 0 c"
885b9810
JH
45 echo "100644 $o1 0 d/e"
46 ) >expected &&
3af82863 47 test_cmp expected actual
885b9810
JH
48'
49
50test_expect_success 'setup 2' '
51
744747ef 52 rm -rf [abcd] &&
885b9810
JH
53 git checkout side &&
54 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
55 (
885b9810
JH
56 echo "100644 blob $o0 a"
57 echo "100644 blob $o0 b"
744747ef 58 echo "100644 blob $o0 c"
885b9810 59 echo "100644 blob $o0 d/e"
885b9810
JH
60 echo "100644 $o0 0 a"
61 echo "100644 $o0 0 b"
744747ef 62 echo "100644 $o0 0 c"
885b9810
JH
63 echo "100644 $o0 0 d/e"
64 ) >expected &&
3af82863 65 test_cmp expected actual &&
885b9810
JH
66
67 echo goodbye >>a &&
68 o2=$(git hash-object a) &&
69
70 git add a &&
71
72 test_tick &&
73 git commit -m "side modifies a" &&
74 c2=$(git rev-parse --verify HEAD) &&
75 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
76 (
885b9810
JH
77 echo "100644 blob $o2 a"
78 echo "100644 blob $o0 b"
744747ef 79 echo "100644 blob $o0 c"
885b9810 80 echo "100644 blob $o0 d/e"
885b9810
JH
81 echo "100644 $o2 0 a"
82 echo "100644 $o0 0 b"
744747ef 83 echo "100644 $o0 0 c"
885b9810
JH
84 echo "100644 $o0 0 d/e"
85 ) >expected &&
3af82863 86 test_cmp expected actual
885b9810
JH
87'
88
89test_expect_success 'setup 3' '
90
744747ef 91 rm -rf [abcd] &&
885b9810
JH
92 git checkout df-1 &&
93 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
94 (
885b9810
JH
95 echo "100644 blob $o0 a"
96 echo "100644 blob $o0 b"
744747ef 97 echo "100644 blob $o0 c"
885b9810 98 echo "100644 blob $o0 d/e"
885b9810
JH
99 echo "100644 $o0 0 a"
100 echo "100644 $o0 0 b"
744747ef 101 echo "100644 $o0 0 c"
885b9810
JH
102 echo "100644 $o0 0 d/e"
103 ) >expected &&
3af82863 104 test_cmp expected actual &&
885b9810
JH
105
106 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
107 o3=$(git hash-object b/c) &&
108
109 test_tick &&
110 git commit -m "df-1 makes b/c" &&
111 c3=$(git rev-parse --verify HEAD) &&
112 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
113 (
885b9810
JH
114 echo "100644 blob $o0 a"
115 echo "100644 blob $o3 b/c"
744747ef 116 echo "100644 blob $o0 c"
885b9810 117 echo "100644 blob $o0 d/e"
885b9810
JH
118 echo "100644 $o0 0 a"
119 echo "100644 $o3 0 b/c"
744747ef 120 echo "100644 $o0 0 c"
885b9810
JH
121 echo "100644 $o0 0 d/e"
122 ) >expected &&
3af82863 123 test_cmp expected actual
885b9810
JH
124'
125
126test_expect_success 'setup 4' '
127
744747ef 128 rm -rf [abcd] &&
885b9810
JH
129 git checkout df-2 &&
130 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
131 (
885b9810
JH
132 echo "100644 blob $o0 a"
133 echo "100644 blob $o0 b"
744747ef 134 echo "100644 blob $o0 c"
885b9810 135 echo "100644 blob $o0 d/e"
885b9810
JH
136 echo "100644 $o0 0 a"
137 echo "100644 $o0 0 b"
744747ef 138 echo "100644 $o0 0 c"
885b9810
JH
139 echo "100644 $o0 0 d/e"
140 ) >expected &&
3af82863 141 test_cmp expected actual &&
885b9810
JH
142
143 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
144 o4=$(git hash-object a/c) &&
145
146 test_tick &&
147 git commit -m "df-2 makes a/c" &&
148 c4=$(git rev-parse --verify HEAD) &&
149 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
150 (
885b9810
JH
151 echo "100644 blob $o4 a/c"
152 echo "100644 blob $o0 b"
744747ef 153 echo "100644 blob $o0 c"
885b9810 154 echo "100644 blob $o0 d/e"
885b9810
JH
155 echo "100644 $o4 0 a/c"
156 echo "100644 $o0 0 b"
744747ef 157 echo "100644 $o0 0 c"
885b9810
JH
158 echo "100644 $o0 0 d/e"
159 ) >expected &&
3af82863 160 test_cmp expected actual
885b9810
JH
161'
162
163test_expect_success 'setup 5' '
164
744747ef 165 rm -rf [abcd] &&
885b9810
JH
166 git checkout remove &&
167 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
168 (
885b9810
JH
169 echo "100644 blob $o0 a"
170 echo "100644 blob $o0 b"
744747ef 171 echo "100644 blob $o0 c"
885b9810 172 echo "100644 blob $o0 d/e"
885b9810
JH
173 echo "100644 $o0 0 a"
174 echo "100644 $o0 0 b"
744747ef 175 echo "100644 $o0 0 c"
885b9810
JH
176 echo "100644 $o0 0 d/e"
177 ) >expected &&
3af82863 178 test_cmp expected actual &&
885b9810
JH
179
180 rm -f b &&
181 echo remove-conflict >a &&
182
183 git add a &&
184 git rm b &&
185 o5=$(git hash-object a) &&
186
187 test_tick &&
188 git commit -m "remove removes b and modifies a" &&
189 c5=$(git rev-parse --verify HEAD) &&
190 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
191 (
885b9810 192 echo "100644 blob $o5 a"
744747ef 193 echo "100644 blob $o0 c"
885b9810 194 echo "100644 blob $o0 d/e"
885b9810 195 echo "100644 $o5 0 a"
744747ef 196 echo "100644 $o0 0 c"
885b9810
JH
197 echo "100644 $o0 0 d/e"
198 ) >expected &&
3af82863 199 test_cmp expected actual
885b9810
JH
200
201'
202
203test_expect_success 'setup 6' '
204
744747ef 205 rm -rf [abcd] &&
885b9810
JH
206 git checkout df-3 &&
207 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
208 (
885b9810
JH
209 echo "100644 blob $o0 a"
210 echo "100644 blob $o0 b"
744747ef 211 echo "100644 blob $o0 c"
885b9810 212 echo "100644 blob $o0 d/e"
885b9810
JH
213 echo "100644 $o0 0 a"
214 echo "100644 $o0 0 b"
744747ef 215 echo "100644 $o0 0 c"
885b9810
JH
216 echo "100644 $o0 0 d/e"
217 ) >expected &&
3af82863 218 test_cmp expected actual &&
885b9810
JH
219
220 rm -fr d && echo df-3 >d && git add d &&
221 o6=$(git hash-object d) &&
222
223 test_tick &&
224 git commit -m "df-3 makes d" &&
225 c6=$(git rev-parse --verify HEAD) &&
226 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
227 (
885b9810
JH
228 echo "100644 blob $o0 a"
229 echo "100644 blob $o0 b"
744747ef 230 echo "100644 blob $o0 c"
885b9810 231 echo "100644 blob $o6 d"
885b9810
JH
232 echo "100644 $o0 0 a"
233 echo "100644 $o0 0 b"
744747ef 234 echo "100644 $o0 0 c"
885b9810
JH
235 echo "100644 $o6 0 d"
236 ) >expected &&
3af82863 237 test_cmp expected actual
885b9810
JH
238'
239
7d82b06d
JS
240test_expect_success 'setup 7' '
241
242 git checkout submod &&
243 git rm d/e &&
244 test_tick &&
245 git commit -m "remove d/e" &&
246 git update-index --add --cacheinfo 160000 $c1 d &&
247 test_tick &&
248 git commit -m "make d/ a submodule"
249'
250
885b9810
JH
251test_expect_success 'merge-recursive simple' '
252
744747ef 253 rm -fr [abcd] &&
885b9810
JH
254 git checkout -f "$c2" &&
255
0cb0e143 256 git merge-recursive "$c0" -- "$c2" "$c1"
885b9810
JH
257 status=$?
258 case "$status" in
259 1)
260 : happy
261 ;;
262 *)
263 echo >&2 "why status $status!!!"
264 false
265 ;;
266 esac
267'
268
269test_expect_success 'merge-recursive result' '
270
271 git ls-files -s >actual &&
272 (
885b9810
JH
273 echo "100644 $o0 1 a"
274 echo "100644 $o2 2 a"
275 echo "100644 $o1 3 a"
276 echo "100644 $o0 0 b"
744747ef 277 echo "100644 $o0 0 c"
885b9810
JH
278 echo "100644 $o1 0 d/e"
279 ) >expected &&
3af82863 280 test_cmp expected actual
885b9810
JH
281
282'
283
446247db
JH
284test_expect_success 'fail if the index has unresolved entries' '
285
286 rm -fr [abcd] &&
287 git checkout -f "$c1" &&
288
289 test_must_fail git merge "$c5" &&
290 test_must_fail git merge "$c5" 2> out &&
d38a30df
MM
291 grep "not possible because you have unmerged files" out &&
292 git add -u &&
293 test_must_fail git merge "$c5" 2> out &&
c8c562a2
CB
294 grep "You have not concluded your merge" out &&
295 rm -f .git/MERGE_HEAD &&
296 test_must_fail git merge "$c5" 2> out &&
e6c111b4 297 grep "Your local changes to the following files would be overwritten by merge:" out
446247db
JH
298'
299
885b9810
JH
300test_expect_success 'merge-recursive remove conflict' '
301
744747ef 302 rm -fr [abcd] &&
885b9810
JH
303 git checkout -f "$c1" &&
304
0cb0e143 305 git merge-recursive "$c0" -- "$c1" "$c5"
885b9810
JH
306 status=$?
307 case "$status" in
308 1)
309 : happy
310 ;;
311 *)
312 echo >&2 "why status $status!!!"
313 false
314 ;;
315 esac
316'
317
318test_expect_success 'merge-recursive remove conflict' '
319
320 git ls-files -s >actual &&
321 (
885b9810
JH
322 echo "100644 $o0 1 a"
323 echo "100644 $o1 2 a"
324 echo "100644 $o5 3 a"
744747ef 325 echo "100644 $o0 0 c"
885b9810
JH
326 echo "100644 $o1 0 d/e"
327 ) >expected &&
3af82863 328 test_cmp expected actual
885b9810
JH
329
330'
331
332test_expect_success 'merge-recursive d/f simple' '
744747ef 333 rm -fr [abcd] &&
885b9810
JH
334 git reset --hard &&
335 git checkout -f "$c1" &&
336
0cb0e143 337 git merge-recursive "$c0" -- "$c1" "$c3"
885b9810
JH
338'
339
340test_expect_success 'merge-recursive result' '
341
342 git ls-files -s >actual &&
343 (
885b9810
JH
344 echo "100644 $o1 0 a"
345 echo "100644 $o3 0 b/c"
744747ef 346 echo "100644 $o0 0 c"
885b9810
JH
347 echo "100644 $o1 0 d/e"
348 ) >expected &&
3af82863 349 test_cmp expected actual
885b9810
JH
350
351'
352
353test_expect_success 'merge-recursive d/f conflict' '
354
744747ef 355 rm -fr [abcd] &&
885b9810
JH
356 git reset --hard &&
357 git checkout -f "$c1" &&
358
0cb0e143 359 git merge-recursive "$c0" -- "$c1" "$c4"
885b9810
JH
360 status=$?
361 case "$status" in
362 1)
363 : happy
364 ;;
365 *)
366 echo >&2 "why status $status!!!"
367 false
368 ;;
369 esac
370'
371
372test_expect_success 'merge-recursive d/f conflict result' '
373
374 git ls-files -s >actual &&
375 (
885b9810
JH
376 echo "100644 $o0 1 a"
377 echo "100644 $o1 2 a"
378 echo "100644 $o4 0 a/c"
379 echo "100644 $o0 0 b"
744747ef 380 echo "100644 $o0 0 c"
885b9810
JH
381 echo "100644 $o1 0 d/e"
382 ) >expected &&
3af82863 383 test_cmp expected actual
885b9810
JH
384
385'
386
387test_expect_success 'merge-recursive d/f conflict the other way' '
388
744747ef 389 rm -fr [abcd] &&
885b9810
JH
390 git reset --hard &&
391 git checkout -f "$c4" &&
392
0cb0e143 393 git merge-recursive "$c0" -- "$c4" "$c1"
885b9810
JH
394 status=$?
395 case "$status" in
396 1)
397 : happy
398 ;;
399 *)
400 echo >&2 "why status $status!!!"
401 false
402 ;;
403 esac
404'
405
406test_expect_success 'merge-recursive d/f conflict result the other way' '
407
408 git ls-files -s >actual &&
409 (
885b9810
JH
410 echo "100644 $o0 1 a"
411 echo "100644 $o1 3 a"
412 echo "100644 $o4 0 a/c"
413 echo "100644 $o0 0 b"
744747ef 414 echo "100644 $o0 0 c"
885b9810
JH
415 echo "100644 $o1 0 d/e"
416 ) >expected &&
3af82863 417 test_cmp expected actual
885b9810
JH
418
419'
420
421test_expect_success 'merge-recursive d/f conflict' '
422
744747ef 423 rm -fr [abcd] &&
885b9810
JH
424 git reset --hard &&
425 git checkout -f "$c1" &&
426
0cb0e143 427 git merge-recursive "$c0" -- "$c1" "$c6"
885b9810
JH
428 status=$?
429 case "$status" in
430 1)
431 : happy
432 ;;
433 *)
434 echo >&2 "why status $status!!!"
435 false
436 ;;
437 esac
438'
439
440test_expect_success 'merge-recursive d/f conflict result' '
441
442 git ls-files -s >actual &&
443 (
885b9810
JH
444 echo "100644 $o1 0 a"
445 echo "100644 $o0 0 b"
744747ef 446 echo "100644 $o0 0 c"
885b9810
JH
447 echo "100644 $o6 3 d"
448 echo "100644 $o0 1 d/e"
449 echo "100644 $o1 2 d/e"
450 ) >expected &&
3af82863 451 test_cmp expected actual
885b9810
JH
452
453'
454
455test_expect_success 'merge-recursive d/f conflict' '
456
744747ef 457 rm -fr [abcd] &&
885b9810
JH
458 git reset --hard &&
459 git checkout -f "$c6" &&
460
0cb0e143 461 git merge-recursive "$c0" -- "$c6" "$c1"
885b9810
JH
462 status=$?
463 case "$status" in
464 1)
465 : happy
466 ;;
467 *)
468 echo >&2 "why status $status!!!"
469 false
470 ;;
471 esac
472'
473
474test_expect_success 'merge-recursive d/f conflict result' '
475
476 git ls-files -s >actual &&
477 (
885b9810
JH
478 echo "100644 $o1 0 a"
479 echo "100644 $o0 0 b"
744747ef 480 echo "100644 $o0 0 c"
885b9810
JH
481 echo "100644 $o6 2 d"
482 echo "100644 $o0 1 d/e"
483 echo "100644 $o1 3 d/e"
484 ) >expected &&
3af82863 485 test_cmp expected actual
885b9810
JH
486
487'
488
489test_expect_success 'reset and 3-way merge' '
490
491 git reset --hard "$c2" &&
492 git read-tree -m "$c0" "$c2" "$c1"
493
494'
495
496test_expect_success 'reset and bind merge' '
497
498 git reset --hard master &&
499 git read-tree --prefix=M/ master &&
500 git ls-files -s >actual &&
501 (
885b9810
JH
502 echo "100644 $o1 0 M/a"
503 echo "100644 $o0 0 M/b"
744747ef 504 echo "100644 $o0 0 M/c"
885b9810
JH
505 echo "100644 $o1 0 M/d/e"
506 echo "100644 $o1 0 a"
507 echo "100644 $o0 0 b"
744747ef 508 echo "100644 $o0 0 c"
885b9810
JH
509 echo "100644 $o1 0 d/e"
510 ) >expected &&
3af82863 511 test_cmp expected actual &&
885b9810
JH
512
513 git read-tree --prefix=a1/ master &&
514 git ls-files -s >actual &&
515 (
885b9810
JH
516 echo "100644 $o1 0 M/a"
517 echo "100644 $o0 0 M/b"
744747ef 518 echo "100644 $o0 0 M/c"
885b9810
JH
519 echo "100644 $o1 0 M/d/e"
520 echo "100644 $o1 0 a"
885b9810
JH
521 echo "100644 $o1 0 a1/a"
522 echo "100644 $o0 0 a1/b"
744747ef 523 echo "100644 $o0 0 a1/c"
885b9810
JH
524 echo "100644 $o1 0 a1/d/e"
525 echo "100644 $o0 0 b"
744747ef 526 echo "100644 $o0 0 c"
885b9810
JH
527 echo "100644 $o1 0 d/e"
528 ) >expected &&
3af82863 529 test_cmp expected actual
885b9810
JH
530
531 git read-tree --prefix=z/ master &&
532 git ls-files -s >actual &&
533 (
885b9810
JH
534 echo "100644 $o1 0 M/a"
535 echo "100644 $o0 0 M/b"
744747ef 536 echo "100644 $o0 0 M/c"
885b9810
JH
537 echo "100644 $o1 0 M/d/e"
538 echo "100644 $o1 0 a"
885b9810
JH
539 echo "100644 $o1 0 a1/a"
540 echo "100644 $o0 0 a1/b"
744747ef 541 echo "100644 $o0 0 a1/c"
885b9810
JH
542 echo "100644 $o1 0 a1/d/e"
543 echo "100644 $o0 0 b"
744747ef 544 echo "100644 $o0 0 c"
885b9810 545 echo "100644 $o1 0 d/e"
885b9810
JH
546 echo "100644 $o1 0 z/a"
547 echo "100644 $o0 0 z/b"
744747ef 548 echo "100644 $o0 0 z/c"
885b9810
JH
549 echo "100644 $o1 0 z/d/e"
550 ) >expected &&
3af82863 551 test_cmp expected actual
885b9810
JH
552
553'
554
41f13af5
AR
555test_expect_success 'merge removes empty directories' '
556
557 git reset --hard master &&
558 git checkout -b rm &&
559 git rm d/e &&
560 git commit -mremoved-d/e &&
561 git checkout master &&
562 git merge -s recursive rm &&
563 test_must_fail test -d d
564'
565
7d82b06d
JS
566test_expect_failure 'merge-recursive simple w/submodule' '
567
568 git checkout submod &&
569 git merge remove
570'
571
572test_expect_failure 'merge-recursive simple w/submodule result' '
573
574 git ls-files -s >actual &&
575 (
576 echo "100644 $o5 0 a"
577 echo "100644 $o0 0 c"
578 echo "160000 $c1 0 d"
579 ) >expected &&
580 test_cmp expected actual
581'
582
885b9810 583test_done