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) &&
29 o1=$(git hash-object a) &&
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"
45 echo "100644 $o1 0 d/e"
47 test_cmp expected actual
50 test_expect_success
'setup 2' '
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"
63 echo "100644 $o0 0 d/e"
65 test_cmp expected actual &&
68 o2=$(git hash-object a) &&
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"
84 echo "100644 $o0 0 d/e"
86 test_cmp expected actual
89 test_expect_success
'setup 3' '
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"
100 echo "100644 $o0 0 b"
101 echo "100644 $o0 0 c"
102 echo "100644 $o0 0 d/e"
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) &&
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"
123 test_cmp expected actual
126 test_expect_success
'setup 4' '
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"
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) &&
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"
160 test_cmp expected actual
163 test_expect_success
'setup 5' '
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"
178 test_cmp expected actual &&
181 echo remove-conflict >a &&
185 o5=$(git hash-object a) &&
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"
199 test_cmp expected actual
203 test_expect_success
'setup 6' '
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"
218 test_cmp expected actual &&
220 rm -fr d && echo df-3 >d && git add d &&
221 o6=$(git hash-object d) &&
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"
237 test_cmp expected actual
240 test_expect_success
'setup 7' '
242 git checkout submod &&
245 git commit -m "remove d/e" &&
246 git update-index --add --cacheinfo 160000 $c1 d &&
248 git commit -m "make d/ a submodule"
251 test_expect_success
'merge-recursive simple' '
254 git checkout -f "$c2" &&
256 git merge-recursive "$c0" -- "$c2" "$c1"
263 echo >&2 "why status $status!!!"
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"
280 test_cmp expected actual
284 test_expect_success
'fail if the index has unresolved entries' '
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 &&
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 the following files would be overwritten by merge:" out
300 test_expect_success
'merge-recursive remove conflict' '
303 git checkout -f "$c1" &&
305 git merge-recursive "$c0" -- "$c1" "$c5"
312 echo >&2 "why status $status!!!"
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"
328 test_cmp expected actual
332 test_expect_success
'merge-recursive d/f simple' '
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"
349 test_cmp expected actual
353 test_expect_success
'merge-recursive d/f conflict' '
357 git checkout -f "$c1" &&
359 git merge-recursive "$c0" -- "$c1" "$c4"
366 echo >&2 "why status $status!!!"
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"
383 test_cmp expected actual
387 test_expect_success
'merge-recursive d/f conflict the other way' '
391 git checkout -f "$c4" &&
393 git merge-recursive "$c0" -- "$c4" "$c1"
400 echo >&2 "why status $status!!!"
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"
417 test_cmp expected actual
421 test_expect_success
'merge-recursive d/f conflict' '
425 git checkout -f "$c1" &&
427 git merge-recursive "$c0" -- "$c1" "$c6"
434 echo >&2 "why status $status!!!"
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"
451 test_cmp expected actual
455 test_expect_success
'merge-recursive d/f conflict' '
459 git checkout -f "$c6" &&
461 git merge-recursive "$c0" -- "$c6" "$c1"
468 echo >&2 "why status $status!!!"
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"
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"
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"
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"
551 test_cmp expected actual
555 test_expect_success
'merge removes empty directories' '
557 git reset --hard master &&
558 git checkout -b rm &&
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 &&
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"
580 test_cmp expected actual