3 test_description
='merge-recursive backend test'
7 test_expect_success
'setup 1' '
10 o0=$(git hash-object a) &&
18 git commit -m initial &&
19 c0=$(git rev-parse --verify HEAD) &&
28 if test_have_prereq SYMLINKS
35 o1=$(git hash-object a) &&
40 git commit -m "master modifies a and d/e" &&
41 c1=$(git rev-parse --verify HEAD) &&
42 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
44 echo "100644 blob $o1 a"
45 echo "100644 blob $o0 b"
46 echo "100644 blob $o0 c"
47 echo "100644 blob $o1 d/e"
51 echo "100644 $o1 0 d/e"
53 test_cmp expected actual
56 test_expect_success
'setup 2' '
60 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
62 echo "100644 blob $o0 a"
63 echo "100644 blob $o0 b"
64 echo "100644 blob $o0 c"
65 echo "100644 blob $o0 d/e"
69 echo "100644 $o0 0 d/e"
71 test_cmp expected actual &&
74 o2=$(git hash-object a) &&
79 git commit -m "side modifies a" &&
80 c2=$(git rev-parse --verify HEAD) &&
81 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
83 echo "100644 blob $o2 a"
84 echo "100644 blob $o0 b"
85 echo "100644 blob $o0 c"
86 echo "100644 blob $o0 d/e"
90 echo "100644 $o0 0 d/e"
92 test_cmp expected actual
95 test_expect_success
'setup 3' '
99 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
101 echo "100644 blob $o0 a"
102 echo "100644 blob $o0 b"
103 echo "100644 blob $o0 c"
104 echo "100644 blob $o0 d/e"
105 echo "100644 $o0 0 a"
106 echo "100644 $o0 0 b"
107 echo "100644 $o0 0 c"
108 echo "100644 $o0 0 d/e"
110 test_cmp expected actual &&
112 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
113 o3=$(git hash-object b/c) &&
116 git commit -m "df-1 makes b/c" &&
117 c3=$(git rev-parse --verify HEAD) &&
118 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
120 echo "100644 blob $o0 a"
121 echo "100644 blob $o3 b/c"
122 echo "100644 blob $o0 c"
123 echo "100644 blob $o0 d/e"
124 echo "100644 $o0 0 a"
125 echo "100644 $o3 0 b/c"
126 echo "100644 $o0 0 c"
127 echo "100644 $o0 0 d/e"
129 test_cmp expected actual
132 test_expect_success
'setup 4' '
136 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
138 echo "100644 blob $o0 a"
139 echo "100644 blob $o0 b"
140 echo "100644 blob $o0 c"
141 echo "100644 blob $o0 d/e"
142 echo "100644 $o0 0 a"
143 echo "100644 $o0 0 b"
144 echo "100644 $o0 0 c"
145 echo "100644 $o0 0 d/e"
147 test_cmp expected actual &&
149 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
150 o4=$(git hash-object a/c) &&
153 git commit -m "df-2 makes a/c" &&
154 c4=$(git rev-parse --verify HEAD) &&
155 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
157 echo "100644 blob $o4 a/c"
158 echo "100644 blob $o0 b"
159 echo "100644 blob $o0 c"
160 echo "100644 blob $o0 d/e"
161 echo "100644 $o4 0 a/c"
162 echo "100644 $o0 0 b"
163 echo "100644 $o0 0 c"
164 echo "100644 $o0 0 d/e"
166 test_cmp expected actual
169 test_expect_success
'setup 5' '
172 git checkout remove &&
173 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
175 echo "100644 blob $o0 a"
176 echo "100644 blob $o0 b"
177 echo "100644 blob $o0 c"
178 echo "100644 blob $o0 d/e"
179 echo "100644 $o0 0 a"
180 echo "100644 $o0 0 b"
181 echo "100644 $o0 0 c"
182 echo "100644 $o0 0 d/e"
184 test_cmp expected actual &&
187 echo remove-conflict >a &&
191 o5=$(git hash-object a) &&
194 git commit -m "remove removes b and modifies a" &&
195 c5=$(git rev-parse --verify HEAD) &&
196 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
198 echo "100644 blob $o5 a"
199 echo "100644 blob $o0 c"
200 echo "100644 blob $o0 d/e"
201 echo "100644 $o5 0 a"
202 echo "100644 $o0 0 c"
203 echo "100644 $o0 0 d/e"
205 test_cmp expected actual
209 test_expect_success
'setup 6' '
213 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
215 echo "100644 blob $o0 a"
216 echo "100644 blob $o0 b"
217 echo "100644 blob $o0 c"
218 echo "100644 blob $o0 d/e"
219 echo "100644 $o0 0 a"
220 echo "100644 $o0 0 b"
221 echo "100644 $o0 0 c"
222 echo "100644 $o0 0 d/e"
224 test_cmp expected actual &&
226 rm -fr d && echo df-3 >d && git add d &&
227 o6=$(git hash-object d) &&
230 git commit -m "df-3 makes d" &&
231 c6=$(git rev-parse --verify HEAD) &&
232 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
234 echo "100644 blob $o0 a"
235 echo "100644 blob $o0 b"
236 echo "100644 blob $o0 c"
237 echo "100644 blob $o6 d"
238 echo "100644 $o0 0 a"
239 echo "100644 $o0 0 b"
240 echo "100644 $o0 0 c"
241 echo "100644 $o6 0 d"
243 test_cmp expected actual
246 test_expect_success
'setup 7' '
248 git checkout submod &&
251 git commit -m "remove d/e" &&
252 git update-index --add --cacheinfo 160000 $c1 d &&
254 git commit -m "make d/ a submodule"
257 test_expect_success
'setup 8' '
258 git checkout rename &&
262 git commit -m "rename a->e" &&
263 if test_have_prereq SYMLINKS
265 git checkout rename-ln &&
270 git commit -m "rename a->e, symlink a->e" &&
271 oln=`printf e | git hash-object --stdin`
275 test_expect_success
'setup 9' '
280 git commit -m "copy a->e"
283 test_expect_success
'merge-recursive simple' '
286 git checkout -f "$c2" &&
288 git merge-recursive "$c0" -- "$c2" "$c1"
295 echo >&2 "why status $status!!!"
301 test_expect_success
'merge-recursive result' '
303 git ls-files -s >actual &&
305 echo "100644 $o0 1 a"
306 echo "100644 $o2 2 a"
307 echo "100644 $o1 3 a"
308 echo "100644 $o0 0 b"
309 echo "100644 $o0 0 c"
310 echo "100644 $o1 0 d/e"
312 test_cmp expected actual
316 test_expect_success
'fail if the index has unresolved entries' '
319 git checkout -f "$c1" &&
321 test_must_fail git merge "$c5" &&
322 test_must_fail git merge "$c5" 2> out &&
323 test_i18ngrep "not possible because you have unmerged files" out &&
325 test_must_fail git merge "$c5" 2> out &&
326 test_i18ngrep "You have not concluded your merge" out &&
327 rm -f .git/MERGE_HEAD &&
328 test_must_fail git merge "$c5" 2> out &&
329 test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
332 test_expect_success
'merge-recursive remove conflict' '
335 git checkout -f "$c1" &&
337 git merge-recursive "$c0" -- "$c1" "$c5"
344 echo >&2 "why status $status!!!"
350 test_expect_success
'merge-recursive remove conflict' '
352 git ls-files -s >actual &&
354 echo "100644 $o0 1 a"
355 echo "100644 $o1 2 a"
356 echo "100644 $o5 3 a"
357 echo "100644 $o0 0 c"
358 echo "100644 $o1 0 d/e"
360 test_cmp expected actual
364 test_expect_success
'merge-recursive d/f simple' '
367 git checkout -f "$c1" &&
369 git merge-recursive "$c0" -- "$c1" "$c3"
372 test_expect_success
'merge-recursive result' '
374 git ls-files -s >actual &&
376 echo "100644 $o1 0 a"
377 echo "100644 $o3 0 b/c"
378 echo "100644 $o0 0 c"
379 echo "100644 $o1 0 d/e"
381 test_cmp expected actual
385 test_expect_success
'merge-recursive d/f conflict' '
389 git checkout -f "$c1" &&
391 git merge-recursive "$c0" -- "$c1" "$c4"
398 echo >&2 "why status $status!!!"
404 test_expect_success
'merge-recursive d/f conflict result' '
406 git ls-files -s >actual &&
408 echo "100644 $o0 1 a"
409 echo "100644 $o1 2 a"
410 echo "100644 $o4 0 a/c"
411 echo "100644 $o0 0 b"
412 echo "100644 $o0 0 c"
413 echo "100644 $o1 0 d/e"
415 test_cmp expected actual
419 test_expect_success
'merge-recursive d/f conflict the other way' '
423 git checkout -f "$c4" &&
425 git merge-recursive "$c0" -- "$c4" "$c1"
432 echo >&2 "why status $status!!!"
438 test_expect_success
'merge-recursive d/f conflict result the other way' '
440 git ls-files -s >actual &&
442 echo "100644 $o0 1 a"
443 echo "100644 $o1 3 a"
444 echo "100644 $o4 0 a/c"
445 echo "100644 $o0 0 b"
446 echo "100644 $o0 0 c"
447 echo "100644 $o1 0 d/e"
449 test_cmp expected actual
453 test_expect_success
'merge-recursive d/f conflict' '
457 git checkout -f "$c1" &&
459 git merge-recursive "$c0" -- "$c1" "$c6"
466 echo >&2 "why status $status!!!"
472 test_expect_success
'merge-recursive d/f conflict result' '
474 git ls-files -s >actual &&
476 echo "100644 $o1 0 a"
477 echo "100644 $o0 0 b"
478 echo "100644 $o0 0 c"
479 echo "100644 $o6 3 d"
480 echo "100644 $o0 1 d/e"
481 echo "100644 $o1 2 d/e"
483 test_cmp expected actual
487 test_expect_success
'merge-recursive d/f conflict' '
491 git checkout -f "$c6" &&
493 git merge-recursive "$c0" -- "$c6" "$c1"
500 echo >&2 "why status $status!!!"
506 test_expect_success
'merge-recursive d/f conflict result' '
508 git ls-files -s >actual &&
510 echo "100644 $o1 0 a"
511 echo "100644 $o0 0 b"
512 echo "100644 $o0 0 c"
513 echo "100644 $o6 2 d"
514 echo "100644 $o0 1 d/e"
515 echo "100644 $o1 3 d/e"
517 test_cmp expected actual
521 test_expect_success
'reset and 3-way merge' '
523 git reset --hard "$c2" &&
524 git read-tree -m "$c0" "$c2" "$c1"
528 test_expect_success
'reset and bind merge' '
530 git reset --hard master &&
531 git read-tree --prefix=M/ 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 $o0 0 b"
540 echo "100644 $o0 0 c"
541 echo "100644 $o1 0 d/e"
543 test_cmp expected actual &&
545 git read-tree --prefix=a1/ master &&
546 git ls-files -s >actual &&
548 echo "100644 $o1 0 M/a"
549 echo "100644 $o0 0 M/b"
550 echo "100644 $o0 0 M/c"
551 echo "100644 $o1 0 M/d/e"
552 echo "100644 $o1 0 a"
553 echo "100644 $o1 0 a1/a"
554 echo "100644 $o0 0 a1/b"
555 echo "100644 $o0 0 a1/c"
556 echo "100644 $o1 0 a1/d/e"
557 echo "100644 $o0 0 b"
558 echo "100644 $o0 0 c"
559 echo "100644 $o1 0 d/e"
561 test_cmp expected actual &&
563 git read-tree --prefix=z/ master &&
564 git ls-files -s >actual &&
566 echo "100644 $o1 0 M/a"
567 echo "100644 $o0 0 M/b"
568 echo "100644 $o0 0 M/c"
569 echo "100644 $o1 0 M/d/e"
570 echo "100644 $o1 0 a"
571 echo "100644 $o1 0 a1/a"
572 echo "100644 $o0 0 a1/b"
573 echo "100644 $o0 0 a1/c"
574 echo "100644 $o1 0 a1/d/e"
575 echo "100644 $o0 0 b"
576 echo "100644 $o0 0 c"
577 echo "100644 $o1 0 d/e"
578 echo "100644 $o1 0 z/a"
579 echo "100644 $o0 0 z/b"
580 echo "100644 $o0 0 z/c"
581 echo "100644 $o1 0 z/d/e"
583 test_cmp expected actual
587 test_expect_success
'merge removes empty directories' '
589 git reset --hard master &&
590 git checkout -b rm &&
592 git commit -mremoved-d/e &&
593 git checkout master &&
594 git merge -s recursive rm &&
595 test_must_fail test -d d
598 test_expect_failure
'merge-recursive simple w/submodule' '
600 git checkout submod &&
604 test_expect_failure
'merge-recursive simple w/submodule result' '
606 git ls-files -s >actual &&
608 echo "100644 $o5 0 a"
609 echo "100644 $o0 0 c"
610 echo "160000 $c1 0 d"
612 test_cmp expected actual
615 test_expect_success
'merge-recursive copy vs. rename' '
616 git checkout -f copy &&
618 ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
620 echo "100644 blob $o0 b"
621 echo "100644 blob $o0 c"
622 echo "100644 blob $o0 d/e"
623 echo "100644 blob $o0 e"
624 echo "100644 $o0 0 b"
625 echo "100644 $o0 0 c"
626 echo "100644 $o0 0 d/e"
627 echo "100644 $o0 0 e"
629 test_cmp expected actual
632 if test_have_prereq SYMLINKS
634 test_expect_failure
'merge-recursive rename vs. rename/symlink' '
636 git checkout -f rename &&
637 git merge rename-ln &&
638 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
640 echo "120000 blob $oln a"
641 echo "100644 blob $o0 b"
642 echo "100644 blob $o0 c"
643 echo "100644 blob $o0 d/e"
644 echo "100644 blob $o0 e"
645 echo "120000 $oln 0 a"
646 echo "100644 $o0 0 b"
647 echo "100644 $o0 0 c"
648 echo "100644 $o0 0 d/e"
649 echo "100644 $o0 0 e"
651 test_cmp expected actual