3 test_description='recursive merge corner cases involving criss-cross merges'
17 test_expect_success 'setup basic criss-cross + rename with no modifications' '
18 test_create_repo basic-rename &&
22 ten="0 1 2 3 4 5 6 7 8 9" &&
25 echo line $i in a sample file
29 echo line $i in another sample file
32 test_tick && git commit -m initial &&
37 test_tick && git commit -m R1 &&
41 test_tick && git commit -m L1 &&
44 test_tick && git merge -s ours R1 &&
48 test_tick && git merge -s ours L1 &&
53 test_expect_success 'merge simple rename+criss-cross with no modifications' '
60 test_must_fail git merge -s recursive R2^0 &&
62 git ls-files -s >out &&
63 test_line_count = 2 out &&
64 git ls-files -u >out &&
65 test_line_count = 2 out &&
66 git ls-files -o >out &&
67 test_line_count = 1 out &&
69 git rev-parse >expect \
71 git rev-parse >actual \
73 test_cmp expect actual
78 # Same as before, but modify L1 slightly:
89 test_expect_success 'setup criss-cross + rename merges with basic modification' '
90 test_create_repo rename-modify &&
94 ten="0 1 2 3 4 5 6 7 8 9" &&
97 echo line $i in a sample file
101 echo line $i in another sample file
104 test_tick && git commit -m initial &&
107 git checkout -b R1 &&
111 test_tick && git commit -m R1 &&
115 test_tick && git commit -m L1 &&
118 test_tick && git merge -s ours R1 &&
122 test_tick && git merge -s ours L1 &&
127 test_expect_success 'merge criss-cross + rename merges with basic modification' '
133 test_must_fail git merge -s recursive R2^0 &&
135 git ls-files -s >out &&
136 test_line_count = 2 out &&
137 git ls-files -u >out &&
138 test_line_count = 2 out &&
139 git ls-files -o >out &&
140 test_line_count = 1 out &&
142 git rev-parse >expect \
144 git rev-parse >actual \
146 test_cmp expect actual
151 # For the next test, we start with three commits in two lines of development
152 # which setup a rename/add conflict:
153 # Commit A: File 'a' exists
154 # Commit B: Rename 'a' -> 'new_a'
155 # Commit C: Modify 'a', create different 'new_a'
156 # Later, two different people merge and resolve differently:
157 # Commit D: Merge B & C, ignoring separately created 'new_a'
158 # Commit E: Merge B & C making use of some piece of secondary 'new_a'
159 # Finally, someone goes to merge D & E. Does git detect the conflict?
170 test_expect_success 'setup differently handled merges of rename/add conflict' '
171 test_create_repo rename-add &&
175 printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
177 test_tick && git commit -m A &&
182 test_write_lines 0 1 2 3 4 5 6 7 foobar >new_a &&
184 test_tick && git commit -m C &&
188 test_tick && git commit -m B &&
191 test_must_fail git merge C &&
192 git show :2:new_a >new_a &&
194 test_tick && git commit -m D &&
198 test_must_fail git merge B &&
199 test_write_lines 0 1 2 3 4 5 6 7 bad_merge >new_a &&
201 test_tick && git commit -m E &&
206 test_expect_success 'git detects differently handled merges conflict' '
212 test_must_fail git merge -s recursive E^0 &&
214 git ls-files -s >out &&
215 test_line_count = 3 out &&
216 git ls-files -u >out &&
217 test_line_count = 3 out &&
218 git ls-files -o >out &&
219 test_line_count = 1 out &&
221 git rev-parse >expect \
222 C:new_a D:new_a E:new_a &&
223 git rev-parse >actual \
224 :1:new_a :2:new_a :3:new_a &&
225 test_cmp expect actual &&
227 # Test that the two-way merge in new_a is as expected
228 git cat-file -p D:new_a >ours &&
229 git cat-file -p E:new_a >theirs &&
231 test_must_fail git merge-file \
236 sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
237 git hash-object new_a >actual &&
238 git hash-object ours >expect &&
239 test_cmp expect actual
243 # Repeat the above testcase with precisely the same setup, other than with
244 # the two merge bases having different orderings of commit timestamps so
245 # that they are reversed in the order they are provided to merge-recursive,
246 # so that we can improve code coverage.
247 test_expect_success 'git detects differently handled merges conflict, swapped' '
251 # Difference #1: Do cleanup from previous testrun
255 # Difference #2: Change commit timestamps
256 btime=$(git log --no-walk --date=raw --format=%cd B | awk "{print \$1}") &&
257 ctime=$(git log --no-walk --date=raw --format=%cd C | awk "{print \$1}") &&
258 newctime=$(($btime+1)) &&
259 git fast-export --no-data --all | sed -e s/$ctime/$newctime/ | git fast-import --force --quiet &&
260 # End of differences; rest is copy-paste of last test
263 test_must_fail git merge -s recursive E^0 &&
265 git ls-files -s >out &&
266 test_line_count = 3 out &&
267 git ls-files -u >out &&
268 test_line_count = 3 out &&
269 git ls-files -o >out &&
270 test_line_count = 1 out &&
272 git rev-parse >expect \
273 C:new_a D:new_a E:new_a &&
274 git rev-parse >actual \
275 :1:new_a :2:new_a :3:new_a &&
276 test_cmp expect actual &&
278 # Test that the two-way merge in new_a is as expected
279 git cat-file -p D:new_a >ours &&
280 git cat-file -p E:new_a >theirs &&
282 test_must_fail git merge-file \
287 sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
288 git hash-object new_a >actual &&
289 git hash-object ours >expect &&
290 test_cmp expect actual
295 # criss-cross + modify/delete:
305 # Commit A: file with contents 'A\n'
306 # Commit B: file with contents 'B\n'
307 # Commit C: file not present
308 # Commit D: file with contents 'B\n'
309 # Commit E: file not present
311 # Merging commits D & E should result in modify/delete conflict.
313 test_expect_success 'setup criss-cross + modify/delete resolved differently' '
314 test_create_repo modify-delete &&
336 test_must_fail git merge C &&
344 test_must_fail git merge B &&
352 test_expect_success 'git detects conflict merging criss-cross+modify/delete' '
358 test_must_fail git merge -s recursive E^0 &&
360 git ls-files -s >out &&
361 test_line_count = 2 out &&
362 git ls-files -u >out &&
363 test_line_count = 2 out &&
365 git rev-parse >expect \
366 master:file B:file &&
367 git rev-parse >actual \
369 test_cmp expect actual
373 test_expect_success 'git detects conflict merging criss-cross+modify/delete, reverse direction' '
380 test_must_fail git merge -s recursive D^0 &&
382 git ls-files -s >out &&
383 test_line_count = 2 out &&
384 git ls-files -u >out &&
385 test_line_count = 2 out &&
387 git rev-parse >expect \
388 master:file B:file &&
389 git rev-parse >actual \
391 test_cmp expect actual
395 # SORRY FOR THE SUPER LONG DESCRIPTION, BUT THIS NEXT ONE IS HAIRY
397 # criss-cross + d/f conflict via add/add:
398 # Commit A: Neither file 'a' nor directory 'a/' exists.
399 # Commit B: Introduce 'a'
400 # Commit C: Introduce 'a/file'
401 # Commit D1: Merge B & C, keeping 'a' and deleting 'a/'
402 # Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
412 # I'll describe D2, E2, & E3 (which are alternatives for D1 & E1) more below...
414 # Merging D1 & E1 requires we first create a virtual merge base X from
415 # merging A & B in memory. There are several possibilities for the merge-base:
416 # 1: Keep both 'a' and 'a/file' (assuming crazy filesystem allowing a tree
417 # with a directory and file at same path): results in merge of D1 & E1
418 # being clean with both files deleted. Bad (no conflict detected).
419 # 2: Keep 'a' but not 'a/file': Merging D1 & E1 is clean and matches E1. Bad.
420 # 3: Keep 'a/file' but not 'a': Merging D1 & E1 is clean and matches D1. Bad.
421 # 4: Keep neither file: Merging D1 & E1 reports the D/F add/add conflict.
423 # So 4 sounds good for this case, but if we were to merge D1 & E3, where E3
425 # Commit E3: Merge B & C, keeping modified a, and deleting a/
426 # then we'd get an add/add conflict for 'a', which seems suboptimal. A little
427 # creativity leads us to an alternate choice:
428 # 5: Keep 'a' as 'a~$UNIQUE' and a/file; results:
429 # Merge D1 & E1: rename/delete conflict for 'a'; a/file silently deleted
430 # Merge D1 & E3 is clean, as expected.
432 # So choice 5 at least provides some kind of conflict for the original case,
433 # and can merge cleanly as expected with D1 and E3. It also made things just
434 # slightly funny for merging D1 and e$, where E4 is defined as:
435 # Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
436 # in this case, we'll get a rename/rename(1to2) conflict because a~$UNIQUE
437 # gets renamed to 'a' in D1 and to 'a2' in E4. But that's better than having
438 # two files (both 'a' and 'a2') sitting around without the user being notified
439 # that we could detect they were related and need to be merged. Also, choice
440 # 5 makes the handling of 'a/file' seem suboptimal. What if we were to merge
441 # D2 and E4, where D2 is:
442 # Commit D2: Merge B & C, renaming 'a'->'a2', keeping 'a/file'
443 # This would result in a clean merge with 'a2' having three-way merged
444 # contents (good), and deleting 'a/' (bad) -- it doesn't detect the
445 # conflict in how the different sides treated a/file differently.
446 # Continuing down the creative route:
447 # 6: Keep 'a' as 'a~$UNIQUE1' and keep 'a/' as 'a~$UNIQUE2/'; results:
448 # Merge D1 & E1: rename/delete conflict for 'a' and each path under 'a/'.
449 # Merge D1 & E3: clean, as expected.
450 # Merge D1 & E4: rename/rename(1to2) conflict on 'a' vs 'a2'.
451 # Merge D2 & E4: clean for 'a2', rename/delete for a/file
453 # Choice 6 could cause rename detection to take longer (providing more targets
454 # that need to be searched). Also, the conflict message for each path under
455 # 'a/' might be annoying unless we can detect it at the directory level, print
456 # it once, and then suppress it for individual filepaths underneath.
459 # As of time of writing, git uses choice 5. Directory rename detection and
460 # rename detection performance improvements might make choice 6 a desirable
461 # improvement. But we can at least document where we fall short for now...
464 # Historically, this testcase also used:
465 # Commit E2: Merge B & C, deleting 'a' but keeping slightly modified 'a/file'
466 # The merge of D1 & E2 is very similar to D1 & E1 -- it has similar issues for
467 # path 'a', but should always result in a modify/delete conflict for path
468 # 'a/file'. These tests ran the two merges
471 # in both directions, to check for directional issues with D/F conflict
472 # handling. Later we added
476 # for good measure, though we only ran those one way because we had pretty
477 # good confidence in merge-recursive's directional handling of D/F issues.
479 # Just to summarize all the intermediate merge commits:
480 # Commit D1: Merge B & C, keeping a and deleting a/
481 # Commit D2: Merge B & C, renaming a->a2, keeping a/file
482 # Commit E1: Merge B & C, deleting a but keeping a/file
483 # Commit E2: Merge B & C, deleting a but keeping slightly modified a/file
484 # Commit E3: Merge B & C, keeping modified a, and deleting a/
485 # Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
488 test_expect_success 'setup differently handled merges of directory/file conflict' '
489 test_create_repo directory-file &&
502 test_write_lines a b c d e f g >a/file &&
508 test_write_lines 1 2 3 4 5 6 7 >a &&
514 git merge -s ours -m D1 C^0 &&
518 test_must_fail git merge C^0 &&
522 git cat-file -p B:a >a2 &&
528 git merge -s ours -m E1 B^0 &&
532 git merge -s ours -m E2 B^0 &&
533 test_write_lines a b c d e f g h >a/file &&
535 git commit --amend -C HEAD &&
539 test_must_fail git merge B^0 &&
542 test_write_lines 1 2 3 4 5 6 7 8 >a &&
548 test_must_fail git merge B^0 &&
552 test_write_lines 1 2 3 4 5 6 7 8 >a2 &&
559 test_expect_success 'merge of D1 & E1 fails but has appropriate contents' '
560 test_when_finished "git -C directory-file reset --hard" &&
561 test_when_finished "git -C directory-file clean -fdqx" &&
567 test_must_fail git merge -s recursive E1^0 &&
569 git ls-files -s >out &&
570 test_line_count = 2 out &&
571 git ls-files -u >out &&
572 test_line_count = 1 out &&
573 git ls-files -o >out &&
574 test_line_count = 1 out &&
576 git rev-parse >expect \
578 git rev-parse >actual \
580 test_cmp expect actual
584 test_expect_success 'merge of E1 & D1 fails but has appropriate contents' '
585 test_when_finished "git -C directory-file reset --hard" &&
586 test_when_finished "git -C directory-file clean -fdqx" &&
592 test_must_fail git merge -s recursive D1^0 &&
594 git ls-files -s >out &&
595 test_line_count = 2 out &&
596 git ls-files -u >out &&
597 test_line_count = 1 out &&
598 git ls-files -o >out &&
599 test_line_count = 1 out &&
601 git rev-parse >expect \
603 git rev-parse >actual \
605 test_cmp expect actual
609 test_expect_success 'merge of D1 & E2 fails but has appropriate contents' '
610 test_when_finished "git -C directory-file reset --hard" &&
611 test_when_finished "git -C directory-file clean -fdqx" &&
617 test_must_fail git merge -s recursive E2^0 &&
619 git ls-files -s >out &&
620 test_line_count = 4 out &&
621 git ls-files -u >out &&
622 test_line_count = 3 out &&
623 git ls-files -o >out &&
624 test_line_count = 2 out &&
626 git rev-parse >expect \
627 B:a E2:a/file C:a/file A:ignore-me &&
628 git rev-parse >actual \
629 :2:a :3:a/file :1:a/file :0:ignore-me &&
630 test_cmp expect actual &&
632 test_path_is_file a~HEAD
636 test_expect_success 'merge of E2 & D1 fails but has appropriate contents' '
637 test_when_finished "git -C directory-file reset --hard" &&
638 test_when_finished "git -C directory-file clean -fdqx" &&
644 test_must_fail git merge -s recursive D1^0 &&
646 git ls-files -s >out &&
647 test_line_count = 4 out &&
648 git ls-files -u >out &&
649 test_line_count = 3 out &&
650 git ls-files -o >out &&
651 test_line_count = 2 out &&
653 git rev-parse >expect \
654 B:a E2:a/file C:a/file A:ignore-me &&
655 git rev-parse >actual \
656 :3:a :2:a/file :1:a/file :0:ignore-me &&
657 test_cmp expect actual &&
659 test_path_is_file a~D1^0
663 test_expect_success 'merge of D1 & E3 succeeds' '
664 test_when_finished "git -C directory-file reset --hard" &&
665 test_when_finished "git -C directory-file clean -fdqx" &&
671 git merge -s recursive E3^0 &&
673 git ls-files -s >out &&
674 test_line_count = 2 out &&
675 git ls-files -u >out &&
676 test_line_count = 0 out &&
677 git ls-files -o >out &&
678 test_line_count = 1 out &&
680 git rev-parse >expect \
682 git rev-parse >actual \
684 test_cmp expect actual
688 test_expect_success 'merge of D1 & E4 notifies user a and a2 are related' '
689 test_when_finished "git -C directory-file reset --hard" &&
690 test_when_finished "git -C directory-file clean -fdqx" &&
696 test_must_fail git merge -s recursive E4^0 &&
698 git ls-files -s >out &&
699 test_line_count = 4 out &&
700 git ls-files -u >out &&
701 test_line_count = 3 out &&
702 git ls-files -o >out &&
703 test_line_count = 1 out &&
705 git rev-parse >expect \
706 A:ignore-me B:a D1:a E4:a2 &&
707 git rev-parse >actual \
708 :0:ignore-me :1:a~Temporary\ merge\ branch\ 2 :2:a :3:a2 &&
709 test_cmp expect actual
713 test_expect_failure 'merge of D2 & E4 merges a2s & reports conflict for a/file' '
714 test_when_finished "git -C directory-file reset --hard" &&
715 test_when_finished "git -C directory-file clean -fdqx" &&
721 test_must_fail git merge -s recursive E4^0 &&
723 git ls-files -s >out &&
724 test_line_count = 3 out &&
725 git ls-files -u >out &&
726 test_line_count = 1 out &&
727 git ls-files -o >out &&
728 test_line_count = 1 out &&
730 git rev-parse >expect \
731 A:ignore-me E4:a2 D2:a/file &&
732 git rev-parse >actual \
733 :0:ignore-me :0:a2 :2:a/file &&
734 test_cmp expect actual
739 # criss-cross with rename/rename(1to2)/modify followed by
740 # rename/rename(2to1)/modify:
750 # Commit A: new file: a
751 # Commit B: rename a->b, modifying by adding a line
752 # Commit C: rename a->c
753 # Commit D: merge B&C, resolving conflict by keeping contents in newname
754 # Commit E: merge B&C, resolving conflict similar to D but adding another line
756 # There is a conflict merging B & C, but one of filename not of file
757 # content. Whoever created D and E chose specific resolutions for that
758 # conflict resolution. Now, since: (1) there is no content conflict
759 # merging B & C, (2) D does not modify that merged content further, and (3)
760 # both D & E resolve the name conflict in the same way, the modification to
761 # newname in E should not cause any conflicts when it is merged with D.
762 # (Note that this can be accomplished by having the virtual merge base have
763 # the merged contents of b and c stored in a file named a, which seems like
764 # the most logical choice anyway.)
766 # Comment from Junio: I do not necessarily agree with the choice "a", but
767 # it feels sound to say "B and C do not agree what the final pathname
768 # should be, but we know this content was derived from the common A:a so we
769 # use one path whose name is arbitrary in the virtual merge base X between
770 # D and E" and then further let the rename detection to notice that that
771 # arbitrary path gets renamed between X-D to "newname" and X-E also to
772 # "newname" to resolve it as both sides renaming it to the same new
773 # name. It is akin to what we do at the content level, i.e. "B and C do not
774 # agree what the final contents should be, so we leave the conflict marker
775 # but that may cancel out at the final merge stage".
777 test_expect_success 'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
778 test_create_repo rename-squared-squared &&
780 cd rename-squared-squared &&
782 printf "1\n2\n3\n4\n5\n6\n" >a &&
787 git checkout -b B A &&
793 git checkout -b C A &&
797 git checkout -q B^0 &&
798 git merge --no-commit -s ours C^0 &&
800 git commit -m "Merge commit C^0 into HEAD" &&
803 git checkout -q C^0 &&
804 git merge --no-commit -s ours B^0 &&
806 printf "7\n8\n" >>newname &&
808 git commit -m "Merge commit B^0 into HEAD" &&
813 test_expect_success 'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
815 cd rename-squared-squared &&
819 git merge -s recursive E^0 &&
821 git ls-files -s >out &&
822 test_line_count = 1 out &&
823 git ls-files -u >out &&
824 test_line_count = 0 out &&
825 git ls-files -o >out &&
826 test_line_count = 1 out &&
828 test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
833 # criss-cross with rename/rename(1to2)/add-source + resolvable modify/modify:
843 # Commit A: new file: a
844 # Commit B: rename a->b
845 # Commit C: rename a->c, add different a
846 # Commit D: merge B&C, keeping b&c and (new) a modified at beginning
847 # Commit E: merge B&C, keeping b&c and (new) a modified at end
849 # Merging commits D & E should result in no conflict; doing so correctly
850 # requires getting the virtual merge base (from merging B&C) right, handling
851 # renaming carefully (both in the virtual merge base and later), and getting
852 # content merge handled.
854 test_expect_success 'setup criss-cross + rename/rename/add-source + modify/modify' '
855 test_create_repo rename-rename-add-source &&
857 cd rename-rename-add-source &&
859 printf "lots\nof\nwords\nand\ncontent\n" >a &&
864 git checkout -b B A &&
868 git checkout -b C A &&
870 printf "2\n3\n4\n5\n6\n7\n" >a &&
875 git merge --no-commit -s ours C^0 &&
876 git checkout C -- a c &&
882 git commit -m "Merge commit C^0 into HEAD" &&
886 git merge --no-commit -s ours B^0 &&
887 git checkout B -- b &&
890 git commit -m "Merge commit B^0 into HEAD" &&
895 test_expect_failure 'detect rename/rename/add-source for virtual merge-base' '
897 cd rename-rename-add-source &&
901 git merge -s recursive E^0 &&
903 git ls-files -s >out &&
904 test_line_count = 3 out &&
905 git ls-files -u >out &&
906 test_line_count = 0 out &&
907 git ls-files -o >out &&
908 test_line_count = 1 out &&
910 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >correct &&
911 git rev-parse >expect \
914 git rev-parse >actual \
916 git hash-object >>actual \
918 test_cmp expect actual
923 # criss-cross with rename/rename(1to2)/add-dest + simple modify:
933 # Commit A: new file: a
934 # Commit B: rename a->b, add c
935 # Commit C: rename a->c
936 # Commit D: merge B&C, keeping A:a and B:c
937 # Commit E: merge B&C, keeping A:a and slightly modified c from B
939 # Merging commits D & E should result in no conflict. The virtual merge
940 # base of B & C needs to not delete B:c for that to work, though...
942 test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' '
943 test_create_repo rename-rename-add-dest &&
945 cd rename-rename-add-dest &&
952 git checkout -b B A &&
954 printf "1\n2\n3\n4\n5\n6\n7\n" >c &&
958 git checkout -b C A &&
963 git merge --no-commit -s ours C^0 &&
965 git commit -m "D is like B but renames b back to a" &&
969 git merge --no-commit -s ours C^0 &&
973 git commit -m "E like D but has mod in c" &&
978 test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
980 cd rename-rename-add-dest &&
984 git merge -s recursive E^0 &&
986 git ls-files -s >out &&
987 test_line_count = 2 out &&
988 git ls-files -u >out &&
989 test_line_count = 0 out &&
990 git ls-files -o >out &&
991 test_line_count = 1 out &&
993 git rev-parse >expect \
995 git rev-parse >actual \
997 test_cmp expect actual
1002 # criss-cross with modify/modify on a symlink:
1012 # Commit A: simple simlink fickle->lagoon
1013 # Commit B: redirect fickle->disneyland
1014 # Commit C: redirect fickle->home
1015 # Commit D: merge B&C, resolving in favor of B
1016 # Commit E: merge B&C, resolving in favor of C
1018 # This is an obvious modify/modify conflict for the symlink 'fickle'. Can
1021 test_expect_success 'setup symlink modify/modify' '
1022 test_create_repo symlink-modify-modify &&
1024 cd symlink-modify-modify &&
1026 test_ln_s_add lagoon fickle &&
1030 git checkout -b B A &&
1032 test_ln_s_add disneyland fickle &&
1035 git checkout -b C A &&
1037 test_ln_s_add home fickle &&
1041 git checkout -q B^0 &&
1042 git merge -s ours -m D C^0 &&
1045 git checkout -q C^0 &&
1046 git merge -s ours -m E B^0 &&
1051 test_expect_failure 'check symlink modify/modify' '
1053 cd symlink-modify-modify &&
1057 test_must_fail git merge -s recursive E^0 &&
1059 git ls-files -s >out &&
1060 test_line_count = 3 out &&
1061 git ls-files -u >out &&
1062 test_line_count = 3 out &&
1063 git ls-files -o >out &&
1064 test_line_count = 1 out
1069 # criss-cross with add/add of a symlink:
1079 # Commit A: No symlink or path exists yet
1080 # Commit B: set up symlink: fickle->disneyland
1081 # Commit C: set up symlink: fickle->home
1082 # Commit D: merge B&C, resolving in favor of B
1083 # Commit E: merge B&C, resolving in favor of C
1085 # This is an obvious add/add conflict for the symlink 'fickle'. Can
1088 test_expect_success 'setup symlink add/add' '
1089 test_create_repo symlink-add-add &&
1091 cd symlink-add-add &&
1098 git checkout -b B A &&
1099 test_ln_s_add disneyland fickle &&
1102 git checkout -b C A &&
1103 test_ln_s_add home fickle &&
1107 git checkout -q B^0 &&
1108 git merge -s ours -m D C^0 &&
1111 git checkout -q C^0 &&
1112 git merge -s ours -m E B^0 &&
1117 test_expect_failure 'check symlink add/add' '
1119 cd symlink-add-add &&
1123 test_must_fail git merge -s recursive E^0 &&
1125 git ls-files -s >out &&
1126 test_line_count = 2 out &&
1127 git ls-files -u >out &&
1128 test_line_count = 2 out &&
1129 git ls-files -o >out &&
1130 test_line_count = 1 out
1135 # criss-cross with modify/modify on a submodule:
1145 # Commit A: simple submodule repo
1146 # Commit B: update repo
1147 # Commit C: update repo differently
1148 # Commit D: merge B&C, resolving in favor of B
1149 # Commit E: merge B&C, resolving in favor of C
1151 # This is an obvious modify/modify conflict for the submodule 'repo'. Can
1154 test_expect_success 'setup submodule modify/modify' '
1155 test_create_repo submodule-modify-modify &&
1157 cd submodule-modify-modify &&
1159 test_create_repo submod &&
1167 git checkout -b B A &&
1173 git checkout -b C A &&
1180 git -C submod reset --hard A &&
1185 git checkout -b B A &&
1186 git -C submod reset --hard B &&
1190 git checkout -b C A &&
1191 git -C submod reset --hard C &&
1195 git checkout -q B^0 &&
1196 git merge -s ours -m D C^0 &&
1199 git checkout -q C^0 &&
1200 git merge -s ours -m E B^0 &&
1205 test_expect_failure 'check submodule modify/modify' '
1207 cd submodule-modify-modify &&
1211 test_must_fail git merge -s recursive E^0 &&
1213 git ls-files -s >out &&
1214 test_line_count = 3 out &&
1215 git ls-files -u >out &&
1216 test_line_count = 3 out &&
1217 git ls-files -o >out &&
1218 test_line_count = 1 out
1223 # criss-cross with add/add on a submodule:
1233 # Commit A: nothing of note
1234 # Commit B: introduce submodule repo
1235 # Commit C: introduce submodule repo at different commit
1236 # Commit D: merge B&C, resolving in favor of B
1237 # Commit E: merge B&C, resolving in favor of C
1239 # This is an obvious add/add conflict for the submodule 'repo'. Can
1242 test_expect_success 'setup submodule add/add' '
1243 test_create_repo submodule-add-add &&
1245 cd submodule-add-add &&
1247 test_create_repo submod &&
1255 git checkout -b B A &&
1261 git checkout -b C A &&
1268 touch irrelevant-file &&
1269 git add irrelevant-file &&
1273 git checkout -b B A &&
1274 git -C submod reset --hard B &&
1278 git checkout -b C A &&
1279 git -C submod reset --hard C &&
1283 git checkout -q B^0 &&
1284 git merge -s ours -m D C^0 &&
1287 git checkout -q C^0 &&
1288 git merge -s ours -m E B^0 &&
1293 test_expect_failure 'check submodule add/add' '
1295 cd submodule-add-add &&
1299 test_must_fail git merge -s recursive E^0 &&
1301 git ls-files -s >out &&
1302 test_line_count = 3 out &&
1303 git ls-files -u >out &&
1304 test_line_count = 2 out &&
1305 git ls-files -o >out &&
1306 test_line_count = 1 out
1311 # criss-cross with conflicting entry types:
1321 # Commit A: nothing of note
1322 # Commit B: introduce submodule 'path'
1323 # Commit C: introduce symlink 'path'
1324 # Commit D: merge B&C, resolving in favor of B
1325 # Commit E: merge B&C, resolving in favor of C
1327 # This is an obvious add/add conflict for 'path'. Can git detect it?
1329 test_expect_success 'setup conflicting entry types (submodule vs symlink)' '
1330 test_create_repo submodule-symlink-add-add &&
1332 cd submodule-symlink-add-add &&
1334 test_create_repo path &&
1343 touch irrelevant-file &&
1344 git add irrelevant-file &&
1348 git checkout -b B A &&
1349 git -C path reset --hard B &&
1353 git checkout -b C A &&
1355 test_ln_s_add irrelevant-file path &&
1358 git checkout -q B^0 &&
1359 git merge -s ours -m D C^0 &&
1362 git checkout -q C^0 &&
1363 git merge -s ours -m E B^0 &&
1368 test_expect_failure 'check conflicting entry types (submodule vs symlink)' '
1370 cd submodule-symlink-add-add &&
1374 test_must_fail git merge -s recursive E^0 &&
1376 git ls-files -s >out &&
1377 test_line_count = 3 out &&
1378 git ls-files -u >out &&
1379 test_line_count = 2 out &&
1380 git ls-files -o >out &&
1381 test_line_count = 1 out
1386 # criss-cross with regular files that have conflicting modes:
1396 # Commit A: nothing of note
1397 # Commit B: introduce file source_me.bash, not executable
1398 # Commit C: introduce file source_me.bash, executable
1399 # Commit D: merge B&C, resolving in favor of B
1400 # Commit E: merge B&C, resolving in favor of C
1402 # This is an obvious add/add mode conflict. Can git detect it?
1404 test_expect_success 'setup conflicting modes for regular file' '
1405 test_create_repo regular-file-mode-conflict &&
1407 cd regular-file-mode-conflict &&
1409 touch irrelevant-file &&
1410 git add irrelevant-file &&
1414 git checkout -b B A &&
1415 echo "command_to_run" >source_me.bash &&
1416 git add source_me.bash &&
1419 git checkout -b C A &&
1420 echo "command_to_run" >source_me.bash &&
1421 git add source_me.bash &&
1422 test_chmod +x source_me.bash &&
1425 git checkout -q B^0 &&
1426 git merge -s ours -m D C^0 &&
1429 git checkout -q C^0 &&
1430 git merge -s ours -m E B^0 &&
1435 test_expect_failure 'check conflicting modes for regular file' '
1437 cd regular-file-mode-conflict &&
1441 test_must_fail git merge -s recursive E^0 &&
1443 git ls-files -s >out &&
1444 test_line_count = 3 out &&
1445 git ls-files -u >out &&
1446 test_line_count = 2 out &&
1447 git ls-files -o >out &&
1448 test_line_count = 1 out
1460 # master has two files, named 'b' and 'a'
1461 # branches L1 and R1 both modify each of the two files in conflicting ways
1463 # L2 is a merge of R1 into L1; more on it later.
1464 # R2 is a merge of L1 into R1; more on it later.
1466 # X is an auto-generated merge-base used when merging L2 and R2.
1467 # since X is a merge of L1 and R1, it has conflicting versions of each file
1469 # More about L2 and R2:
1470 # - both resolve the conflicts in 'b' and 'a' differently
1471 # - L2 renames 'b' to 'm'
1472 # - R2 renames 'a' to 'm'
1474 # In the end, in file 'm' we have four different conflicting files (from
1475 # two versions of 'b' and two of 'a'). In addition, if
1476 # merge.conflictstyle is diff3, then the base version also has
1477 # conflict markers of its own, leading to a total of three levels of
1478 # conflict markers. This is a pretty weird corner case, but we just want
1479 # to ensure that we handle it as well as practical.
1481 test_expect_success 'setup nested conflicts' '
1482 test_create_repo nested_conflicts &&
1484 cd nested_conflicts &&
1486 # Create some related files now
1487 for i in $(test_seq 1 10)
1489 echo Random base content line $i
1501 test_write_lines b b_L1 >>b_L1 &&
1502 test_write_lines b b_R1 >>b_R1 &&
1503 test_write_lines b b_L2 >>b_L2 &&
1504 test_write_lines b b_R2 >>b_R2 &&
1505 test_write_lines a a_L1 >>a_L1 &&
1506 test_write_lines a a_R1 >>a_R1 &&
1507 test_write_lines a a_L2 >>a_L2 &&
1508 test_write_lines a a_R2 >>a_R2 &&
1510 # Setup original commit (or merge-base), consisting of
1511 # files named "b" and "a"
1517 test_tick && git commit -m initial &&
1522 # Handle the left side
1527 test_tick && git commit -m "version L1 of files" &&
1530 # Handle the right side
1535 test_tick && git commit -m "version R1 of files" &&
1538 # Create first merge on left side
1540 test_must_fail git merge R1 &&
1545 test_tick && git commit -m "left merge, rename b->m" &&
1548 # Create first merge on right side
1550 test_must_fail git merge L1 &&
1555 test_tick && git commit -m "right merge, rename a->m" &&
1560 test_expect_success 'check nested conflicts' '
1562 cd nested_conflicts &&
1565 MASTER=$(git rev-parse --short master) &&
1566 git checkout L2^0 &&
1568 # Merge must fail; there is a conflict
1569 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R2^0 &&
1571 # Make sure the index has the right number of entries
1572 git ls-files -s >out &&
1573 test_line_count = 2 out &&
1574 git ls-files -u >out &&
1575 test_line_count = 2 out &&
1576 # Ensure we have the correct number of untracked files
1577 git ls-files -o >out &&
1578 test_line_count = 1 out &&
1580 # Create a and b from virtual merge base X
1581 git cat-file -p master:a >base &&
1582 git cat-file -p L1:a >ours &&
1583 git cat-file -p R1:a >theirs &&
1584 test_must_fail git merge-file --diff3 \
1585 -L "Temporary merge branch 1" \
1587 -L "Temporary merge branch 2" \
1591 sed -e "s/^\([<|=>]\)/\1\1/" ours >vmb_a &&
1593 git cat-file -p master:b >base &&
1594 git cat-file -p L1:b >ours &&
1595 git cat-file -p R1:b >theirs &&
1596 test_must_fail git merge-file --diff3 \
1597 -L "Temporary merge branch 1" \
1599 -L "Temporary merge branch 2" \
1603 sed -e "s/^\([<|=>]\)/\1\1/" ours >vmb_b &&
1605 # Compare :2:m to expected values
1606 git cat-file -p L2:m >ours &&
1607 git cat-file -p R2:b >theirs &&
1608 test_must_fail git merge-file --diff3 \
1610 -L "merged common ancestors:b" \
1615 sed -e "s/^\([<|=>]\)/\1\1/" ours >m_stage_2 &&
1616 git cat-file -p :2:m >actual &&
1617 test_cmp m_stage_2 actual &&
1619 # Compare :3:m to expected values
1620 git cat-file -p L2:a >ours &&
1621 git cat-file -p R2:m >theirs &&
1622 test_must_fail git merge-file --diff3 \
1624 -L "merged common ancestors:a" \
1629 sed -e "s/^\([<|=>]\)/\1\1/" ours >m_stage_3 &&
1630 git cat-file -p :3:m >actual &&
1631 test_cmp m_stage_3 actual &&
1633 # Compare m to expected contents
1635 cp m_stage_2 expected_final_m &&
1636 test_must_fail git merge-file --diff3 \
1638 -L "merged common ancestors" \
1643 test_cmp expected_final_m m
1655 # master has one file named 'content'
1656 # branches L1 and R1 both modify each of the two files in conflicting ways
1658 # L<n> (n>1) is a merge of R<n-1> into L<n-1>
1659 # R<n> (n>1) is a merge of L<n-1> into R<n-1>
1660 # L<n> and R<n> resolve the conflicts differently.
1662 # X<n> is an auto-generated merge-base used when merging L<n+1> and R<n+1>.
1663 # By construction, X1 has conflict markers due to conflicting versions.
1664 # X2, due to using merge.conflictstyle=3, has nested conflict markers.
1666 # So, merging R3 into L3 using merge.conflictstyle=3 should show the
1667 # nested conflict markers from X2 in the base version -- that means we
1668 # have three levels of conflict markers. Can we distinguish all three?
1670 test_expect_success 'setup virtual merge base with nested conflicts' '
1671 test_create_repo virtual_merge_base_has_nested_conflicts &&
1673 cd virtual_merge_base_has_nested_conflicts &&
1675 # Create some related files now
1676 for i in $(test_seq 1 10)
1678 echo Random base content line $i
1681 # Setup original commit
1683 test_tick && git commit -m initial &&
1690 echo left >>content &&
1692 test_tick && git commit -m "version L1 of content" &&
1697 echo right >>content &&
1699 test_tick && git commit -m "version R1 of content" &&
1704 test_must_fail git -c merge.conflictstyle=diff3 merge R1 &&
1705 git checkout L1 content &&
1706 test_tick && git commit -m "version L2 of content" &&
1711 test_must_fail git -c merge.conflictstyle=diff3 merge L1 &&
1712 git checkout R1 content &&
1713 test_tick && git commit -m "version R2 of content" &&
1718 test_must_fail git -c merge.conflictstyle=diff3 merge R2 &&
1719 git checkout L1 content &&
1720 test_tick && git commit -m "version L3 of content" &&
1725 test_must_fail git -c merge.conflictstyle=diff3 merge L2 &&
1726 git checkout R1 content &&
1727 test_tick && git commit -m "version R3 of content" &&
1732 test_expect_success 'check virtual merge base with nested conflicts' '
1734 cd virtual_merge_base_has_nested_conflicts &&
1736 MASTER=$(git rev-parse --short master) &&
1737 git checkout L3^0 &&
1739 # Merge must fail; there is a conflict
1740 test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R3^0 &&
1742 # Make sure the index has the right number of entries
1743 git ls-files -s >out &&
1744 test_line_count = 3 out &&
1745 git ls-files -u >out &&
1746 test_line_count = 3 out &&
1747 # Ensure we have the correct number of untracked files
1748 git ls-files -o >out &&
1749 test_line_count = 1 out &&
1751 # Compare :[23]:content to expected values
1752 git rev-parse L1:content R1:content >expect &&
1753 git rev-parse :2:content :3:content >actual &&
1754 test_cmp expect actual &&
1756 # Imitate X1 merge base, except without long enough conflict
1757 # markers because a subsequent sed will modify them. Put
1759 git cat-file -p master:content >base &&
1760 git cat-file -p L:content >left &&
1761 git cat-file -p R:content >right &&
1762 cp left merged-once &&
1763 test_must_fail git merge-file --diff3 \
1764 -L "Temporary merge branch 1" \
1766 -L "Temporary merge branch 2" \
1770 sed -e "s/^\([<|=>]\)/\1\1\1/" merged-once >vmb &&
1772 # Imitate X2 merge base, overwriting vmb. Note that we
1773 # extend both sets of conflict markers to make them longer
1774 # with the sed command.
1775 cp left merged-twice &&
1776 test_must_fail git merge-file --diff3 \
1777 -L "Temporary merge branch 1" \
1778 -L "merged common ancestors" \
1779 -L "Temporary merge branch 2" \
1783 sed -e "s/^\([<|=>]\)/\1\1\1/" merged-twice >vmb &&
1785 # Compare :1:content to expected value
1786 git cat-file -p :1:content >actual &&
1787 test_cmp vmb actual &&
1789 # Determine expected content in final outer merge, compare to
1790 # what the merge generated.
1791 cp -f left expect &&
1792 test_must_fail git merge-file --diff3 \
1793 -L "HEAD" -L "merged common ancestors" -L "R3^0" \
1795 test_cmp expect content