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) &&
31 o1=$(git hash-object a) &&
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"
47 echo "100644 $o1 0 d/e"
49 test_cmp expected actual
52 test_expect_success
'setup 2' '
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"
65 echo "100644 $o0 0 d/e"
67 test_cmp expected actual &&
70 o2=$(git hash-object a) &&
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"
86 echo "100644 $o0 0 d/e"
88 test_cmp expected actual
91 test_expect_success
'setup 3' '
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"
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) &&
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"
125 test_cmp expected actual
128 test_expect_success
'setup 4' '
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"
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) &&
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"
162 test_cmp expected actual
165 test_expect_success
'setup 5' '
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"
180 test_cmp expected actual &&
183 echo remove-conflict >a &&
187 o5=$(git hash-object a) &&
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"
201 test_cmp expected actual
205 test_expect_success
'setup 6' '
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"
220 test_cmp expected actual &&
222 rm -fr d && echo df-3 >d && git add d &&
223 o6=$(git hash-object d) &&
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"
239 test_cmp expected actual
242 test_expect_success
'setup 7' '
244 git checkout submod &&
247 git commit -m "remove d/e" &&
248 git update-index --add --cacheinfo 160000 $c1 d &&
250 git commit -m "make d/ a submodule"
253 test_expect_success
'setup 8' '
254 git checkout rename &&
258 git commit -m "rename a->e"
261 test_expect_success
'setup 9' '
266 git commit -m "copy a->e"
269 test_expect_success
'merge-recursive simple' '
272 git checkout -f "$c2" &&
274 git merge-recursive "$c0" -- "$c2" "$c1"
281 echo >&2 "why status $status!!!"
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"
298 test_cmp expected actual
302 test_expect_success
'fail if the index has unresolved entries' '
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 &&
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' '
321 git checkout -f "$c1" &&
323 git merge-recursive "$c0" -- "$c1" "$c5"
330 echo >&2 "why status $status!!!"
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"
346 test_cmp expected actual
350 test_expect_success
'merge-recursive d/f simple' '
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"
367 test_cmp expected actual
371 test_expect_success
'merge-recursive d/f conflict' '
375 git checkout -f "$c1" &&
377 git merge-recursive "$c0" -- "$c1" "$c4"
384 echo >&2 "why status $status!!!"
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"
401 test_cmp expected actual
405 test_expect_success
'merge-recursive d/f conflict the other way' '
409 git checkout -f "$c4" &&
411 git merge-recursive "$c0" -- "$c4" "$c1"
418 echo >&2 "why status $status!!!"
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"
435 test_cmp expected actual
439 test_expect_success
'merge-recursive d/f conflict' '
443 git checkout -f "$c1" &&
445 git merge-recursive "$c0" -- "$c1" "$c6"
452 echo >&2 "why status $status!!!"
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"
469 test_cmp expected actual
473 test_expect_success
'merge-recursive d/f conflict' '
477 git checkout -f "$c6" &&
479 git merge-recursive "$c0" -- "$c6" "$c1"
486 echo >&2 "why status $status!!!"
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"
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"
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"
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"
569 test_cmp expected actual
573 test_expect_success
'merge removes empty directories' '
575 git reset --hard master &&
576 git checkout -b rm &&
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 &&
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"
598 test_cmp expected actual
601 test_expect_success
'merge-recursive copy vs. rename' '
602 git checkout -f copy &&
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"
615 test_cmp expected actual