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 o1=$(git hash-object a) &&
33 git commit -m "master modifies a and d/e" &&
34 c1=$(git rev-parse --verify HEAD) &&
35 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
37 echo "100644 blob $o1 a"
38 echo "100644 blob $o0 b"
39 echo "100644 blob $o0 c"
40 echo "100644 blob $o1 d/e"
44 echo "100644 $o1 0 d/e"
46 test_cmp expected actual
49 test_expect_success
'setup 2' '
53 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
55 echo "100644 blob $o0 a"
56 echo "100644 blob $o0 b"
57 echo "100644 blob $o0 c"
58 echo "100644 blob $o0 d/e"
62 echo "100644 $o0 0 d/e"
64 test_cmp expected actual &&
67 o2=$(git hash-object a) &&
72 git commit -m "side modifies a" &&
73 c2=$(git rev-parse --verify HEAD) &&
74 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
76 echo "100644 blob $o2 a"
77 echo "100644 blob $o0 b"
78 echo "100644 blob $o0 c"
79 echo "100644 blob $o0 d/e"
83 echo "100644 $o0 0 d/e"
85 test_cmp expected actual
88 test_expect_success
'setup 3' '
92 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
94 echo "100644 blob $o0 a"
95 echo "100644 blob $o0 b"
96 echo "100644 blob $o0 c"
97 echo "100644 blob $o0 d/e"
100 echo "100644 $o0 0 c"
101 echo "100644 $o0 0 d/e"
103 test_cmp expected actual &&
105 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
106 o3=$(git hash-object b/c) &&
109 git commit -m "df-1 makes b/c" &&
110 c3=$(git rev-parse --verify HEAD) &&
111 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
113 echo "100644 blob $o0 a"
114 echo "100644 blob $o3 b/c"
115 echo "100644 blob $o0 c"
116 echo "100644 blob $o0 d/e"
117 echo "100644 $o0 0 a"
118 echo "100644 $o3 0 b/c"
119 echo "100644 $o0 0 c"
120 echo "100644 $o0 0 d/e"
122 test_cmp expected actual
125 test_expect_success
'setup 4' '
129 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
131 echo "100644 blob $o0 a"
132 echo "100644 blob $o0 b"
133 echo "100644 blob $o0 c"
134 echo "100644 blob $o0 d/e"
135 echo "100644 $o0 0 a"
136 echo "100644 $o0 0 b"
137 echo "100644 $o0 0 c"
138 echo "100644 $o0 0 d/e"
140 test_cmp expected actual &&
142 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
143 o4=$(git hash-object a/c) &&
146 git commit -m "df-2 makes a/c" &&
147 c4=$(git rev-parse --verify HEAD) &&
148 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
150 echo "100644 blob $o4 a/c"
151 echo "100644 blob $o0 b"
152 echo "100644 blob $o0 c"
153 echo "100644 blob $o0 d/e"
154 echo "100644 $o4 0 a/c"
155 echo "100644 $o0 0 b"
156 echo "100644 $o0 0 c"
157 echo "100644 $o0 0 d/e"
159 test_cmp expected actual
162 test_expect_success
'setup 5' '
165 git checkout remove &&
166 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
168 echo "100644 blob $o0 a"
169 echo "100644 blob $o0 b"
170 echo "100644 blob $o0 c"
171 echo "100644 blob $o0 d/e"
172 echo "100644 $o0 0 a"
173 echo "100644 $o0 0 b"
174 echo "100644 $o0 0 c"
175 echo "100644 $o0 0 d/e"
177 test_cmp expected actual &&
180 echo remove-conflict >a &&
184 o5=$(git hash-object a) &&
187 git commit -m "remove removes b and modifies a" &&
188 c5=$(git rev-parse --verify HEAD) &&
189 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
191 echo "100644 blob $o5 a"
192 echo "100644 blob $o0 c"
193 echo "100644 blob $o0 d/e"
194 echo "100644 $o5 0 a"
195 echo "100644 $o0 0 c"
196 echo "100644 $o0 0 d/e"
198 test_cmp expected actual
202 test_expect_success
'setup 6' '
206 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
208 echo "100644 blob $o0 a"
209 echo "100644 blob $o0 b"
210 echo "100644 blob $o0 c"
211 echo "100644 blob $o0 d/e"
212 echo "100644 $o0 0 a"
213 echo "100644 $o0 0 b"
214 echo "100644 $o0 0 c"
215 echo "100644 $o0 0 d/e"
217 test_cmp expected actual &&
219 rm -fr d && echo df-3 >d && git add d &&
220 o6=$(git hash-object d) &&
223 git commit -m "df-3 makes d" &&
224 c6=$(git rev-parse --verify HEAD) &&
225 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
227 echo "100644 blob $o0 a"
228 echo "100644 blob $o0 b"
229 echo "100644 blob $o0 c"
230 echo "100644 blob $o6 d"
231 echo "100644 $o0 0 a"
232 echo "100644 $o0 0 b"
233 echo "100644 $o0 0 c"
234 echo "100644 $o6 0 d"
236 test_cmp expected actual
239 test_expect_success
'merge-recursive simple' '
242 git checkout -f "$c2" &&
244 git merge-recursive "$c0" -- "$c2" "$c1"
251 echo >&2 "why status $status!!!"
257 test_expect_success
'merge-recursive result' '
259 git ls-files -s >actual &&
261 echo "100644 $o0 1 a"
262 echo "100644 $o2 2 a"
263 echo "100644 $o1 3 a"
264 echo "100644 $o0 0 b"
265 echo "100644 $o0 0 c"
266 echo "100644 $o1 0 d/e"
268 test_cmp expected actual
272 test_expect_success
'fail if the index has unresolved entries' '
275 git checkout -f "$c1" &&
277 test_must_fail git merge "$c5" &&
278 test_must_fail git merge "$c5" 2> out &&
279 grep "You have not concluded your merge" out &&
280 rm -f .git/MERGE_HEAD &&
281 test_must_fail git merge "$c5" 2> out &&
282 grep "You are in the middle of a conflicted merge" out
286 test_expect_success
'merge-recursive remove conflict' '
289 git checkout -f "$c1" &&
291 git merge-recursive "$c0" -- "$c1" "$c5"
298 echo >&2 "why status $status!!!"
304 test_expect_success
'merge-recursive remove conflict' '
306 git ls-files -s >actual &&
308 echo "100644 $o0 1 a"
309 echo "100644 $o1 2 a"
310 echo "100644 $o5 3 a"
311 echo "100644 $o0 0 c"
312 echo "100644 $o1 0 d/e"
314 test_cmp expected actual
318 test_expect_success
'merge-recursive d/f simple' '
321 git checkout -f "$c1" &&
323 git merge-recursive "$c0" -- "$c1" "$c3"
326 test_expect_success
'merge-recursive result' '
328 git ls-files -s >actual &&
330 echo "100644 $o1 0 a"
331 echo "100644 $o3 0 b/c"
332 echo "100644 $o0 0 c"
333 echo "100644 $o1 0 d/e"
335 test_cmp expected actual
339 test_expect_success
'merge-recursive d/f conflict' '
343 git checkout -f "$c1" &&
345 git merge-recursive "$c0" -- "$c1" "$c4"
352 echo >&2 "why status $status!!!"
358 test_expect_success
'merge-recursive d/f conflict result' '
360 git ls-files -s >actual &&
362 echo "100644 $o0 1 a"
363 echo "100644 $o1 2 a"
364 echo "100644 $o4 0 a/c"
365 echo "100644 $o0 0 b"
366 echo "100644 $o0 0 c"
367 echo "100644 $o1 0 d/e"
369 test_cmp expected actual
373 test_expect_success
'merge-recursive d/f conflict the other way' '
377 git checkout -f "$c4" &&
379 git merge-recursive "$c0" -- "$c4" "$c1"
386 echo >&2 "why status $status!!!"
392 test_expect_success
'merge-recursive d/f conflict result the other way' '
394 git ls-files -s >actual &&
396 echo "100644 $o0 1 a"
397 echo "100644 $o1 3 a"
398 echo "100644 $o4 0 a/c"
399 echo "100644 $o0 0 b"
400 echo "100644 $o0 0 c"
401 echo "100644 $o1 0 d/e"
403 test_cmp expected actual
407 test_expect_success
'merge-recursive d/f conflict' '
411 git checkout -f "$c1" &&
413 git merge-recursive "$c0" -- "$c1" "$c6"
420 echo >&2 "why status $status!!!"
426 test_expect_success
'merge-recursive d/f conflict result' '
428 git ls-files -s >actual &&
430 echo "100644 $o1 0 a"
431 echo "100644 $o0 0 b"
432 echo "100644 $o0 0 c"
433 echo "100644 $o6 3 d"
434 echo "100644 $o0 1 d/e"
435 echo "100644 $o1 2 d/e"
437 test_cmp expected actual
441 test_expect_success
'merge-recursive d/f conflict' '
445 git checkout -f "$c6" &&
447 git merge-recursive "$c0" -- "$c6" "$c1"
454 echo >&2 "why status $status!!!"
460 test_expect_success
'merge-recursive d/f conflict result' '
462 git ls-files -s >actual &&
464 echo "100644 $o1 0 a"
465 echo "100644 $o0 0 b"
466 echo "100644 $o0 0 c"
467 echo "100644 $o6 2 d"
468 echo "100644 $o0 1 d/e"
469 echo "100644 $o1 3 d/e"
471 test_cmp expected actual
475 test_expect_success
'reset and 3-way merge' '
477 git reset --hard "$c2" &&
478 git read-tree -m "$c0" "$c2" "$c1"
482 test_expect_success
'reset and bind merge' '
484 git reset --hard master &&
485 git read-tree --prefix=M/ master &&
486 git ls-files -s >actual &&
488 echo "100644 $o1 0 M/a"
489 echo "100644 $o0 0 M/b"
490 echo "100644 $o0 0 M/c"
491 echo "100644 $o1 0 M/d/e"
492 echo "100644 $o1 0 a"
493 echo "100644 $o0 0 b"
494 echo "100644 $o0 0 c"
495 echo "100644 $o1 0 d/e"
497 test_cmp expected actual &&
499 git read-tree --prefix=a1/ 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 $o1 0 a1/a"
508 echo "100644 $o0 0 a1/b"
509 echo "100644 $o0 0 a1/c"
510 echo "100644 $o1 0 a1/d/e"
511 echo "100644 $o0 0 b"
512 echo "100644 $o0 0 c"
513 echo "100644 $o1 0 d/e"
515 test_cmp expected actual
517 git read-tree --prefix=z/ 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 $o1 0 a1/a"
526 echo "100644 $o0 0 a1/b"
527 echo "100644 $o0 0 a1/c"
528 echo "100644 $o1 0 a1/d/e"
529 echo "100644 $o0 0 b"
530 echo "100644 $o0 0 c"
531 echo "100644 $o1 0 d/e"
532 echo "100644 $o1 0 z/a"
533 echo "100644 $o0 0 z/b"
534 echo "100644 $o0 0 z/c"
535 echo "100644 $o1 0 z/d/e"
537 test_cmp expected actual
541 test_expect_success
'merge removes empty directories' '
543 git reset --hard master &&
544 git checkout -b rm &&
546 git commit -mremoved-d/e &&
547 git checkout master &&
548 git merge -s recursive rm &&
549 test_must_fail test -d d