Merge branch 'ed/color-prompt'
[git/gitweb.git] / t / t3030-merge-recursive.sh
blob2f96100a5f655bbea859bf596ff9835c9abb11a2
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 &&
28 git branch rename-ln &&
30 echo hello >>a &&
31 cp a d/e &&
32 o1=$(git hash-object a) &&
34 git add a d/e &&
36 test_tick &&
37 git commit -m "master modifies a and d/e" &&
38 c1=$(git rev-parse --verify HEAD) &&
39 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
48 echo "100644 $o1 0 d/e"
49 ) >expected &&
50 test_cmp expected actual
53 test_expect_success 'setup 2' '
55 rm -rf [abcd] &&
56 git checkout side &&
57 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
66 echo "100644 $o0 0 d/e"
67 ) >expected &&
68 test_cmp expected actual &&
70 echo goodbye >>a &&
71 o2=$(git hash-object a) &&
73 git add a &&
75 test_tick &&
76 git commit -m "side modifies a" &&
77 c2=$(git rev-parse --verify HEAD) &&
78 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
87 echo "100644 $o0 0 d/e"
88 ) >expected &&
89 test_cmp expected actual
92 test_expect_success 'setup 3' '
94 rm -rf [abcd] &&
95 git checkout df-1 &&
96 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
105 echo "100644 $o0 0 d/e"
106 ) >expected &&
107 test_cmp expected actual &&
109 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
110 o3=$(git hash-object b/c) &&
112 test_tick &&
113 git commit -m "df-1 makes b/c" &&
114 c3=$(git rev-parse --verify HEAD) &&
115 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
124 echo "100644 $o0 0 d/e"
125 ) >expected &&
126 test_cmp expected actual
129 test_expect_success 'setup 4' '
131 rm -rf [abcd] &&
132 git checkout df-2 &&
133 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
142 echo "100644 $o0 0 d/e"
143 ) >expected &&
144 test_cmp expected actual &&
146 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
147 o4=$(git hash-object a/c) &&
149 test_tick &&
150 git commit -m "df-2 makes a/c" &&
151 c4=$(git rev-parse --verify HEAD) &&
152 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
161 echo "100644 $o0 0 d/e"
162 ) >expected &&
163 test_cmp expected actual
166 test_expect_success 'setup 5' '
168 rm -rf [abcd] &&
169 git checkout remove &&
170 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
179 echo "100644 $o0 0 d/e"
180 ) >expected &&
181 test_cmp expected actual &&
183 rm -f b &&
184 echo remove-conflict >a &&
186 git add a &&
187 git rm b &&
188 o5=$(git hash-object a) &&
190 test_tick &&
191 git commit -m "remove removes b and modifies a" &&
192 c5=$(git rev-parse --verify HEAD) &&
193 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
200 echo "100644 $o0 0 d/e"
201 ) >expected &&
202 test_cmp expected actual
206 test_expect_success 'setup 6' '
208 rm -rf [abcd] &&
209 git checkout df-3 &&
210 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
219 echo "100644 $o0 0 d/e"
220 ) >expected &&
221 test_cmp expected actual &&
223 rm -fr d && echo df-3 >d && git add d &&
224 o6=$(git hash-object d) &&
226 test_tick &&
227 git commit -m "df-3 makes d" &&
228 c6=$(git rev-parse --verify HEAD) &&
229 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
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"
238 echo "100644 $o6 0 d"
239 ) >expected &&
240 test_cmp expected actual
243 test_expect_success 'setup 7' '
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"
254 test_expect_success 'setup 8' '
255 git checkout rename &&
256 git mv a e &&
257 git add e &&
258 test_tick &&
259 git commit -m "rename a->e" &&
260 git checkout rename-ln &&
261 git mv a e &&
262 test_ln_s_add e a &&
263 test_tick &&
264 git commit -m "rename a->e, symlink a->e" &&
265 oln=`printf e | git hash-object --stdin`
268 test_expect_success 'setup 9' '
269 git checkout copy &&
270 cp a e &&
271 git add e &&
272 test_tick &&
273 git commit -m "copy a->e"
276 test_expect_success 'merge-recursive simple' '
278 rm -fr [abcd] &&
279 git checkout -f "$c2" &&
281 test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1"
284 test_expect_success 'merge-recursive result' '
286 git ls-files -s >actual &&
288 echo "100644 $o0 1 a"
289 echo "100644 $o2 2 a"
290 echo "100644 $o1 3 a"
291 echo "100644 $o0 0 b"
292 echo "100644 $o0 0 c"
293 echo "100644 $o1 0 d/e"
294 ) >expected &&
295 test_cmp expected actual
299 test_expect_success 'fail if the index has unresolved entries' '
301 rm -fr [abcd] &&
302 git checkout -f "$c1" &&
304 test_must_fail git merge "$c5" &&
305 test_must_fail git merge "$c5" 2> out &&
306 test_i18ngrep "not possible because you have unmerged files" out &&
307 git add -u &&
308 test_must_fail git merge "$c5" 2> out &&
309 test_i18ngrep "You have not concluded your merge" out &&
310 rm -f .git/MERGE_HEAD &&
311 test_must_fail git merge "$c5" 2> out &&
312 test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
315 test_expect_success 'merge-recursive remove conflict' '
317 rm -fr [abcd] &&
318 git checkout -f "$c1" &&
320 test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5"
323 test_expect_success 'merge-recursive remove conflict' '
325 git ls-files -s >actual &&
327 echo "100644 $o0 1 a"
328 echo "100644 $o1 2 a"
329 echo "100644 $o5 3 a"
330 echo "100644 $o0 0 c"
331 echo "100644 $o1 0 d/e"
332 ) >expected &&
333 test_cmp expected actual
337 test_expect_success 'merge-recursive d/f simple' '
338 rm -fr [abcd] &&
339 git reset --hard &&
340 git checkout -f "$c1" &&
342 git merge-recursive "$c0" -- "$c1" "$c3"
345 test_expect_success 'merge-recursive result' '
347 git ls-files -s >actual &&
349 echo "100644 $o1 0 a"
350 echo "100644 $o3 0 b/c"
351 echo "100644 $o0 0 c"
352 echo "100644 $o1 0 d/e"
353 ) >expected &&
354 test_cmp expected actual
358 test_expect_success 'merge-recursive d/f conflict' '
360 rm -fr [abcd] &&
361 git reset --hard &&
362 git checkout -f "$c1" &&
364 test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4"
367 test_expect_success 'merge-recursive d/f conflict result' '
369 git ls-files -s >actual &&
371 echo "100644 $o0 1 a"
372 echo "100644 $o1 2 a"
373 echo "100644 $o4 0 a/c"
374 echo "100644 $o0 0 b"
375 echo "100644 $o0 0 c"
376 echo "100644 $o1 0 d/e"
377 ) >expected &&
378 test_cmp expected actual
382 test_expect_success 'merge-recursive d/f conflict the other way' '
384 rm -fr [abcd] &&
385 git reset --hard &&
386 git checkout -f "$c4" &&
388 test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1"
391 test_expect_success 'merge-recursive d/f conflict result the other way' '
393 git ls-files -s >actual &&
395 echo "100644 $o0 1 a"
396 echo "100644 $o1 3 a"
397 echo "100644 $o4 0 a/c"
398 echo "100644 $o0 0 b"
399 echo "100644 $o0 0 c"
400 echo "100644 $o1 0 d/e"
401 ) >expected &&
402 test_cmp expected actual
406 test_expect_success 'merge-recursive d/f conflict' '
408 rm -fr [abcd] &&
409 git reset --hard &&
410 git checkout -f "$c1" &&
412 test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6"
415 test_expect_success 'merge-recursive d/f conflict result' '
417 git ls-files -s >actual &&
419 echo "100644 $o1 0 a"
420 echo "100644 $o0 0 b"
421 echo "100644 $o0 0 c"
422 echo "100644 $o6 3 d"
423 echo "100644 $o0 1 d/e"
424 echo "100644 $o1 2 d/e"
425 ) >expected &&
426 test_cmp expected actual
430 test_expect_success 'merge-recursive d/f conflict' '
432 rm -fr [abcd] &&
433 git reset --hard &&
434 git checkout -f "$c6" &&
436 test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1"
439 test_expect_success 'merge-recursive d/f conflict result' '
441 git ls-files -s >actual &&
443 echo "100644 $o1 0 a"
444 echo "100644 $o0 0 b"
445 echo "100644 $o0 0 c"
446 echo "100644 $o6 2 d"
447 echo "100644 $o0 1 d/e"
448 echo "100644 $o1 3 d/e"
449 ) >expected &&
450 test_cmp expected actual
454 test_expect_success 'reset and 3-way merge' '
456 git reset --hard "$c2" &&
457 git read-tree -m "$c0" "$c2" "$c1"
461 test_expect_success 'reset and bind merge' '
463 git reset --hard master &&
464 git read-tree --prefix=M/ master &&
465 git ls-files -s >actual &&
467 echo "100644 $o1 0 M/a"
468 echo "100644 $o0 0 M/b"
469 echo "100644 $o0 0 M/c"
470 echo "100644 $o1 0 M/d/e"
471 echo "100644 $o1 0 a"
472 echo "100644 $o0 0 b"
473 echo "100644 $o0 0 c"
474 echo "100644 $o1 0 d/e"
475 ) >expected &&
476 test_cmp expected actual &&
478 git read-tree --prefix=a1/ master &&
479 git ls-files -s >actual &&
481 echo "100644 $o1 0 M/a"
482 echo "100644 $o0 0 M/b"
483 echo "100644 $o0 0 M/c"
484 echo "100644 $o1 0 M/d/e"
485 echo "100644 $o1 0 a"
486 echo "100644 $o1 0 a1/a"
487 echo "100644 $o0 0 a1/b"
488 echo "100644 $o0 0 a1/c"
489 echo "100644 $o1 0 a1/d/e"
490 echo "100644 $o0 0 b"
491 echo "100644 $o0 0 c"
492 echo "100644 $o1 0 d/e"
493 ) >expected &&
494 test_cmp expected actual &&
496 git read-tree --prefix=z/ master &&
497 git ls-files -s >actual &&
499 echo "100644 $o1 0 M/a"
500 echo "100644 $o0 0 M/b"
501 echo "100644 $o0 0 M/c"
502 echo "100644 $o1 0 M/d/e"
503 echo "100644 $o1 0 a"
504 echo "100644 $o1 0 a1/a"
505 echo "100644 $o0 0 a1/b"
506 echo "100644 $o0 0 a1/c"
507 echo "100644 $o1 0 a1/d/e"
508 echo "100644 $o0 0 b"
509 echo "100644 $o0 0 c"
510 echo "100644 $o1 0 d/e"
511 echo "100644 $o1 0 z/a"
512 echo "100644 $o0 0 z/b"
513 echo "100644 $o0 0 z/c"
514 echo "100644 $o1 0 z/d/e"
515 ) >expected &&
516 test_cmp expected actual
520 test_expect_success 'merge removes empty directories' '
522 git reset --hard master &&
523 git checkout -b rm &&
524 git rm d/e &&
525 git commit -mremoved-d/e &&
526 git checkout master &&
527 git merge -s recursive rm &&
528 test_must_fail test -d d
531 test_expect_failure 'merge-recursive simple w/submodule' '
533 git checkout submod &&
534 git merge remove
537 test_expect_failure 'merge-recursive simple w/submodule result' '
539 git ls-files -s >actual &&
541 echo "100644 $o5 0 a"
542 echo "100644 $o0 0 c"
543 echo "160000 $c1 0 d"
544 ) >expected &&
545 test_cmp expected actual
548 test_expect_success 'merge-recursive copy vs. rename' '
549 git checkout -f copy &&
550 git merge rename &&
551 ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
553 echo "100644 blob $o0 b"
554 echo "100644 blob $o0 c"
555 echo "100644 blob $o0 d/e"
556 echo "100644 blob $o0 e"
557 echo "100644 $o0 0 b"
558 echo "100644 $o0 0 c"
559 echo "100644 $o0 0 d/e"
560 echo "100644 $o0 0 e"
561 ) >expected &&
562 test_cmp expected actual
565 test_expect_failure 'merge-recursive rename vs. rename/symlink' '
567 git checkout -f rename &&
568 git merge rename-ln &&
569 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
571 echo "120000 blob $oln a"
572 echo "100644 blob $o0 b"
573 echo "100644 blob $o0 c"
574 echo "100644 blob $o0 d/e"
575 echo "100644 blob $o0 e"
576 echo "120000 $oln 0 a"
577 echo "100644 $o0 0 b"
578 echo "100644 $o0 0 c"
579 echo "100644 $o0 0 d/e"
580 echo "100644 $o0 0 e"
581 ) >expected &&
582 test_cmp expected actual
586 test_done