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 = 3 out &&
69 git rev-parse >expect \
72 git rev-parse >actual \
74 git hash-object >>actual \
75 three~HEAD three~R2^0 &&
76 test_cmp expect actual
81 # Same as before, but modify L1 slightly:
92 test_expect_success 'setup criss-cross + rename merges with basic modification' '
93 test_create_repo rename-modify &&
97 ten="0 1 2 3 4 5 6 7 8 9" &&
100 echo line $i in a sample file
104 echo line $i in another sample file
107 test_tick && git commit -m initial &&
110 git checkout -b R1 &&
114 test_tick && git commit -m R1 &&
118 test_tick && git commit -m L1 &&
121 test_tick && git merge -s ours R1 &&
125 test_tick && git merge -s ours L1 &&
130 test_expect_success 'merge criss-cross + rename merges with basic modification' '
136 test_must_fail git merge -s recursive R2^0 &&
138 git ls-files -s >out &&
139 test_line_count = 2 out &&
140 git ls-files -u >out &&
141 test_line_count = 2 out &&
142 git ls-files -o >out &&
143 test_line_count = 3 out &&
145 git rev-parse >expect \
148 git rev-parse >actual \
150 git hash-object >>actual \
151 three~HEAD three~R2^0 &&
152 test_cmp expect actual
157 # For the next test, we start with three commits in two lines of development
158 # which setup a rename/add conflict:
159 # Commit A: File 'a' exists
160 # Commit B: Rename 'a' -> 'new_a'
161 # Commit C: Modify 'a', create different 'new_a'
162 # Later, two different people merge and resolve differently:
163 # Commit D: Merge B & C, ignoring separately created 'new_a'
164 # Commit E: Merge B & C making use of some piece of secondary 'new_a'
165 # Finally, someone goes to merge D & E. Does git detect the conflict?
176 test_expect_success 'setup differently handled merges of rename/add conflict' '
177 test_create_repo rename-add &&
181 printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
183 test_tick && git commit -m A &&
188 echo "other content" >>new_a &&
190 test_tick && git commit -m C &&
194 test_tick && git commit -m B &&
197 test_must_fail git merge C &&
199 test_tick && git commit -m D &&
203 test_must_fail git merge B &&
204 rm new_a~HEAD new_a &&
205 printf "Incorrectly merged content" >>new_a &&
207 test_tick && git commit -m E &&
212 test_expect_success 'git detects differently handled merges conflict' '
218 test_must_fail git merge -s recursive E^0 &&
220 git ls-files -s >out &&
221 test_line_count = 3 out &&
222 git ls-files -u >out &&
223 test_line_count = 3 out &&
224 git ls-files -o >out &&
225 test_line_count = 1 out &&
227 git rev-parse >expect \
229 git rev-parse >actual \
231 test_cmp expect actual &&
233 git cat-file -p C:new_a >ours &&
234 git cat-file -p B:new_a >theirs &&
236 test_must_fail git merge-file \
237 -L "Temporary merge branch 1" \
239 -L "Temporary merge branch 2" \
241 sed -e "s/^\([<=>]\)/\1\1\1/" ours >expect &&
242 git cat-file -p :1:new_a >actual &&
243 test_cmp expect actual
248 # criss-cross + modify/delete:
258 # Commit A: file with contents 'A\n'
259 # Commit B: file with contents 'B\n'
260 # Commit C: file not present
261 # Commit D: file with contents 'B\n'
262 # Commit E: file not present
264 # Merging commits D & E should result in modify/delete conflict.
266 test_expect_success 'setup criss-cross + modify/delete resolved differently' '
267 test_create_repo modify-delete &&
289 test_must_fail git merge C &&
297 test_must_fail git merge B &&
305 test_expect_success 'git detects conflict merging criss-cross+modify/delete' '
311 test_must_fail git merge -s recursive E^0 &&
313 git ls-files -s >out &&
314 test_line_count = 2 out &&
315 git ls-files -u >out &&
316 test_line_count = 2 out &&
318 git rev-parse >expect \
319 master:file B:file &&
320 git rev-parse >actual \
322 test_cmp expect actual
326 test_expect_success 'git detects conflict merging criss-cross+modify/delete, reverse direction' '
333 test_must_fail git merge -s recursive D^0 &&
335 git ls-files -s >out &&
336 test_line_count = 2 out &&
337 git ls-files -u >out &&
338 test_line_count = 2 out &&
340 git rev-parse >expect \
341 master:file B:file &&
342 git rev-parse >actual \
344 test_cmp expect actual
348 # SORRY FOR THE SUPER LONG DESCRIPTION, BUT THIS NEXT ONE IS HAIRY
350 # criss-cross + d/f conflict via add/add:
351 # Commit A: Neither file 'a' nor directory 'a/' exists.
352 # Commit B: Introduce 'a'
353 # Commit C: Introduce 'a/file'
354 # Commit D1: Merge B & C, keeping 'a' and deleting 'a/'
355 # Commit E1: Merge B & C, deleting 'a' but keeping 'a/file'
365 # I'll describe D2, E2, & E3 (which are alternatives for D1 & E1) more below...
367 # Merging D1 & E1 requires we first create a virtual merge base X from
368 # merging A & B in memory. There are several possibilities for the merge-base:
369 # 1: Keep both 'a' and 'a/file' (assuming crazy filesystem allowing a tree
370 # with a directory and file at same path): results in merge of D1 & E1
371 # being clean with both files deleted. Bad (no conflict detected).
372 # 2: Keep 'a' but not 'a/file': Merging D1 & E1 is clean and matches E1. Bad.
373 # 3: Keep 'a/file' but not 'a': Merging D1 & E1 is clean and matches D1. Bad.
374 # 4: Keep neither file: Merging D1 & E1 reports the D/F add/add conflict.
376 # So 4 sounds good for this case, but if we were to merge D1 & E3, where E3
378 # Commit E3: Merge B & C, keeping modified a, and deleting a/
379 # then we'd get an add/add conflict for 'a', which seems suboptimal. A little
380 # creativity leads us to an alternate choice:
381 # 5: Keep 'a' as 'a~$UNIQUE' and a/file; results:
382 # Merge D1 & E1: rename/delete conflict for 'a'; a/file silently deleted
383 # Merge D1 & E3 is clean, as expected.
385 # So choice 5 at least provides some kind of conflict for the original case,
386 # and can merge cleanly as expected with D1 and E3. It also made things just
387 # slightly funny for merging D1 and e$, where E4 is defined as:
388 # Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
389 # in this case, we'll get a rename/rename(1to2) conflict because a~$UNIQUE
390 # gets renamed to 'a' in D1 and to 'a2' in E4. But that's better than having
391 # two files (both 'a' and 'a2') sitting around without the user being notified
392 # that we could detect they were related and need to be merged. Also, choice
393 # 5 makes the handling of 'a/file' seem suboptimal. What if we were to merge
394 # D2 and E4, where D2 is:
395 # Commit D2: Merge B & C, renaming 'a'->'a2', keeping 'a/file'
396 # This would result in a clean merge with 'a2' having three-way merged
397 # contents (good), and deleting 'a/' (bad) -- it doesn't detect the
398 # conflict in how the different sides treated a/file differently.
399 # Continuing down the creative route:
400 # 6: Keep 'a' as 'a~$UNIQUE1' and keep 'a/' as 'a~$UNIQUE2/'; results:
401 # Merge D1 & E1: rename/delete conflict for 'a' and each path under 'a/'.
402 # Merge D1 & E3: clean, as expected.
403 # Merge D1 & E4: rename/rename(1to2) conflict on 'a' vs 'a2'.
404 # Merge D2 & E4: clean for 'a2', rename/delete for a/file
406 # Choice 6 could cause rename detection to take longer (providing more targets
407 # that need to be searched). Also, the conflict message for each path under
408 # 'a/' might be annoying unless we can detect it at the directory level, print
409 # it once, and then suppress it for individual filepaths underneath.
412 # As of time of writing, git uses choice 5. Directory rename detection and
413 # rename detection performance improvements might make choice 6 a desirable
414 # improvement. But we can at least document where we fall short for now...
417 # Historically, this testcase also used:
418 # Commit E2: Merge B & C, deleting 'a' but keeping slightly modified 'a/file'
419 # The merge of D1 & E2 is very similar to D1 & E1 -- it has similar issues for
420 # path 'a', but should always result in a modify/delete conflict for path
421 # 'a/file'. These tests ran the two merges
424 # in both directions, to check for directional issues with D/F conflict
425 # handling. Later we added
429 # for good measure, though we only ran those one way because we had pretty
430 # good confidence in merge-recursive's directional handling of D/F issues.
432 # Just to summarize all the intermediate merge commits:
433 # Commit D1: Merge B & C, keeping a and deleting a/
434 # Commit D2: Merge B & C, renaming a->a2, keeping a/file
435 # Commit E1: Merge B & C, deleting a but keeping a/file
436 # Commit E2: Merge B & C, deleting a but keeping slightly modified a/file
437 # Commit E3: Merge B & C, keeping modified a, and deleting a/
438 # Commit E4: Merge B & C, modifying 'a' and renaming to 'a2', and deleting 'a/'
441 test_expect_success 'setup differently handled merges of directory/file conflict' '
442 test_create_repo directory-file &&
455 test_write_lines a b c d e f g >a/file &&
461 test_write_lines 1 2 3 4 5 6 7 >a &&
467 git merge -s ours -m D1 C^0 &&
471 test_must_fail git merge C^0 &&
475 git cat-file -p B:a >a2 &&
481 git merge -s ours -m E1 B^0 &&
485 git merge -s ours -m E2 B^0 &&
486 test_write_lines a b c d e f g h >a/file &&
488 git commit --amend -C HEAD &&
492 test_must_fail git merge B^0 &&
495 test_write_lines 1 2 3 4 5 6 7 8 >a &&
501 test_must_fail git merge B^0 &&
505 test_write_lines 1 2 3 4 5 6 7 8 >a2 &&
512 test_expect_success 'merge of D1 & E1 fails but has appropriate contents' '
513 test_when_finished "git -C directory-file reset --hard" &&
514 test_when_finished "git -C directory-file clean -fdqx" &&
520 test_must_fail git merge -s recursive E1^0 &&
522 git ls-files -s >out &&
523 test_line_count = 2 out &&
524 git ls-files -u >out &&
525 test_line_count = 1 out &&
526 git ls-files -o >out &&
527 test_line_count = 1 out &&
529 git rev-parse >expect \
531 git rev-parse >actual \
533 test_cmp expect actual
537 test_expect_success 'merge of E1 & D1 fails but has appropriate contents' '
538 test_when_finished "git -C directory-file reset --hard" &&
539 test_when_finished "git -C directory-file clean -fdqx" &&
545 test_must_fail git merge -s recursive D1^0 &&
547 git ls-files -s >out &&
548 test_line_count = 2 out &&
549 git ls-files -u >out &&
550 test_line_count = 1 out &&
551 git ls-files -o >out &&
552 test_line_count = 1 out &&
554 git rev-parse >expect \
556 git rev-parse >actual \
558 test_cmp expect actual
562 test_expect_success 'merge of D1 & E2 fails but has appropriate contents' '
563 test_when_finished "git -C directory-file reset --hard" &&
564 test_when_finished "git -C directory-file clean -fdqx" &&
570 test_must_fail git merge -s recursive E2^0 &&
572 git ls-files -s >out &&
573 test_line_count = 4 out &&
574 git ls-files -u >out &&
575 test_line_count = 3 out &&
576 git ls-files -o >out &&
577 test_line_count = 2 out &&
579 git rev-parse >expect \
580 B:a E2:a/file C:a/file A:ignore-me &&
581 git rev-parse >actual \
582 :2:a :3:a/file :1:a/file :0:ignore-me &&
583 test_cmp expect actual &&
585 test_path_is_file a~HEAD
589 test_expect_success 'merge of E2 & D1 fails but has appropriate contents' '
590 test_when_finished "git -C directory-file reset --hard" &&
591 test_when_finished "git -C directory-file clean -fdqx" &&
597 test_must_fail git merge -s recursive D1^0 &&
599 git ls-files -s >out &&
600 test_line_count = 4 out &&
601 git ls-files -u >out &&
602 test_line_count = 3 out &&
603 git ls-files -o >out &&
604 test_line_count = 2 out &&
606 git rev-parse >expect \
607 B:a E2:a/file C:a/file A:ignore-me &&
608 git rev-parse >actual \
609 :3:a :2:a/file :1:a/file :0:ignore-me &&
610 test_cmp expect actual &&
612 test_path_is_file a~D1^0
616 test_expect_success 'merge of D1 & E3 succeeds' '
617 test_when_finished "git -C directory-file reset --hard" &&
618 test_when_finished "git -C directory-file clean -fdqx" &&
624 git merge -s recursive E3^0 &&
626 git ls-files -s >out &&
627 test_line_count = 2 out &&
628 git ls-files -u >out &&
629 test_line_count = 0 out &&
630 git ls-files -o >out &&
631 test_line_count = 1 out &&
633 git rev-parse >expect \
635 git rev-parse >actual \
637 test_cmp expect actual
641 test_expect_success 'merge of D1 & E4 notifies user a and a2 are related' '
642 test_when_finished "git -C directory-file reset --hard" &&
643 test_when_finished "git -C directory-file clean -fdqx" &&
649 test_must_fail git merge -s recursive E4^0 &&
651 git ls-files -s >out &&
652 test_line_count = 4 out &&
653 git ls-files -u >out &&
654 test_line_count = 3 out &&
655 git ls-files -o >out &&
656 test_line_count = 1 out &&
658 git rev-parse >expect \
659 A:ignore-me B:a D1:a E4:a2 &&
660 git rev-parse >actual \
661 :0:ignore-me :1:a~Temporary\ merge\ branch\ 2 :2:a :3:a2 &&
662 test_cmp expect actual
666 test_expect_failure 'merge of D2 & E4 merges a2s & reports conflict for a/file' '
667 test_when_finished "git -C directory-file reset --hard" &&
668 test_when_finished "git -C directory-file clean -fdqx" &&
674 test_must_fail git merge -s recursive E4^0 &&
676 git ls-files -s >out &&
677 test_line_count = 3 out &&
678 git ls-files -u >out &&
679 test_line_count = 1 out &&
680 git ls-files -o >out &&
681 test_line_count = 1 out &&
683 git rev-parse >expect \
684 A:ignore-me E4:a2 D2:a/file &&
685 git rev-parse >actual \
686 :0:ignore-me :0:a2 :2:a/file &&
687 test_cmp expect actual
692 # criss-cross with rename/rename(1to2)/modify followed by
693 # rename/rename(2to1)/modify:
703 # Commit A: new file: a
704 # Commit B: rename a->b, modifying by adding a line
705 # Commit C: rename a->c
706 # Commit D: merge B&C, resolving conflict by keeping contents in newname
707 # Commit E: merge B&C, resolving conflict similar to D but adding another line
709 # There is a conflict merging B & C, but one of filename not of file
710 # content. Whoever created D and E chose specific resolutions for that
711 # conflict resolution. Now, since: (1) there is no content conflict
712 # merging B & C, (2) D does not modify that merged content further, and (3)
713 # both D & E resolve the name conflict in the same way, the modification to
714 # newname in E should not cause any conflicts when it is merged with D.
715 # (Note that this can be accomplished by having the virtual merge base have
716 # the merged contents of b and c stored in a file named a, which seems like
717 # the most logical choice anyway.)
719 # Comment from Junio: I do not necessarily agree with the choice "a", but
720 # it feels sound to say "B and C do not agree what the final pathname
721 # should be, but we know this content was derived from the common A:a so we
722 # use one path whose name is arbitrary in the virtual merge base X between
723 # D and E" and then further let the rename detection to notice that that
724 # arbitrary path gets renamed between X-D to "newname" and X-E also to
725 # "newname" to resolve it as both sides renaming it to the same new
726 # name. It is akin to what we do at the content level, i.e. "B and C do not
727 # agree what the final contents should be, so we leave the conflict marker
728 # but that may cancel out at the final merge stage".
730 test_expect_success 'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
731 test_create_repo rename-squared-squared &&
733 cd rename-squared-squared &&
735 printf "1\n2\n3\n4\n5\n6\n" >a &&
740 git checkout -b B A &&
746 git checkout -b C A &&
750 git checkout -q B^0 &&
751 git merge --no-commit -s ours C^0 &&
753 git commit -m "Merge commit C^0 into HEAD" &&
756 git checkout -q C^0 &&
757 git merge --no-commit -s ours B^0 &&
759 printf "7\n8\n" >>newname &&
761 git commit -m "Merge commit B^0 into HEAD" &&
766 test_expect_success 'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
768 cd rename-squared-squared &&
772 git merge -s recursive E^0 &&
774 git ls-files -s >out &&
775 test_line_count = 1 out &&
776 git ls-files -u >out &&
777 test_line_count = 0 out &&
778 git ls-files -o >out &&
779 test_line_count = 1 out &&
781 test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
786 # criss-cross with rename/rename(1to2)/add-source + resolvable modify/modify:
796 # Commit A: new file: a
797 # Commit B: rename a->b
798 # Commit C: rename a->c, add different a
799 # Commit D: merge B&C, keeping b&c and (new) a modified at beginning
800 # Commit E: merge B&C, keeping b&c and (new) a modified at end
802 # Merging commits D & E should result in no conflict; doing so correctly
803 # requires getting the virtual merge base (from merging B&C) right, handling
804 # renaming carefully (both in the virtual merge base and later), and getting
805 # content merge handled.
807 test_expect_success 'setup criss-cross + rename/rename/add-source + modify/modify' '
808 test_create_repo rename-rename-add-source &&
810 cd rename-rename-add-source &&
812 printf "lots\nof\nwords\nand\ncontent\n" >a &&
817 git checkout -b B A &&
821 git checkout -b C A &&
823 printf "2\n3\n4\n5\n6\n7\n" >a &&
828 git merge --no-commit -s ours C^0 &&
829 git checkout C -- a c &&
835 git commit -m "Merge commit C^0 into HEAD" &&
839 git merge --no-commit -s ours B^0 &&
840 git checkout B -- b &&
843 git commit -m "Merge commit B^0 into HEAD" &&
848 test_expect_failure 'detect rename/rename/add-source for virtual merge-base' '
850 cd rename-rename-add-source &&
854 git merge -s recursive E^0 &&
856 git ls-files -s >out &&
857 test_line_count = 3 out &&
858 git ls-files -u >out &&
859 test_line_count = 0 out &&
860 git ls-files -o >out &&
861 test_line_count = 1 out &&
863 printf "1\n2\n3\n4\n5\n6\n7\n8\n" >correct &&
864 git rev-parse >expect \
867 git rev-parse >actual \
869 git hash-object >>actual \
871 test_cmp expect actual
876 # criss-cross with rename/rename(1to2)/add-dest + simple modify:
886 # Commit A: new file: a
887 # Commit B: rename a->b, add c
888 # Commit C: rename a->c
889 # Commit D: merge B&C, keeping A:a and B:c
890 # Commit E: merge B&C, keeping A:a and slightly modified c from B
892 # Merging commits D & E should result in no conflict. The virtual merge
893 # base of B & C needs to not delete B:c for that to work, though...
895 test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' '
896 test_create_repo rename-rename-add-dest &&
898 cd rename-rename-add-dest &&
905 git checkout -b B A &&
907 printf "1\n2\n3\n4\n5\n6\n7\n" >c &&
911 git checkout -b C A &&
916 git merge --no-commit -s ours C^0 &&
918 git commit -m "D is like B but renames b back to a" &&
922 git merge --no-commit -s ours C^0 &&
926 git commit -m "E like D but has mod in c" &&
931 test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
933 cd rename-rename-add-dest &&
937 git merge -s recursive E^0 &&
939 git ls-files -s >out &&
940 test_line_count = 2 out &&
941 git ls-files -u >out &&
942 test_line_count = 0 out &&
943 git ls-files -o >out &&
944 test_line_count = 1 out &&
946 git rev-parse >expect \
948 git rev-parse >actual \
950 test_cmp expect actual
955 # criss-cross with modify/modify on a symlink:
965 # Commit A: simple simlink fickle->lagoon
966 # Commit B: redirect fickle->disneyland
967 # Commit C: redirect fickle->home
968 # Commit D: merge B&C, resolving in favor of B
969 # Commit E: merge B&C, resolving in favor of C
971 # This is an obvious modify/modify conflict for the symlink 'fickle'. Can
974 test_expect_success 'setup symlink modify/modify' '
975 test_create_repo symlink-modify-modify &&
977 cd symlink-modify-modify &&
979 test_ln_s_add lagoon fickle &&
983 git checkout -b B A &&
985 test_ln_s_add disneyland fickle &&
988 git checkout -b C A &&
990 test_ln_s_add home fickle &&
994 git checkout -q B^0 &&
995 git merge -s ours -m D C^0 &&
998 git checkout -q C^0 &&
999 git merge -s ours -m E B^0 &&
1004 test_expect_failure 'check symlink modify/modify' '
1006 cd symlink-modify-modify &&
1010 test_must_fail git merge -s recursive E^0 &&
1012 git ls-files -s >out &&
1013 test_line_count = 3 out &&
1014 git ls-files -u >out &&
1015 test_line_count = 3 out &&
1016 git ls-files -o >out &&
1017 test_line_count = 1 out
1022 # criss-cross with add/add of a symlink:
1032 # Commit A: No symlink or path exists yet
1033 # Commit B: set up symlink: fickle->disneyland
1034 # Commit C: set up symlink: fickle->home
1035 # Commit D: merge B&C, resolving in favor of B
1036 # Commit E: merge B&C, resolving in favor of C
1038 # This is an obvious add/add conflict for the symlink 'fickle'. Can
1041 test_expect_success 'setup symlink add/add' '
1042 test_create_repo symlink-add-add &&
1044 cd symlink-add-add &&
1051 git checkout -b B A &&
1052 test_ln_s_add disneyland fickle &&
1055 git checkout -b C A &&
1056 test_ln_s_add home fickle &&
1060 git checkout -q B^0 &&
1061 git merge -s ours -m D C^0 &&
1064 git checkout -q C^0 &&
1065 git merge -s ours -m E B^0 &&
1070 test_expect_failure 'check symlink add/add' '
1072 cd symlink-add-add &&
1076 test_must_fail git merge -s recursive E^0 &&
1078 git ls-files -s >out &&
1079 test_line_count = 2 out &&
1080 git ls-files -u >out &&
1081 test_line_count = 2 out &&
1082 git ls-files -o >out &&
1083 test_line_count = 1 out
1088 # criss-cross with modify/modify on a submodule:
1098 # Commit A: simple submodule repo
1099 # Commit B: update repo
1100 # Commit C: update repo differently
1101 # Commit D: merge B&C, resolving in favor of B
1102 # Commit E: merge B&C, resolving in favor of C
1104 # This is an obvious modify/modify conflict for the submodule 'repo'. Can
1107 test_expect_success 'setup submodule modify/modify' '
1108 test_create_repo submodule-modify-modify &&
1110 cd submodule-modify-modify &&
1112 test_create_repo submod &&
1120 git checkout -b B A &&
1126 git checkout -b C A &&
1133 git -C submod reset --hard A &&
1138 git checkout -b B A &&
1139 git -C submod reset --hard B &&
1143 git checkout -b C A &&
1144 git -C submod reset --hard C &&
1148 git checkout -q B^0 &&
1149 git merge -s ours -m D C^0 &&
1152 git checkout -q C^0 &&
1153 git merge -s ours -m E B^0 &&
1158 test_expect_failure 'check submodule modify/modify' '
1160 cd submodule-modify-modify &&
1164 test_must_fail git merge -s recursive E^0 &&
1166 git ls-files -s >out &&
1167 test_line_count = 3 out &&
1168 git ls-files -u >out &&
1169 test_line_count = 3 out &&
1170 git ls-files -o >out &&
1171 test_line_count = 1 out
1176 # criss-cross with add/add on a submodule:
1186 # Commit A: nothing of note
1187 # Commit B: introduce submodule repo
1188 # Commit C: introduce submodule repo at different commit
1189 # Commit D: merge B&C, resolving in favor of B
1190 # Commit E: merge B&C, resolving in favor of C
1192 # This is an obvious add/add conflict for the submodule 'repo'. Can
1195 test_expect_success 'setup submodule add/add' '
1196 test_create_repo submodule-add-add &&
1198 cd submodule-add-add &&
1200 test_create_repo submod &&
1208 git checkout -b B A &&
1214 git checkout -b C A &&
1221 touch irrelevant-file &&
1222 git add irrelevant-file &&
1226 git checkout -b B A &&
1227 git -C submod reset --hard B &&
1231 git checkout -b C A &&
1232 git -C submod reset --hard C &&
1236 git checkout -q B^0 &&
1237 git merge -s ours -m D C^0 &&
1240 git checkout -q C^0 &&
1241 git merge -s ours -m E B^0 &&
1246 test_expect_failure 'check submodule add/add' '
1248 cd submodule-add-add &&
1252 test_must_fail git merge -s recursive E^0 &&
1254 git ls-files -s >out &&
1255 test_line_count = 3 out &&
1256 git ls-files -u >out &&
1257 test_line_count = 2 out &&
1258 git ls-files -o >out &&
1259 test_line_count = 1 out
1264 # criss-cross with conflicting entry types:
1274 # Commit A: nothing of note
1275 # Commit B: introduce submodule 'path'
1276 # Commit C: introduce symlink 'path'
1277 # Commit D: merge B&C, resolving in favor of B
1278 # Commit E: merge B&C, resolving in favor of C
1280 # This is an obvious add/add conflict for 'path'. Can git detect it?
1282 test_expect_success 'setup conflicting entry types (submodule vs symlink)' '
1283 test_create_repo submodule-symlink-add-add &&
1285 cd submodule-symlink-add-add &&
1287 test_create_repo path &&
1296 touch irrelevant-file &&
1297 git add irrelevant-file &&
1301 git checkout -b B A &&
1302 git -C path reset --hard B &&
1306 git checkout -b C A &&
1308 test_ln_s_add irrelevant-file path &&
1311 git checkout -q B^0 &&
1312 git merge -s ours -m D C^0 &&
1315 git checkout -q C^0 &&
1316 git merge -s ours -m E B^0 &&
1321 test_expect_failure 'check conflicting entry types (submodule vs symlink)' '
1323 cd submodule-symlink-add-add &&
1327 test_must_fail git merge -s recursive E^0 &&
1329 git ls-files -s >out &&
1330 test_line_count = 3 out &&
1331 git ls-files -u >out &&
1332 test_line_count = 2 out &&
1333 git ls-files -o >out &&
1334 test_line_count = 1 out
1339 # criss-cross with regular files that have conflicting modes:
1349 # Commit A: nothing of note
1350 # Commit B: introduce file source_me.bash, not executable
1351 # Commit C: introduce file source_me.bash, executable
1352 # Commit D: merge B&C, resolving in favor of B
1353 # Commit E: merge B&C, resolving in favor of C
1355 # This is an obvious add/add mode conflict. Can git detect it?
1357 test_expect_success 'setup conflicting modes for regular file' '
1358 test_create_repo regular-file-mode-conflict &&
1360 cd regular-file-mode-conflict &&
1362 touch irrelevant-file &&
1363 git add irrelevant-file &&
1367 git checkout -b B A &&
1368 echo "command_to_run" >source_me.bash &&
1369 git add source_me.bash &&
1372 git checkout -b C A &&
1373 echo "command_to_run" >source_me.bash &&
1374 git add source_me.bash &&
1375 test_chmod +x source_me.bash &&
1378 git checkout -q B^0 &&
1379 git merge -s ours -m D C^0 &&
1382 git checkout -q C^0 &&
1383 git merge -s ours -m E B^0 &&
1388 test_expect_failure 'check conflicting modes for regular file' '
1390 cd regular-file-mode-conflict &&
1394 test_must_fail git merge -s recursive E^0 &&
1396 git ls-files -s >out &&
1397 test_line_count = 3 out &&
1398 git ls-files -u >out &&
1399 test_line_count = 2 out &&
1400 git ls-files -o >out &&
1401 test_line_count = 1 out