cherry-pick/revert: Use error() for failure message
[git/dscho.git] / t / t3030-merge-recursive.sh
blobd541544537d47587abad8d27565cf9197387cfd6
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 &&
27 echo hello >>a &&
28 cp a d/e &&
29 o1=$(git hash-object a) &&
31 git add a d/e &&
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 &&
38 echo "100644 blob $o1 a"
39 echo "100644 blob $o0 b"
40 echo "100644 blob $o0 c"
41 echo "100644 blob $o1 d/e"
42 echo "100644 $o1 0 a"
43 echo "100644 $o0 0 b"
44 echo "100644 $o0 0 c"
45 echo "100644 $o1 0 d/e"
46 ) >expected &&
47 test_cmp expected actual
50 test_expect_success 'setup 2' '
52 rm -rf [abcd] &&
53 git checkout side &&
54 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
56 echo "100644 blob $o0 a"
57 echo "100644 blob $o0 b"
58 echo "100644 blob $o0 c"
59 echo "100644 blob $o0 d/e"
60 echo "100644 $o0 0 a"
61 echo "100644 $o0 0 b"
62 echo "100644 $o0 0 c"
63 echo "100644 $o0 0 d/e"
64 ) >expected &&
65 test_cmp expected actual &&
67 echo goodbye >>a &&
68 o2=$(git hash-object a) &&
70 git add a &&
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 &&
77 echo "100644 blob $o2 a"
78 echo "100644 blob $o0 b"
79 echo "100644 blob $o0 c"
80 echo "100644 blob $o0 d/e"
81 echo "100644 $o2 0 a"
82 echo "100644 $o0 0 b"
83 echo "100644 $o0 0 c"
84 echo "100644 $o0 0 d/e"
85 ) >expected &&
86 test_cmp expected actual
89 test_expect_success 'setup 3' '
91 rm -rf [abcd] &&
92 git checkout df-1 &&
93 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
95 echo "100644 blob $o0 a"
96 echo "100644 blob $o0 b"
97 echo "100644 blob $o0 c"
98 echo "100644 blob $o0 d/e"
99 echo "100644 $o0 0 a"
100 echo "100644 $o0 0 b"
101 echo "100644 $o0 0 c"
102 echo "100644 $o0 0 d/e"
103 ) >expected &&
104 test_cmp expected actual &&
106 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
107 o3=$(git hash-object b/c) &&
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 &&
114 echo "100644 blob $o0 a"
115 echo "100644 blob $o3 b/c"
116 echo "100644 blob $o0 c"
117 echo "100644 blob $o0 d/e"
118 echo "100644 $o0 0 a"
119 echo "100644 $o3 0 b/c"
120 echo "100644 $o0 0 c"
121 echo "100644 $o0 0 d/e"
122 ) >expected &&
123 test_cmp expected actual
126 test_expect_success 'setup 4' '
128 rm -rf [abcd] &&
129 git checkout df-2 &&
130 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
132 echo "100644 blob $o0 a"
133 echo "100644 blob $o0 b"
134 echo "100644 blob $o0 c"
135 echo "100644 blob $o0 d/e"
136 echo "100644 $o0 0 a"
137 echo "100644 $o0 0 b"
138 echo "100644 $o0 0 c"
139 echo "100644 $o0 0 d/e"
140 ) >expected &&
141 test_cmp expected actual &&
143 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
144 o4=$(git hash-object a/c) &&
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 &&
151 echo "100644 blob $o4 a/c"
152 echo "100644 blob $o0 b"
153 echo "100644 blob $o0 c"
154 echo "100644 blob $o0 d/e"
155 echo "100644 $o4 0 a/c"
156 echo "100644 $o0 0 b"
157 echo "100644 $o0 0 c"
158 echo "100644 $o0 0 d/e"
159 ) >expected &&
160 test_cmp expected actual
163 test_expect_success 'setup 5' '
165 rm -rf [abcd] &&
166 git checkout remove &&
167 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
169 echo "100644 blob $o0 a"
170 echo "100644 blob $o0 b"
171 echo "100644 blob $o0 c"
172 echo "100644 blob $o0 d/e"
173 echo "100644 $o0 0 a"
174 echo "100644 $o0 0 b"
175 echo "100644 $o0 0 c"
176 echo "100644 $o0 0 d/e"
177 ) >expected &&
178 test_cmp expected actual &&
180 rm -f b &&
181 echo remove-conflict >a &&
183 git add a &&
184 git rm b &&
185 o5=$(git hash-object a) &&
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 &&
192 echo "100644 blob $o5 a"
193 echo "100644 blob $o0 c"
194 echo "100644 blob $o0 d/e"
195 echo "100644 $o5 0 a"
196 echo "100644 $o0 0 c"
197 echo "100644 $o0 0 d/e"
198 ) >expected &&
199 test_cmp expected actual
203 test_expect_success 'setup 6' '
205 rm -rf [abcd] &&
206 git checkout df-3 &&
207 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
209 echo "100644 blob $o0 a"
210 echo "100644 blob $o0 b"
211 echo "100644 blob $o0 c"
212 echo "100644 blob $o0 d/e"
213 echo "100644 $o0 0 a"
214 echo "100644 $o0 0 b"
215 echo "100644 $o0 0 c"
216 echo "100644 $o0 0 d/e"
217 ) >expected &&
218 test_cmp expected actual &&
220 rm -fr d && echo df-3 >d && git add d &&
221 o6=$(git hash-object d) &&
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 &&
228 echo "100644 blob $o0 a"
229 echo "100644 blob $o0 b"
230 echo "100644 blob $o0 c"
231 echo "100644 blob $o6 d"
232 echo "100644 $o0 0 a"
233 echo "100644 $o0 0 b"
234 echo "100644 $o0 0 c"
235 echo "100644 $o6 0 d"
236 ) >expected &&
237 test_cmp expected actual
240 test_expect_success 'setup 7' '
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"
251 test_expect_success 'merge-recursive simple' '
253 rm -fr [abcd] &&
254 git checkout -f "$c2" &&
256 git merge-recursive "$c0" -- "$c2" "$c1"
257 status=$?
258 case "$status" in
260 : happy
263 echo >&2 "why status $status!!!"
264 false
266 esac
269 test_expect_success 'merge-recursive result' '
271 git ls-files -s >actual &&
273 echo "100644 $o0 1 a"
274 echo "100644 $o2 2 a"
275 echo "100644 $o1 3 a"
276 echo "100644 $o0 0 b"
277 echo "100644 $o0 0 c"
278 echo "100644 $o1 0 d/e"
279 ) >expected &&
280 test_cmp expected actual
284 test_expect_success 'fail if the index has unresolved entries' '
286 rm -fr [abcd] &&
287 git checkout -f "$c1" &&
289 test_must_fail git merge "$c5" &&
290 test_must_fail git merge "$c5" 2> out &&
291 grep "not possible because you have unmerged files" out &&
292 git add -u &&
293 test_must_fail git merge "$c5" 2> out &&
294 grep "You have not concluded your merge" out &&
295 rm -f .git/MERGE_HEAD &&
296 test_must_fail git merge "$c5" 2> out &&
297 grep "Your local changes to .* would be overwritten by merge." out
300 test_expect_success 'merge-recursive remove conflict' '
302 rm -fr [abcd] &&
303 git checkout -f "$c1" &&
305 git merge-recursive "$c0" -- "$c1" "$c5"
306 status=$?
307 case "$status" in
309 : happy
312 echo >&2 "why status $status!!!"
313 false
315 esac
318 test_expect_success 'merge-recursive remove conflict' '
320 git ls-files -s >actual &&
322 echo "100644 $o0 1 a"
323 echo "100644 $o1 2 a"
324 echo "100644 $o5 3 a"
325 echo "100644 $o0 0 c"
326 echo "100644 $o1 0 d/e"
327 ) >expected &&
328 test_cmp expected actual
332 test_expect_success 'merge-recursive d/f simple' '
333 rm -fr [abcd] &&
334 git reset --hard &&
335 git checkout -f "$c1" &&
337 git merge-recursive "$c0" -- "$c1" "$c3"
340 test_expect_success 'merge-recursive result' '
342 git ls-files -s >actual &&
344 echo "100644 $o1 0 a"
345 echo "100644 $o3 0 b/c"
346 echo "100644 $o0 0 c"
347 echo "100644 $o1 0 d/e"
348 ) >expected &&
349 test_cmp expected actual
353 test_expect_success 'merge-recursive d/f conflict' '
355 rm -fr [abcd] &&
356 git reset --hard &&
357 git checkout -f "$c1" &&
359 git merge-recursive "$c0" -- "$c1" "$c4"
360 status=$?
361 case "$status" in
363 : happy
366 echo >&2 "why status $status!!!"
367 false
369 esac
372 test_expect_success 'merge-recursive d/f conflict result' '
374 git ls-files -s >actual &&
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"
380 echo "100644 $o0 0 c"
381 echo "100644 $o1 0 d/e"
382 ) >expected &&
383 test_cmp expected actual
387 test_expect_success 'merge-recursive d/f conflict the other way' '
389 rm -fr [abcd] &&
390 git reset --hard &&
391 git checkout -f "$c4" &&
393 git merge-recursive "$c0" -- "$c4" "$c1"
394 status=$?
395 case "$status" in
397 : happy
400 echo >&2 "why status $status!!!"
401 false
403 esac
406 test_expect_success 'merge-recursive d/f conflict result the other way' '
408 git ls-files -s >actual &&
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"
414 echo "100644 $o0 0 c"
415 echo "100644 $o1 0 d/e"
416 ) >expected &&
417 test_cmp expected actual
421 test_expect_success 'merge-recursive d/f conflict' '
423 rm -fr [abcd] &&
424 git reset --hard &&
425 git checkout -f "$c1" &&
427 git merge-recursive "$c0" -- "$c1" "$c6"
428 status=$?
429 case "$status" in
431 : happy
434 echo >&2 "why status $status!!!"
435 false
437 esac
440 test_expect_success 'merge-recursive d/f conflict result' '
442 git ls-files -s >actual &&
444 echo "100644 $o1 0 a"
445 echo "100644 $o0 0 b"
446 echo "100644 $o0 0 c"
447 echo "100644 $o6 3 d"
448 echo "100644 $o0 1 d/e"
449 echo "100644 $o1 2 d/e"
450 ) >expected &&
451 test_cmp expected actual
455 test_expect_success 'merge-recursive d/f conflict' '
457 rm -fr [abcd] &&
458 git reset --hard &&
459 git checkout -f "$c6" &&
461 git merge-recursive "$c0" -- "$c6" "$c1"
462 status=$?
463 case "$status" in
465 : happy
468 echo >&2 "why status $status!!!"
469 false
471 esac
474 test_expect_success 'merge-recursive d/f conflict result' '
476 git ls-files -s >actual &&
478 echo "100644 $o1 0 a"
479 echo "100644 $o0 0 b"
480 echo "100644 $o0 0 c"
481 echo "100644 $o6 2 d"
482 echo "100644 $o0 1 d/e"
483 echo "100644 $o1 3 d/e"
484 ) >expected &&
485 test_cmp expected actual
489 test_expect_success 'reset and 3-way merge' '
491 git reset --hard "$c2" &&
492 git read-tree -m "$c0" "$c2" "$c1"
496 test_expect_success 'reset and bind merge' '
498 git reset --hard master &&
499 git read-tree --prefix=M/ master &&
500 git ls-files -s >actual &&
502 echo "100644 $o1 0 M/a"
503 echo "100644 $o0 0 M/b"
504 echo "100644 $o0 0 M/c"
505 echo "100644 $o1 0 M/d/e"
506 echo "100644 $o1 0 a"
507 echo "100644 $o0 0 b"
508 echo "100644 $o0 0 c"
509 echo "100644 $o1 0 d/e"
510 ) >expected &&
511 test_cmp expected actual &&
513 git read-tree --prefix=a1/ master &&
514 git ls-files -s >actual &&
516 echo "100644 $o1 0 M/a"
517 echo "100644 $o0 0 M/b"
518 echo "100644 $o0 0 M/c"
519 echo "100644 $o1 0 M/d/e"
520 echo "100644 $o1 0 a"
521 echo "100644 $o1 0 a1/a"
522 echo "100644 $o0 0 a1/b"
523 echo "100644 $o0 0 a1/c"
524 echo "100644 $o1 0 a1/d/e"
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=z/ 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 echo "100644 $o1 0 z/a"
547 echo "100644 $o0 0 z/b"
548 echo "100644 $o0 0 z/c"
549 echo "100644 $o1 0 z/d/e"
550 ) >expected &&
551 test_cmp expected actual
555 test_expect_success 'merge removes empty directories' '
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
566 test_expect_failure 'merge-recursive simple w/submodule' '
568 git checkout submod &&
569 git merge remove
572 test_expect_failure 'merge-recursive simple w/submodule result' '
574 git ls-files -s >actual &&
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
583 test_done