t4129: don't fail if setgid is set in the test directory
[git] / t / t6430-merge-recursive.sh
1 #!/bin/sh
2
3 test_description='merge-recursive backend test'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-merge.sh
7
8 test_expect_success 'setup 1' '
9
10         echo hello >a &&
11         o0=$(git hash-object a) &&
12         cp a b &&
13         cp a c &&
14         mkdir d &&
15         cp a d/e &&
16
17         test_tick &&
18         git add a b c d/e &&
19         git commit -m initial &&
20         c0=$(git rev-parse --verify HEAD) &&
21         git branch side &&
22         git branch df-1 &&
23         git branch df-2 &&
24         git branch df-3 &&
25         git branch remove &&
26         git branch submod &&
27         git branch copy &&
28         git branch rename &&
29         git branch rename-ln &&
30
31         echo hello >>a &&
32         cp a d/e &&
33         o1=$(git hash-object a) &&
34
35         git add a d/e &&
36
37         test_tick &&
38         git commit -m "master modifies a and d/e" &&
39         c1=$(git rev-parse --verify HEAD) &&
40         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
41         (
42                 echo "100644 blob $o1   a" &&
43                 echo "100644 blob $o0   b" &&
44                 echo "100644 blob $o0   c" &&
45                 echo "100644 blob $o1   d/e" &&
46                 echo "100644 $o1 0      a" &&
47                 echo "100644 $o0 0      b" &&
48                 echo "100644 $o0 0      c" &&
49                 echo "100644 $o1 0      d/e"
50         ) >expected &&
51         test_cmp expected actual
52 '
53
54 test_expect_success 'setup 2' '
55
56         rm -rf [abcd] &&
57         git checkout side &&
58         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
59         (
60                 echo "100644 blob $o0   a" &&
61                 echo "100644 blob $o0   b" &&
62                 echo "100644 blob $o0   c" &&
63                 echo "100644 blob $o0   d/e" &&
64                 echo "100644 $o0 0      a" &&
65                 echo "100644 $o0 0      b" &&
66                 echo "100644 $o0 0      c" &&
67                 echo "100644 $o0 0      d/e"
68         ) >expected &&
69         test_cmp expected actual &&
70
71         echo goodbye >>a &&
72         o2=$(git hash-object a) &&
73
74         git add a &&
75
76         test_tick &&
77         git commit -m "side modifies a" &&
78         c2=$(git rev-parse --verify HEAD) &&
79         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
80         (
81                 echo "100644 blob $o2   a" &&
82                 echo "100644 blob $o0   b" &&
83                 echo "100644 blob $o0   c" &&
84                 echo "100644 blob $o0   d/e" &&
85                 echo "100644 $o2 0      a" &&
86                 echo "100644 $o0 0      b" &&
87                 echo "100644 $o0 0      c" &&
88                 echo "100644 $o0 0      d/e"
89         ) >expected &&
90         test_cmp expected actual
91 '
92
93 test_expect_success 'setup 3' '
94
95         rm -rf [abcd] &&
96         git checkout df-1 &&
97         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
98         (
99                 echo "100644 blob $o0   a" &&
100                 echo "100644 blob $o0   b" &&
101                 echo "100644 blob $o0   c" &&
102                 echo "100644 blob $o0   d/e" &&
103                 echo "100644 $o0 0      a" &&
104                 echo "100644 $o0 0      b" &&
105                 echo "100644 $o0 0      c" &&
106                 echo "100644 $o0 0      d/e"
107         ) >expected &&
108         test_cmp expected actual &&
109
110         rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
111         o3=$(git hash-object b/c) &&
112
113         test_tick &&
114         git commit -m "df-1 makes b/c" &&
115         c3=$(git rev-parse --verify HEAD) &&
116         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
117         (
118                 echo "100644 blob $o0   a" &&
119                 echo "100644 blob $o3   b/c" &&
120                 echo "100644 blob $o0   c" &&
121                 echo "100644 blob $o0   d/e" &&
122                 echo "100644 $o0 0      a" &&
123                 echo "100644 $o3 0      b/c" &&
124                 echo "100644 $o0 0      c" &&
125                 echo "100644 $o0 0      d/e"
126         ) >expected &&
127         test_cmp expected actual
128 '
129
130 test_expect_success 'setup 4' '
131
132         rm -rf [abcd] &&
133         git checkout df-2 &&
134         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
135         (
136                 echo "100644 blob $o0   a" &&
137                 echo "100644 blob $o0   b" &&
138                 echo "100644 blob $o0   c" &&
139                 echo "100644 blob $o0   d/e" &&
140                 echo "100644 $o0 0      a" &&
141                 echo "100644 $o0 0      b" &&
142                 echo "100644 $o0 0      c" &&
143                 echo "100644 $o0 0      d/e"
144         ) >expected &&
145         test_cmp expected actual &&
146
147         rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
148         o4=$(git hash-object a/c) &&
149
150         test_tick &&
151         git commit -m "df-2 makes a/c" &&
152         c4=$(git rev-parse --verify HEAD) &&
153         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
154         (
155                 echo "100644 blob $o4   a/c" &&
156                 echo "100644 blob $o0   b" &&
157                 echo "100644 blob $o0   c" &&
158                 echo "100644 blob $o0   d/e" &&
159                 echo "100644 $o4 0      a/c" &&
160                 echo "100644 $o0 0      b" &&
161                 echo "100644 $o0 0      c" &&
162                 echo "100644 $o0 0      d/e"
163         ) >expected &&
164         test_cmp expected actual
165 '
166
167 test_expect_success 'setup 5' '
168
169         rm -rf [abcd] &&
170         git checkout remove &&
171         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
172         (
173                 echo "100644 blob $o0   a" &&
174                 echo "100644 blob $o0   b" &&
175                 echo "100644 blob $o0   c" &&
176                 echo "100644 blob $o0   d/e" &&
177                 echo "100644 $o0 0      a" &&
178                 echo "100644 $o0 0      b" &&
179                 echo "100644 $o0 0      c" &&
180                 echo "100644 $o0 0      d/e"
181         ) >expected &&
182         test_cmp expected actual &&
183
184         rm -f b &&
185         echo remove-conflict >a &&
186
187         git add a &&
188         git rm b &&
189         o5=$(git hash-object a) &&
190
191         test_tick &&
192         git commit -m "remove removes b and modifies a" &&
193         c5=$(git rev-parse --verify HEAD) &&
194         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
195         (
196                 echo "100644 blob $o5   a" &&
197                 echo "100644 blob $o0   c" &&
198                 echo "100644 blob $o0   d/e" &&
199                 echo "100644 $o5 0      a" &&
200                 echo "100644 $o0 0      c" &&
201                 echo "100644 $o0 0      d/e"
202         ) >expected &&
203         test_cmp expected actual
204
205 '
206
207 test_expect_success 'setup 6' '
208
209         rm -rf [abcd] &&
210         git checkout df-3 &&
211         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
212         (
213                 echo "100644 blob $o0   a" &&
214                 echo "100644 blob $o0   b" &&
215                 echo "100644 blob $o0   c" &&
216                 echo "100644 blob $o0   d/e" &&
217                 echo "100644 $o0 0      a" &&
218                 echo "100644 $o0 0      b" &&
219                 echo "100644 $o0 0      c" &&
220                 echo "100644 $o0 0      d/e"
221         ) >expected &&
222         test_cmp expected actual &&
223
224         rm -fr d && echo df-3 >d && git add d &&
225         o6=$(git hash-object d) &&
226
227         test_tick &&
228         git commit -m "df-3 makes d" &&
229         c6=$(git rev-parse --verify HEAD) &&
230         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
231         (
232                 echo "100644 blob $o0   a" &&
233                 echo "100644 blob $o0   b" &&
234                 echo "100644 blob $o0   c" &&
235                 echo "100644 blob $o6   d" &&
236                 echo "100644 $o0 0      a" &&
237                 echo "100644 $o0 0      b" &&
238                 echo "100644 $o0 0      c" &&
239                 echo "100644 $o6 0      d"
240         ) >expected &&
241         test_cmp expected actual
242 '
243
244 test_expect_success 'setup 7' '
245
246         git checkout submod &&
247         git rm d/e &&
248         test_tick &&
249         git commit -m "remove d/e" &&
250         git update-index --add --cacheinfo 160000 $c1 d &&
251         test_tick &&
252         git commit -m "make d/ a submodule"
253 '
254
255 test_expect_success 'setup 8' '
256         git checkout rename &&
257         git mv a e &&
258         git add e &&
259         test_tick &&
260         git commit -m "rename a->e" &&
261         c7=$(git rev-parse --verify HEAD) &&
262         git checkout rename-ln &&
263         git mv a e &&
264         test_ln_s_add e a &&
265         test_tick &&
266         git commit -m "rename a->e, symlink a->e" &&
267         oln=$(printf e | git hash-object --stdin)
268 '
269
270 test_expect_success 'setup 9' '
271         git checkout copy &&
272         cp a e &&
273         git add e &&
274         test_tick &&
275         git commit -m "copy a->e"
276 '
277
278 test_expect_success 'merge-recursive simple' '
279
280         rm -fr [abcd] &&
281         git checkout -f "$c2" &&
282
283         test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1"
284 '
285
286 test_expect_success 'merge-recursive result' '
287
288         git ls-files -s >actual &&
289         (
290                 echo "100644 $o0 1      a" &&
291                 echo "100644 $o2 2      a" &&
292                 echo "100644 $o1 3      a" &&
293                 echo "100644 $o0 0      b" &&
294                 echo "100644 $o0 0      c" &&
295                 echo "100644 $o1 0      d/e"
296         ) >expected &&
297         test_cmp expected actual
298
299 '
300
301 test_expect_success 'fail if the index has unresolved entries' '
302
303         rm -fr [abcd] &&
304         git checkout -f "$c1" &&
305
306         test_must_fail git merge "$c5" &&
307         test_must_fail git merge "$c5" 2> out &&
308         test_i18ngrep "not possible because you have unmerged files" out &&
309         git add -u &&
310         test_must_fail git merge "$c5" 2> out &&
311         test_i18ngrep "You have not concluded your merge" out &&
312         rm -f .git/MERGE_HEAD &&
313         test_must_fail git merge "$c5" 2> out &&
314         test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
315 '
316
317 test_expect_success 'merge-recursive remove conflict' '
318
319         rm -fr [abcd] &&
320         git checkout -f "$c1" &&
321
322         test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5"
323 '
324
325 test_expect_success 'merge-recursive remove conflict' '
326
327         git ls-files -s >actual &&
328         (
329                 echo "100644 $o0 1      a" &&
330                 echo "100644 $o1 2      a" &&
331                 echo "100644 $o5 3      a" &&
332                 echo "100644 $o0 0      c" &&
333                 echo "100644 $o1 0      d/e"
334         ) >expected &&
335         test_cmp expected actual
336
337 '
338
339 test_expect_success 'merge-recursive d/f simple' '
340         rm -fr [abcd] &&
341         git reset --hard &&
342         git checkout -f "$c1" &&
343
344         git merge-recursive "$c0" -- "$c1" "$c3"
345 '
346
347 test_expect_success 'merge-recursive result' '
348
349         git ls-files -s >actual &&
350         (
351                 echo "100644 $o1 0      a" &&
352                 echo "100644 $o3 0      b/c" &&
353                 echo "100644 $o0 0      c" &&
354                 echo "100644 $o1 0      d/e"
355         ) >expected &&
356         test_cmp expected actual
357
358 '
359
360 test_expect_success 'merge-recursive d/f conflict' '
361
362         rm -fr [abcd] &&
363         git reset --hard &&
364         git checkout -f "$c1" &&
365
366         test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4"
367 '
368
369 test_expect_success 'merge-recursive d/f conflict result' '
370
371         git ls-files -s >actual &&
372         (
373                 echo "100644 $o0 1      a" &&
374                 echo "100644 $o1 2      a" &&
375                 echo "100644 $o4 0      a/c" &&
376                 echo "100644 $o0 0      b" &&
377                 echo "100644 $o0 0      c" &&
378                 echo "100644 $o1 0      d/e"
379         ) >expected &&
380         test_cmp expected actual
381
382 '
383
384 test_expect_success 'merge-recursive d/f conflict the other way' '
385
386         rm -fr [abcd] &&
387         git reset --hard &&
388         git checkout -f "$c4" &&
389
390         test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1"
391 '
392
393 test_expect_success 'merge-recursive d/f conflict result the other way' '
394
395         git ls-files -s >actual &&
396         (
397                 echo "100644 $o0 1      a" &&
398                 echo "100644 $o1 3      a" &&
399                 echo "100644 $o4 0      a/c" &&
400                 echo "100644 $o0 0      b" &&
401                 echo "100644 $o0 0      c" &&
402                 echo "100644 $o1 0      d/e"
403         ) >expected &&
404         test_cmp expected actual
405
406 '
407
408 test_expect_success 'merge-recursive d/f conflict' '
409
410         rm -fr [abcd] &&
411         git reset --hard &&
412         git checkout -f "$c1" &&
413
414         test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6"
415 '
416
417 test_expect_success 'merge-recursive d/f conflict result' '
418
419         git ls-files -s >actual &&
420         (
421                 echo "100644 $o1 0      a" &&
422                 echo "100644 $o0 0      b" &&
423                 echo "100644 $o0 0      c" &&
424                 echo "100644 $o6 3      d" &&
425                 echo "100644 $o0 1      d/e" &&
426                 echo "100644 $o1 2      d/e"
427         ) >expected &&
428         test_cmp expected actual
429
430 '
431
432 test_expect_success 'merge-recursive d/f conflict' '
433
434         rm -fr [abcd] &&
435         git reset --hard &&
436         git checkout -f "$c6" &&
437
438         test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1"
439 '
440
441 test_expect_success 'merge-recursive d/f conflict result' '
442
443         git ls-files -s >actual &&
444         (
445                 echo "100644 $o1 0      a" &&
446                 echo "100644 $o0 0      b" &&
447                 echo "100644 $o0 0      c" &&
448                 echo "100644 $o6 2      d" &&
449                 echo "100644 $o0 1      d/e" &&
450                 echo "100644 $o1 3      d/e"
451         ) >expected &&
452         test_cmp expected actual
453
454 '
455
456 test_expect_success SYMLINKS 'dir in working tree with symlink ancestor does not produce d/f conflict' '
457         git init sym &&
458         (
459                 cd sym &&
460                 ln -s . foo &&
461                 mkdir bar &&
462                 >bar/file &&
463                 git add foo bar/file &&
464                 git commit -m "foo symlink" &&
465
466                 git checkout -b branch1 &&
467                 git commit --allow-empty -m "empty commit" &&
468
469                 git checkout master &&
470                 git rm foo &&
471                 mkdir foo &&
472                 >foo/bar &&
473                 git add foo/bar &&
474                 git commit -m "replace foo symlink with real foo dir and foo/bar file" &&
475
476                 git checkout branch1 &&
477
478                 git cherry-pick master &&
479                 test_path_is_dir foo &&
480                 test_path_is_file foo/bar
481         )
482 '
483
484 test_expect_success 'reset and 3-way merge' '
485
486         git reset --hard "$c2" &&
487         git read-tree -m "$c0" "$c2" "$c1"
488
489 '
490
491 test_expect_success 'reset and bind merge' '
492
493         git reset --hard master &&
494         git read-tree --prefix=M/ master &&
495         git ls-files -s >actual &&
496         (
497                 echo "100644 $o1 0      M/a" &&
498                 echo "100644 $o0 0      M/b" &&
499                 echo "100644 $o0 0      M/c" &&
500                 echo "100644 $o1 0      M/d/e" &&
501                 echo "100644 $o1 0      a" &&
502                 echo "100644 $o0 0      b" &&
503                 echo "100644 $o0 0      c" &&
504                 echo "100644 $o1 0      d/e"
505         ) >expected &&
506         test_cmp expected actual &&
507
508         git read-tree --prefix=a1/ master &&
509         git ls-files -s >actual &&
510         (
511                 echo "100644 $o1 0      M/a" &&
512                 echo "100644 $o0 0      M/b" &&
513                 echo "100644 $o0 0      M/c" &&
514                 echo "100644 $o1 0      M/d/e" &&
515                 echo "100644 $o1 0      a" &&
516                 echo "100644 $o1 0      a1/a" &&
517                 echo "100644 $o0 0      a1/b" &&
518                 echo "100644 $o0 0      a1/c" &&
519                 echo "100644 $o1 0      a1/d/e" &&
520                 echo "100644 $o0 0      b" &&
521                 echo "100644 $o0 0      c" &&
522                 echo "100644 $o1 0      d/e"
523         ) >expected &&
524         test_cmp expected actual &&
525
526         git read-tree --prefix=z/ master &&
527         git ls-files -s >actual &&
528         (
529                 echo "100644 $o1 0      M/a" &&
530                 echo "100644 $o0 0      M/b" &&
531                 echo "100644 $o0 0      M/c" &&
532                 echo "100644 $o1 0      M/d/e" &&
533                 echo "100644 $o1 0      a" &&
534                 echo "100644 $o1 0      a1/a" &&
535                 echo "100644 $o0 0      a1/b" &&
536                 echo "100644 $o0 0      a1/c" &&
537                 echo "100644 $o1 0      a1/d/e" &&
538                 echo "100644 $o0 0      b" &&
539                 echo "100644 $o0 0      c" &&
540                 echo "100644 $o1 0      d/e" &&
541                 echo "100644 $o1 0      z/a" &&
542                 echo "100644 $o0 0      z/b" &&
543                 echo "100644 $o0 0      z/c" &&
544                 echo "100644 $o1 0      z/d/e"
545         ) >expected &&
546         test_cmp expected actual
547
548 '
549
550 test_expect_success 'merge-recursive w/ empty work tree - ours has rename' '
551         (
552                 GIT_WORK_TREE="$PWD/ours-has-rename-work" &&
553                 export GIT_WORK_TREE &&
554                 GIT_INDEX_FILE="$PWD/ours-has-rename-index" &&
555                 export GIT_INDEX_FILE &&
556                 mkdir "$GIT_WORK_TREE" &&
557                 git read-tree -i -m $c7 2>actual-err &&
558                 test_must_be_empty actual-err &&
559                 git update-index --ignore-missing --refresh 2>actual-err &&
560                 test_must_be_empty actual-err &&
561                 git merge-recursive $c0 -- $c7 $c3 2>actual-err &&
562                 test_must_be_empty actual-err &&
563                 git ls-files -s >actual-files 2>actual-err &&
564                 test_must_be_empty actual-err
565         ) &&
566         cat >expected-files <<-EOF &&
567         100644 $o3 0    b/c
568         100644 $o0 0    c
569         100644 $o0 0    d/e
570         100644 $o0 0    e
571         EOF
572         test_cmp expected-files actual-files
573 '
574
575 test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' '
576         (
577                 GIT_WORK_TREE="$PWD/theirs-has-rename-work" &&
578                 export GIT_WORK_TREE &&
579                 GIT_INDEX_FILE="$PWD/theirs-has-rename-index" &&
580                 export GIT_INDEX_FILE &&
581                 mkdir "$GIT_WORK_TREE" &&
582                 git read-tree -i -m $c3 2>actual-err &&
583                 test_must_be_empty actual-err &&
584                 git update-index --ignore-missing --refresh 2>actual-err &&
585                 test_must_be_empty actual-err &&
586                 git merge-recursive $c0 -- $c3 $c7 2>actual-err &&
587                 test_must_be_empty actual-err &&
588                 git ls-files -s >actual-files 2>actual-err &&
589                 test_must_be_empty actual-err
590         ) &&
591         cat >expected-files <<-EOF &&
592         100644 $o3 0    b/c
593         100644 $o0 0    c
594         100644 $o0 0    d/e
595         100644 $o0 0    e
596         EOF
597         test_cmp expected-files actual-files
598 '
599
600 test_expect_success 'merge removes empty directories' '
601
602         git reset --hard master &&
603         git checkout -b rm &&
604         git rm d/e &&
605         git commit -mremoved-d/e &&
606         git checkout master &&
607         git merge -s recursive rm &&
608         test_path_is_missing d
609 '
610
611 test_expect_success 'merge-recursive simple w/submodule' '
612
613         git checkout submod &&
614         git merge remove
615 '
616
617 test_expect_success 'merge-recursive simple w/submodule result' '
618
619         git ls-files -s >actual &&
620         (
621                 echo "100644 $o5 0      a" &&
622                 echo "100644 $o0 0      c" &&
623                 echo "160000 $c1 0      d"
624         ) >expected &&
625         test_cmp expected actual
626 '
627
628 test_expect_success 'merge-recursive copy vs. rename' '
629         git checkout -f copy &&
630         git merge rename &&
631         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
632         (
633                 echo "100644 blob $o0   b" &&
634                 echo "100644 blob $o0   c" &&
635                 echo "100644 blob $o0   d/e" &&
636                 echo "100644 blob $o0   e" &&
637                 echo "100644 $o0 0      b" &&
638                 echo "100644 $o0 0      c" &&
639                 echo "100644 $o0 0      d/e" &&
640                 echo "100644 $o0 0      e"
641         ) >expected &&
642         test_cmp expected actual
643 '
644
645 test_expect_merge_algorithm failure success 'merge-recursive rename vs. rename/symlink' '
646
647         git checkout -f rename &&
648         git merge rename-ln &&
649         ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
650         (
651                 echo "120000 blob $oln  a" &&
652                 echo "100644 blob $o0   b" &&
653                 echo "100644 blob $o0   c" &&
654                 echo "100644 blob $o0   d/e" &&
655                 echo "100644 blob $o0   e" &&
656                 echo "120000 $oln 0     a" &&
657                 echo "100644 $o0 0      b" &&
658                 echo "100644 $o0 0      c" &&
659                 echo "100644 $o0 0      d/e" &&
660                 echo "100644 $o0 0      e"
661         ) >expected &&
662         test_cmp expected actual
663 '
664
665 test_expect_success 'merging with triple rename across D/F conflict' '
666         git reset --hard HEAD &&
667         git checkout -b topic &&
668         git rm -rf . &&
669
670         echo "just a file" >sub1 &&
671         mkdir -p sub2 &&
672         echo content1 >sub2/file1 &&
673         echo content2 >sub2/file2 &&
674         echo content3 >sub2/file3 &&
675         mkdir simple &&
676         echo base >simple/bar &&
677         git add -A &&
678         test_tick &&
679         git commit -m base &&
680
681         git checkout -b other &&
682         echo more >>simple/bar &&
683         test_tick &&
684         git commit -a -m changesimplefile &&
685
686         git checkout topic &&
687         git rm sub1 &&
688         git mv sub2 sub1 &&
689         test_tick &&
690         git commit -m changefiletodir &&
691
692         test_tick &&
693         git merge other
694 '
695
696 test_expect_success 'merge-recursive remembers the names of all base trees' '
697         git reset --hard HEAD &&
698
699         # make the index match $c1 so that merge-recursive below does not
700         # fail early
701         git diff --binary HEAD $c1 -- | git apply --cached &&
702
703         # more trees than static slots used by oid_to_hex()
704         for commit in $c0 $c2 $c4 $c5 $c6 $c7
705         do
706                 git rev-parse "$commit^{tree}"
707         done >trees &&
708
709         # ignore the return code; it only fails because the input is weird...
710         test_must_fail git -c merge.verbosity=5 merge-recursive $(cat trees) -- $c1 $c3 >out &&
711
712         # ...but make sure it fails in the expected way
713         test_i18ngrep CONFLICT.*rename/rename out &&
714
715         # merge-recursive prints in reverse order, but we do not care
716         sort <trees >expect &&
717         sed -n "s/^virtual //p" out | sort >actual &&
718         test_cmp expect actual
719 '
720
721 test_expect_success 'merge-recursive internal merge resolves to the sameness' '
722         git reset --hard HEAD &&
723
724         # We are going to create a history leading to two criss-cross
725         # branches A and B.  The common ancestor at the bottom, O0,
726         # has two child commits O1 and O2, both of which will be merge
727         # base between A and B, like so:
728         #
729         #       O1---A
730         #      /  \ /
731         #    O0    .
732         #      \  / \
733         #       O2---B
734         #
735         # The recently added "check to see if the index is different from
736         # the tree into which something else is getting merged" check must
737         # NOT kick in when an inner merge between O1 and O2 is made.  Both
738         # O1 and O2 happen to have the same tree as O0 in this test to
739         # trigger the bug---whether the inner merge is made by merging O2
740         # into O1 or O1 into O2, their common ancestor O0 and the branch
741         # being merged have the same tree.  We should not trigger the "is
742         # the index dirty?" check in this case.
743
744         echo "zero" >file &&
745         git add file &&
746         test_tick &&
747         git commit -m "O0" &&
748         O0=$(git rev-parse HEAD) &&
749
750         test_tick &&
751         git commit --allow-empty -m "O1" &&
752         O1=$(git rev-parse HEAD) &&
753
754         git reset --hard $O0 &&
755         test_tick &&
756         git commit --allow-empty -m "O2" &&
757         O2=$(git rev-parse HEAD) &&
758
759         test_tick &&
760         git merge -s ours $O1 &&
761         B=$(git rev-parse HEAD) &&
762
763         git reset --hard $O1 &&
764         test_tick &&
765         git merge -s ours $O2 &&
766         A=$(git rev-parse HEAD) &&
767
768         git merge $B
769 '
770
771 test_done