1#!/bin/sh
2
3test_description='merge-recursive backend test'
4
5. ./test-lib.sh
6
7test_expect_success 'setup 1' '
8
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 &&
15
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
27 echo hello >>a &&
28 cp a d/e &&
29 o1=$(git hash-object a) &&
30
31 git add a d/e &&
32
33 test_tick &&
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 &&
37 (
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"
42 echo "100644 $o1 0 a"
43 echo "100644 $o0 0 b"
44 echo "100644 $o0 0 c"
45 echo "100644 $o1 0 d/e"
46 ) >expected &&
47 test_cmp expected actual
48'
49
50test_expect_success 'setup 2' '
51
52 rm -rf [abcd] &&
53 git checkout side &&
54 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
55 (
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"
60 echo "100644 $o0 0 a"
61 echo "100644 $o0 0 b"
62 echo "100644 $o0 0 c"
63 echo "100644 $o0 0 d/e"
64 ) >expected &&
65 test_cmp expected actual &&
66
67 echo goodbye >>a &&
68 o2=$(git hash-object a) &&
69
70 git add a &&
71
72 test_tick &&
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 &&
76 (
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"
81 echo "100644 $o2 0 a"
82 echo "100644 $o0 0 b"
83 echo "100644 $o0 0 c"
84 echo "100644 $o0 0 d/e"
85 ) >expected &&
86 test_cmp expected actual
87'
88
89test_expect_success 'setup 3' '
90
91 rm -rf [abcd] &&
92 git checkout df-1 &&
93 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
94 (
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"
99 echo "100644 $o0 0 a"
100 echo "100644 $o0 0 b"
101 echo "100644 $o0 0 c"
102 echo "100644 $o0 0 d/e"
103 ) >expected &&
104 test_cmp expected actual &&
105
106 rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
107 o3=$(git hash-object b/c) &&
108
109 test_tick &&
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 &&
113 (
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"
122 ) >expected &&
123 test_cmp expected actual
124'
125
126test_expect_success 'setup 4' '
127
128 rm -rf [abcd] &&
129 git checkout df-2 &&
130 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
131 (
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"
140 ) >expected &&
141 test_cmp expected actual &&
142
143 rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
144 o4=$(git hash-object a/c) &&
145
146 test_tick &&
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 &&
150 (
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"
159 ) >expected &&
160 test_cmp expected actual
161'
162
163test_expect_success 'setup 5' '
164
165 rm -rf [abcd] &&
166 git checkout remove &&
167 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
168 (
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"
177 ) >expected &&
178 test_cmp expected actual &&
179
180 rm -f b &&
181 echo remove-conflict >a &&
182
183 git add a &&
184 git rm b &&
185 o5=$(git hash-object a) &&
186
187 test_tick &&
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 &&
191 (
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"
198 ) >expected &&
199 test_cmp expected actual
200
201'
202
203test_expect_success 'setup 6' '
204
205 rm -rf [abcd] &&
206 git checkout df-3 &&
207 ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
208 (
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"
217 ) >expected &&
218 test_cmp expected actual &&
219
220 rm -fr d && echo df-3 >d && git add d &&
221 o6=$(git hash-object d) &&
222
223 test_tick &&
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 &&
227 (
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"
236 ) >expected &&
237 test_cmp expected actual
238'
239
240test_expect_success 'setup 7' '
241
242 git checkout submod &&
243 git rm d/e &&
244 test_tick &&
245 git commit -m "remove d/e" &&
246 git update-index --add --cacheinfo 160000 $c1 d &&
247 test_tick &&
248 git commit -m "make d/ a submodule"
249'
250
251test_expect_success 'merge-recursive simple' '
252
253 rm -fr [abcd] &&
254 git checkout -f "$c2" &&
255
256 git merge-recursive "$c0" -- "$c2" "$c1"
257 status=$?
258 case "$status" in
259 1)
260 : happy
261 ;;
262 *)
263 echo >&2 "why status $status!!!"
264 false
265 ;;
266 esac
267'
268
269test_expect_success 'merge-recursive result' '
270
271 git ls-files -s >actual &&
272 (
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"
279 ) >expected &&
280 test_cmp expected actual
281
282'
283
284test_expect_success 'fail if the index has unresolved entries' '
285
286 rm -fr [abcd] &&
287 git checkout -f "$c1" &&
288
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 &&
292 git add -u &&
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 .* would be overwritten by merge." out
298'
299
300test_expect_success 'merge-recursive remove conflict' '
301
302 rm -fr [abcd] &&
303 git checkout -f "$c1" &&
304
305 git merge-recursive "$c0" -- "$c1" "$c5"
306 status=$?
307 case "$status" in
308 1)
309 : happy
310 ;;
311 *)
312 echo >&2 "why status $status!!!"
313 false
314 ;;
315 esac
316'
317
318test_expect_success 'merge-recursive remove conflict' '
319
320 git ls-files -s >actual &&
321 (
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"
327 ) >expected &&
328 test_cmp expected actual
329
330'
331
332test_expect_success 'merge-recursive d/f simple' '
333 rm -fr [abcd] &&
334 git reset --hard &&
335 git checkout -f "$c1" &&
336
337 git merge-recursive "$c0" -- "$c1" "$c3"
338'
339
340test_expect_success 'merge-recursive result' '
341
342 git ls-files -s >actual &&
343 (
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"
348 ) >expected &&
349 test_cmp expected actual
350
351'
352
353test_expect_success 'merge-recursive d/f conflict' '
354
355 rm -fr [abcd] &&
356 git reset --hard &&
357 git checkout -f "$c1" &&
358
359 git merge-recursive "$c0" -- "$c1" "$c4"
360 status=$?
361 case "$status" in
362 1)
363 : happy
364 ;;
365 *)
366 echo >&2 "why status $status!!!"
367 false
368 ;;
369 esac
370'
371
372test_expect_success 'merge-recursive d/f conflict result' '
373
374 git ls-files -s >actual &&
375 (
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"
382 ) >expected &&
383 test_cmp expected actual
384
385'
386
387test_expect_success 'merge-recursive d/f conflict the other way' '
388
389 rm -fr [abcd] &&
390 git reset --hard &&
391 git checkout -f "$c4" &&
392
393 git merge-recursive "$c0" -- "$c4" "$c1"
394 status=$?
395 case "$status" in
396 1)
397 : happy
398 ;;
399 *)
400 echo >&2 "why status $status!!!"
401 false
402 ;;
403 esac
404'
405
406test_expect_success 'merge-recursive d/f conflict result the other way' '
407
408 git ls-files -s >actual &&
409 (
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"
416 ) >expected &&
417 test_cmp expected actual
418
419'
420
421test_expect_success 'merge-recursive d/f conflict' '
422
423 rm -fr [abcd] &&
424 git reset --hard &&
425 git checkout -f "$c1" &&
426
427 git merge-recursive "$c0" -- "$c1" "$c6"
428 status=$?
429 case "$status" in
430 1)
431 : happy
432 ;;
433 *)
434 echo >&2 "why status $status!!!"
435 false
436 ;;
437 esac
438'
439
440test_expect_success 'merge-recursive d/f conflict result' '
441
442 git ls-files -s >actual &&
443 (
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"
450 ) >expected &&
451 test_cmp expected actual
452
453'
454
455test_expect_success 'merge-recursive d/f conflict' '
456
457 rm -fr [abcd] &&
458 git reset --hard &&
459 git checkout -f "$c6" &&
460
461 git merge-recursive "$c0" -- "$c6" "$c1"
462 status=$?
463 case "$status" in
464 1)
465 : happy
466 ;;
467 *)
468 echo >&2 "why status $status!!!"
469 false
470 ;;
471 esac
472'
473
474test_expect_success 'merge-recursive d/f conflict result' '
475
476 git ls-files -s >actual &&
477 (
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"
484 ) >expected &&
485 test_cmp expected actual
486
487'
488
489test_expect_success 'reset and 3-way merge' '
490
491 git reset --hard "$c2" &&
492 git read-tree -m "$c0" "$c2" "$c1"
493
494'
495
496test_expect_success 'reset and bind merge' '
497
498 git reset --hard master &&
499 git read-tree --prefix=M/ master &&
500 git ls-files -s >actual &&
501 (
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"
510 ) >expected &&
511 test_cmp expected actual &&
512
513 git read-tree --prefix=a1/ master &&
514 git ls-files -s >actual &&
515 (
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"
528 ) >expected &&
529 test_cmp expected actual
530
531 git read-tree --prefix=z/ master &&
532 git ls-files -s >actual &&
533 (
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"
550 ) >expected &&
551 test_cmp expected actual
552
553'
554
555test_expect_success 'merge removes empty directories' '
556
557 git reset --hard master &&
558 git checkout -b rm &&
559 git rm d/e &&
560 git commit -mremoved-d/e &&
561 git checkout master &&
562 git merge -s recursive rm &&
563 test_must_fail test -d d
564'
565
566test_expect_failure 'merge-recursive simple w/submodule' '
567
568 git checkout submod &&
569 git merge remove
570'
571
572test_expect_failure 'merge-recursive simple w/submodule result' '
573
574 git ls-files -s >actual &&
575 (
576 echo "100644 $o5 0 a"
577 echo "100644 $o0 0 c"
578 echo "160000 $c1 0 d"
579 ) >expected &&
580 test_cmp expected actual
581'
582
583test_done