3 test_description
="recursive merge corner cases w/ renames but not criss-crosses"
4 # t6036 has corner cases that involve both criss-cross merges and renames
6 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
7 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 .
"$TEST_DIRECTORY"/lib-merge.sh
12 test_setup_rename_delete_untracked
() {
13 test_create_repo rename-delete-untracked
&&
15 cd rename-delete-untracked
&&
17 echo "A pretty inscription" >ring
&&
20 git commit
-m beginning
&&
23 git checkout
-b rename-the-ring
&&
24 git
mv ring one-ring-to-rule-them-all
&&
26 git commit
-m fullname
&&
28 git checkout people
&&
33 git commit
-m track-people-instead-of-objects
&&
34 echo "Myyy PRECIOUSSS" >ring
38 test_expect_success
"Does git preserve Gollum's precious artifact?" '
39 test_setup_rename_delete_untracked &&
41 cd rename-delete-untracked &&
43 test_must_fail git merge -s recursive rename-the-ring &&
45 # Make sure git did not delete an untracked file
46 test_path_is_file ring
50 # Testcase setup for rename/modify/add-source:
51 # Commit A: new file: a
52 # Commit B: modify a slightly
53 # Commit C: rename a->b, add completely different a
55 # We should be able to merge B & C cleanly
57 test_setup_rename_modify_add_source
() {
58 test_create_repo rename-modify-add-source
&&
60 cd rename-modify-add-source
&&
62 printf "1\n2\n3\n4\n5\n6\n7\n" >a
&&
67 git checkout
-b B A
&&
72 git checkout
-b C A
&&
74 echo something completely different
>a
&&
80 test_expect_failure
'rename/modify/add-source conflict resolvable' '
81 test_setup_rename_modify_add_source &&
83 cd rename-modify-add-source &&
87 git merge -s recursive C^0 &&
89 git rev-parse >expect \
91 git rev-parse >actual \
93 test_cmp expect actual
97 test_setup_break_detection_1
() {
98 test_create_repo break-detection-1
&&
100 cd break-detection-1
&&
102 printf "1\n2\n3\n4\n5\n" >a
&&
108 git checkout
-b B A
&&
110 echo "Completely different content" >a
&&
114 git checkout
-b C A
&&
121 test_expect_failure
'conflict caused if rename not detected' '
122 test_setup_break_detection_1 &&
124 cd break-detection-1 &&
126 git checkout -q C^0 &&
127 git merge -s recursive B^0 &&
129 git ls-files -s >out &&
130 test_line_count = 3 out &&
131 git ls-files -u >out &&
132 test_line_count = 0 out &&
133 git ls-files -o >out &&
134 test_line_count = 1 out &&
136 test_line_count = 6 c &&
137 git rev-parse >expect \
139 git rev-parse >actual \
141 test_cmp expect actual
145 test_setup_break_detection_2
() {
146 test_create_repo break-detection-2
&&
148 cd break-detection-2
&&
150 printf "1\n2\n3\n4\n5\n" >a
&&
156 git checkout
-b D A
&&
160 echo "Completely different content" >a
&&
164 git checkout
-b E A
&&
166 echo "Completely different content" >>a
&&
172 test_expect_failure
'missed conflict if rename not detected' '
173 test_setup_break_detection_2 &&
175 cd break-detection-2 &&
177 git checkout -q E^0 &&
178 test_must_fail git merge -s recursive D^0
182 # Tests for undetected rename/add-source causing a file to erroneously be
183 # deleted (and for mishandled rename/rename(1to1) causing the same issue).
185 # This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
186 # same file is renamed on both sides to the same thing; it should trigger
187 # the 1to2 logic, which it would do if the add-source didn't cause issues
188 # for git's rename detection):
189 # Commit A: new file: a
190 # Commit B: rename a->b
191 # Commit C: rename a->b, add unrelated a
193 test_setup_break_detection_3
() {
194 test_create_repo break-detection-3
&&
196 cd break-detection-3
&&
198 printf "1\n2\n3\n4\n5\n" >a
&&
203 git checkout
-b B A
&&
207 git checkout
-b C A
&&
215 test_expect_failure
'detect rename/add-source and preserve all data' '
216 test_setup_break_detection_3 &&
218 cd break-detection-3 &&
222 git merge -s recursive C^0 &&
224 git ls-files -s >out &&
225 test_line_count = 2 out &&
226 git ls-files -u >out &&
227 test_line_count = 2 out &&
228 git ls-files -o >out &&
229 test_line_count = 1 out &&
231 test_path_is_file a &&
232 test_path_is_file b &&
234 git rev-parse >expect \
236 git rev-parse >actual \
238 test_cmp expect actual
242 test_expect_failure
'detect rename/add-source and preserve all data, merge other way' '
243 test_setup_break_detection_3 &&
245 cd break-detection-3 &&
249 git merge -s recursive B^0 &&
251 git ls-files -s >out &&
252 test_line_count = 2 out &&
253 git ls-files -u >out &&
254 test_line_count = 2 out &&
255 git ls-files -o >out &&
256 test_line_count = 1 out &&
258 test_path_is_file a &&
259 test_path_is_file b &&
261 git rev-parse >expect \
263 git rev-parse >actual \
265 test_cmp expect actual
269 test_setup_rename_directory
() {
270 test_create_repo rename-directory-
$1 &&
272 cd rename-directory-
$1 &&
274 printf "1\n2\n3\n4\n5\n6\n" >file &&
277 git commit
-m base
&&
280 git checkout
-b right
&&
283 echo junk
>newfile
/realfile
&&
284 git add
file newfile
/realfile
&&
286 git commit
-m right
&&
288 git checkout
-b left-conflict base
&&
291 git
mv file newfile
&&
293 git commit
-m left
&&
295 git checkout
-b left-clean base
&&
297 cat file >>newfile
&&
305 test_expect_success
'rename/directory conflict + clean content merge' '
306 test_setup_rename_directory 1a &&
308 cd rename-directory-1a &&
310 git checkout left-clean^0 &&
312 test_must_fail git merge -s recursive right^0 &&
314 git ls-files -s >out &&
315 test_line_count = 2 out &&
316 git ls-files -u >out &&
317 test_line_count = 1 out &&
318 git ls-files -o >out &&
319 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
321 test_line_count = 1 out
323 test_line_count = 2 out
327 git cat-file -p base:file >>expect &&
329 test_cmp expect newfile~HEAD &&
331 test_path_is_file newfile/realfile &&
332 test_path_is_file newfile~HEAD
336 test_expect_success
'rename/directory conflict + content merge conflict' '
337 test_setup_rename_directory 1b &&
339 cd rename-directory-1b &&
344 git checkout left-conflict^0 &&
346 test_must_fail git merge -s recursive right^0 &&
348 git ls-files -s >out &&
349 test_line_count = 4 out &&
350 git ls-files -u >out &&
351 test_line_count = 3 out &&
352 git ls-files -o >out &&
353 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
355 test_line_count = 1 out
357 test_line_count = 2 out
360 git cat-file -p left-conflict:newfile >left &&
361 git cat-file -p base:file >base &&
362 git cat-file -p right:file >right &&
363 test_must_fail git merge-file \
368 test_cmp left newfile~HEAD &&
370 git rev-parse >expect \
371 base:file left-conflict:newfile right:file &&
372 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
374 git rev-parse >actual \
375 :1:newfile~HEAD :2:newfile~HEAD :3:newfile~HEAD
377 git rev-parse >actual \
378 :1:newfile :2:newfile :3:newfile
380 test_cmp expect actual &&
382 test_path_is_file newfile/realfile &&
383 test_path_is_file newfile~HEAD
387 test_setup_rename_directory_2
() {
388 test_create_repo rename-directory-2
&&
390 cd rename-directory-2
&&
393 printf "1\n2\n3\n4\n5\n6\n" >sub
/file &&
396 git commit
-m base
&&
399 git checkout
-b right
&&
403 git commit
-m right
&&
405 git checkout
-b left base
&&
407 cat sub
/file >>newfile
&&
416 test_expect_success
'disappearing dir in rename/directory conflict handled' '
417 test_setup_rename_directory_2 &&
419 cd rename-directory-2 &&
421 git checkout left^0 &&
423 git merge -s recursive right^0 &&
425 git ls-files -s >out &&
426 test_line_count = 1 out &&
427 git ls-files -u >out &&
428 test_line_count = 0 out &&
429 git ls-files -o >out &&
430 test_line_count = 1 out &&
433 git cat-file -p base:sub/file >>expect &&
435 test_cmp expect sub &&
437 test_path_is_file sub
441 # Test for basic rename/add-dest conflict, with rename needing content merge:
443 # Commit A: rename a->b, modifying b too
444 # Commit B: modify a, add different b
446 test_setup_rename_with_content_merge_and_add
() {
447 test_create_repo rename-with-content-merge-and-add-
$1 &&
449 cd rename-with-content-merge-and-add-
$1 &&
456 git checkout
-b A O
&&
462 git checkout
-b B O
&&
464 echo hello world
>b
&&
470 test_expect_success
'handle rename-with-content-merge vs. add' '
471 test_setup_rename_with_content_merge_and_add AB &&
473 cd rename-with-content-merge-and-add-AB &&
477 test_must_fail git merge -s recursive B^0 >out &&
478 test_i18ngrep "CONFLICT (.*/add)" out &&
480 git ls-files -s >out &&
481 test_line_count = 2 out &&
482 git ls-files -u >out &&
483 test_line_count = 2 out &&
484 # Also, make sure both unmerged entries are for "b"
485 git ls-files -u b >out &&
486 test_line_count = 2 out &&
487 git ls-files -o >out &&
488 test_line_count = 1 out &&
490 test_path_is_missing a &&
491 test_path_is_file b &&
494 git hash-object tmp >expect &&
495 git rev-parse B:b >>expect &&
496 git rev-parse >actual \
498 test_cmp expect actual &&
500 # Test that the two-way merge in b is as expected
501 git cat-file -p :2:b >>ours &&
502 git cat-file -p :3:b >>theirs &&
504 test_must_fail git merge-file \
513 test_expect_success
'handle rename-with-content-merge vs. add, merge other way' '
514 test_setup_rename_with_content_merge_and_add BA &&
516 cd rename-with-content-merge-and-add-BA &&
523 test_must_fail git merge -s recursive A^0 >out &&
524 test_i18ngrep "CONFLICT (.*/add)" out &&
526 git ls-files -s >out &&
527 test_line_count = 2 out &&
528 git ls-files -u >out &&
529 test_line_count = 2 out &&
530 # Also, make sure both unmerged entries are for "b"
531 git ls-files -u b >out &&
532 test_line_count = 2 out &&
533 git ls-files -o >out &&
534 test_line_count = 1 out &&
536 test_path_is_missing a &&
537 test_path_is_file b &&
540 git rev-parse B:b >expect &&
541 git hash-object tmp >>expect &&
542 git rev-parse >actual \
544 test_cmp expect actual &&
546 # Test that the two-way merge in b is as expected
547 git cat-file -p :2:b >>ours &&
548 git cat-file -p :3:b >>theirs &&
550 test_must_fail git merge-file \
559 # Test for all kinds of things that can go wrong with rename/rename (2to1):
560 # Commit A: new files: a & b
561 # Commit B: rename a->c, modify b
562 # Commit C: rename b->c, modify a
564 # Merging of B & C should NOT be clean. Questions:
565 # * Both a & b should be removed by the merge; are they?
566 # * The two c's should contain modifications to a & b; do they?
567 # * The index should contain two files, both for c; does it?
568 # * The working copy should have two files, both of form c~<unique>; does it?
569 # * Nothing else should be present. Is anything?
571 test_setup_rename_rename_2to1
() {
572 test_create_repo rename-rename-2to1
&&
574 cd rename-rename-2to1
&&
576 printf "1\n2\n3\n4\n5\n" >a
&&
577 printf "5\n4\n3\n2\n1\n" >b
&&
582 git checkout
-b B A
&&
588 git checkout
-b C A
&&
596 test_expect_success
'handle rename/rename (2to1) conflict correctly' '
597 test_setup_rename_rename_2to1 &&
599 cd rename-rename-2to1 &&
603 test_must_fail git merge -s recursive C^0 >out &&
604 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
606 git ls-files -s >out &&
607 test_line_count = 2 out &&
608 git ls-files -u >out &&
609 test_line_count = 2 out &&
610 git ls-files -u c >out &&
611 test_line_count = 2 out &&
612 git ls-files -o >out &&
613 test_line_count = 1 out &&
615 test_path_is_missing a &&
616 test_path_is_missing b &&
618 git rev-parse >expect \
620 git rev-parse >actual \
622 test_cmp expect actual &&
624 # Test that the two-way merge in new_a is as expected
625 git cat-file -p :2:c >>ours &&
626 git cat-file -p :3:c >>theirs &&
628 test_must_fail git merge-file \
633 git hash-object c >actual &&
634 git hash-object ours >expect &&
635 test_cmp expect actual
639 # Testcase setup for simple rename/rename (1to2) conflict:
640 # Commit A: new file: a
641 # Commit B: rename a->b
642 # Commit C: rename a->c
643 test_setup_rename_rename_1to2
() {
644 test_create_repo rename-rename-1to2
&&
646 cd rename-rename-1to2
&&
654 git checkout
-b B A
&&
659 git checkout
-b C A
&&
666 test_expect_success
'merge has correct working tree contents' '
667 test_setup_rename_rename_1to2 &&
669 cd rename-rename-1to2 &&
673 test_must_fail git merge -s recursive B^0 &&
675 git ls-files -s >out &&
676 test_line_count = 3 out &&
677 git ls-files -u >out &&
678 test_line_count = 3 out &&
679 git ls-files -o >out &&
680 test_line_count = 1 out &&
682 test_path_is_missing a &&
683 git rev-parse >expect \
686 git rev-parse >actual \
688 git hash-object >>actual \
690 test_cmp expect actual
694 # Testcase setup for rename/rename(1to2)/add-source conflict:
695 # Commit A: new file: a
696 # Commit B: rename a->b
697 # Commit C: rename a->c, add completely different a
699 # Merging of B & C should NOT be clean; there's a rename/rename conflict
701 test_setup_rename_rename_1to2_add_source_1
() {
702 test_create_repo rename-rename-1to2-add-source-1
&&
704 cd rename-rename-1to2-add-source-1
&&
706 printf "1\n2\n3\n4\n5\n6\n7\n" >a
&&
711 git checkout
-b B A
&&
715 git checkout
-b C A
&&
717 echo something completely different
>a
&&
723 test_expect_failure
'detect conflict with rename/rename(1to2)/add-source merge' '
724 test_setup_rename_rename_1to2_add_source_1 &&
726 cd rename-rename-1to2-add-source-1 &&
730 test_must_fail git merge -s recursive C^0 &&
732 git ls-files -s >out &&
733 test_line_count = 4 out &&
734 git ls-files -o >out &&
735 test_line_count = 1 out &&
737 git rev-parse >expect \
739 git rev-parse >actual \
740 :3:a :1:a :2:b :3:c &&
741 test_cmp expect actual &&
743 test_path_is_file a &&
744 test_path_is_file b &&
749 test_setup_rename_rename_1to2_add_source_2
() {
750 test_create_repo rename-rename-1to2-add-source-2
&&
752 cd rename-rename-1to2-add-source-2
&&
757 git commit
-m base
&&
760 git checkout
-b B A
&&
765 git checkout
-b C A
&&
767 echo important-info
>a
&&
774 test_expect_failure
'rename/rename/add-source still tracks new a file' '
775 test_setup_rename_rename_1to2_add_source_2 &&
777 cd rename-rename-1to2-add-source-2 &&
780 git merge -s recursive B^0 &&
782 git ls-files -s >out &&
783 test_line_count = 2 out &&
784 git ls-files -o >out &&
785 test_line_count = 1 out &&
787 git rev-parse >expect \
789 git rev-parse >actual \
791 test_cmp expect actual
795 test_setup_rename_rename_1to2_add_dest
() {
796 test_create_repo rename-rename-1to2-add-dest
&&
798 cd rename-rename-1to2-add-dest
&&
803 git commit
-m base
&&
806 git checkout
-b B A
&&
808 echo precious-data
>c
&&
813 git checkout
-b C A
&&
815 echo important-info
>b
&&
822 test_expect_success
'rename/rename/add-dest merge still knows about conflicting file versions' '
823 test_setup_rename_rename_1to2_add_dest &&
825 cd rename-rename-1to2-add-dest &&
828 test_must_fail git merge -s recursive B^0 &&
830 git ls-files -s >out &&
831 test_line_count = 5 out &&
832 git ls-files -u b >out &&
833 test_line_count = 2 out &&
834 git ls-files -u c >out &&
835 test_line_count = 2 out &&
836 git ls-files -o >out &&
837 test_line_count = 1 out &&
839 git rev-parse >expect \
840 A:a C:b B:b C:c B:c &&
841 git rev-parse >actual \
842 :1:a :2:b :3:b :2:c :3:c &&
843 test_cmp expect actual &&
845 # Record some contents for re-doing merges
846 git cat-file -p A:a >stuff &&
847 git cat-file -p C:b >important_info &&
848 git cat-file -p B:c >precious_data &&
851 # Test the merge in b
852 test_must_fail git merge-file \
856 important_info empty stuff &&
857 test_cmp important_info b &&
859 # Test the merge in c
860 test_must_fail git merge-file \
864 stuff empty precious_data &&
869 # Testcase rad, rename/add/delete
871 # Commit A: rm foo, add different bar
872 # Commit B: rename foo->bar
873 # Expected: CONFLICT (rename/add/delete), two-way merged bar
876 test_create_repo rad
&&
879 echo "original file" >foo
&&
881 git commit
-m "original" &&
889 echo "different file" >bar
&&
891 git commit
-m "Remove foo, add bar" &&
895 git commit
-m "rename foo to bar"
899 test_expect_merge_algorithm failure success
'rad-check: rename/add/delete conflict' '
905 test_must_fail git merge -s recursive A^0 >out 2>err &&
907 # Instead of requiring the output to contain one combined line
908 # CONFLICT (rename/add/delete)
909 # or perhaps two lines:
910 # CONFLICT (rename/add): new file collides with rename target
911 # CONFLICT (rename/delete): rename source removed on other side
912 # and instead of requiring "rename/add" instead of "add/add",
913 # be flexible in the type of console output message(s) reported
914 # for this particular case; we will be more stringent about the
915 # contents of the index and working directory.
916 test_i18ngrep "CONFLICT (.*/add)" out &&
917 test_i18ngrep "CONFLICT (rename.*/delete)" out &&
918 test_must_be_empty err &&
920 git ls-files -s >file_count &&
921 test_line_count = 2 file_count &&
922 git ls-files -u >file_count &&
923 test_line_count = 2 file_count &&
924 git ls-files -o >file_count &&
925 test_line_count = 3 file_count &&
927 git rev-parse >actual \
929 git rev-parse >expect \
932 test_path_is_missing foo &&
933 # bar should have two-way merged contents of the different
934 # versions of bar; check that content from both sides is
941 # Testcase rrdd, rename/rename(2to1)/delete/delete
943 # Commit A: rename foo->baz, rm bar
944 # Commit B: rename bar->baz, rm foo
945 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
948 test_create_repo rrdd
&&
963 git commit
-m "Rename foo, remove bar" &&
968 git commit
-m "Rename bar, remove foo"
972 test_expect_merge_algorithm failure success
'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
978 test_must_fail git merge -s recursive B^0 >out 2>err &&
980 # Instead of requiring the output to contain one combined line
981 # CONFLICT (rename/rename/delete/delete)
982 # or perhaps two lines:
983 # CONFLICT (rename/rename): ...
984 # CONFLICT (rename/delete): info about pair 1
985 # CONFLICT (rename/delete): info about pair 2
986 # and instead of requiring "rename/rename" instead of "add/add",
987 # be flexible in the type of console output message(s) reported
988 # for this particular case; we will be more stringent about the
989 # contents of the index and working directory.
990 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
991 test_i18ngrep "CONFLICT (rename.*delete)" out &&
992 test_must_be_empty err &&
994 git ls-files -s >file_count &&
995 test_line_count = 2 file_count &&
996 git ls-files -u >file_count &&
997 test_line_count = 2 file_count &&
998 git ls-files -o >file_count &&
999 test_line_count = 3 file_count &&
1001 git rev-parse >actual \
1003 git rev-parse >expect \
1006 test_path_is_missing foo &&
1007 test_path_is_missing bar &&
1008 # baz should have two-way merged contents of the original
1009 # contents of foo and bar; check that content from both sides
1016 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
1017 # Commit O: one, three, five
1018 # Commit A: one->two, three->four, five->six
1019 # Commit B: one->six, three->two, five->four
1020 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
1021 # multi-way merged contents found in two, four, six
1023 test_setup_mod6
() {
1024 test_create_repo mod6
&&
1027 test_seq
11 19 >one
&&
1028 test_seq
31 39 >three
&&
1029 test_seq
51 59 >five
&&
1032 git commit
-m "O" &&
1039 test_seq
10 19 >one
&&
1041 git add one three
&&
1043 git
mv three four
&&
1046 git commit
-m "A" &&
1050 echo forty
>>three
&&
1052 git add one three five
&&
1061 test_expect_merge_algorithm failure success
'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
1068 test_must_fail git merge -s recursive B^0 >out 2>err &&
1070 test_i18ngrep "CONFLICT (rename/rename)" out &&
1071 test_must_be_empty err &&
1073 git ls-files -s >file_count &&
1074 test_line_count = 9 file_count &&
1075 git ls-files -u >file_count &&
1076 test_line_count = 9 file_count &&
1077 git ls-files -o >file_count &&
1078 test_line_count = 3 file_count &&
1080 test_seq 10 20 >merged-one &&
1081 test_seq 51 60 >merged-five &&
1082 # Determine what the merge of three would give us.
1083 test_seq 31 39 >three-base &&
1084 test_seq 31 40 >three-side-A &&
1085 test_seq 31 39 >three-side-B &&
1086 echo forty >>three-side-B &&
1087 test_must_fail git merge-file \
1091 three-side-A three-base three-side-B &&
1092 sed -e "s/^\([<=>]\)/\1\1/" three-side-A >merged-three &&
1094 # Verify the index is as expected
1095 git rev-parse >actual \
1099 git hash-object >expect \
1100 merged-one merged-three \
1101 merged-three merged-five \
1102 merged-five merged-one &&
1103 test_cmp expect actual &&
1105 git cat-file -p :2:two >expect &&
1106 git cat-file -p :3:two >other &&
1108 test_must_fail git merge-file \
1109 -L "HEAD" -L "" -L "B^0" \
1110 expect empty other &&
1111 test_cmp expect two &&
1113 git cat-file -p :2:four >expect &&
1114 git cat-file -p :3:four >other &&
1115 test_must_fail git merge-file \
1116 -L "HEAD" -L "" -L "B^0" \
1117 expect empty other &&
1118 test_cmp expect four &&
1120 git cat-file -p :2:six >expect &&
1121 git cat-file -p :3:six >other &&
1122 test_must_fail git merge-file \
1123 -L "HEAD" -L "" -L "B^0" \
1124 expect empty other &&
1129 test_conflicts_with_adds_and_renames
() {
1141 # Both L and R have files named 'three' which collide. Each of
1142 # the colliding files could have been involved in a rename, in
1143 # which case there was a file named 'one' or 'two' that was
1144 # modified on the opposite side of history and renamed into the
1145 # collision on this side of history.
1148 # 1) The index should contain both a stage 2 and stage 3 entry
1149 # for the colliding file. Does it?
1150 # 2) When renames are involved, the content merges are clean, so
1151 # the index should reflect the content merges, not merely the
1152 # version of the colliding file from the prior commit. Does
1154 # 3) There should be a file in the worktree named 'three'
1155 # containing the two-way merged contents of the content-merged
1156 # versions of 'three' from each of the two colliding
1157 # files. Is it present?
1158 # 4) There should not be any three~* files in the working
1160 test_setup_collision_conflict
() {
1161 #test_expect_success "setup simple $sideL/$sideR conflict" '
1162 test_create_repo simple_
${sideL}_
${sideR} &&
1164 cd simple_
${sideL}_
${sideR} &&
1166 # Create some related files now
1167 for i
in $
(test_seq
1 10)
1169 echo Random base content line
$i
1171 cp file_v1 file_v2
&&
1172 echo modification
>>file_v2
&&
1174 cp file_v1 file_v3
&&
1175 echo more stuff
>>file_v3
&&
1176 cp file_v3 file_v4
&&
1177 echo yet
more stuff
>>file_v4
&&
1179 # Use a tag to record both these files for simple
1180 # access, and clean out these untracked files
1181 git tag file_v1 $
(git hash-object
-w file_v1
) &&
1182 git tag file_v2 $
(git hash-object
-w file_v2
) &&
1183 git tag file_v3 $
(git hash-object
-w file_v3
) &&
1184 git tag file_v4 $
(git hash-object
-w file_v4
) &&
1187 # Setup original commit (or merge-base), consisting of
1188 # files named "one" and "two" if renames were involved.
1189 touch irrelevant_file
&&
1190 git add irrelevant_file
&&
1191 if [ $sideL = "rename" ]
1193 git show file_v1
>one
&&
1196 if [ $sideR = "rename" ]
1198 git show file_v3
>two
&&
1201 test_tick
&& git commit
-m initial
&&
1206 # Handle the left side
1208 if [ $sideL = "rename" ]
1212 git show file_v2
>three
&&
1215 if [ $sideR = "rename" ]
1217 git show file_v4
>two
&&
1220 test_tick
&& git commit
-m L
&&
1222 # Handle the right side
1224 if [ $sideL = "rename" ]
1226 git show file_v2
>one
&&
1229 if [ $sideR = "rename" ]
1233 git show file_v4
>three
&&
1236 test_tick
&& git commit
-m R
1241 test_expect_success
"check simple $sideL/$sideR conflict" '
1242 test_setup_collision_conflict &&
1244 cd simple_${sideL}_${sideR} &&
1248 # Merge must fail; there is a conflict
1249 test_must_fail git merge -s recursive R^0 &&
1251 # Make sure the index has the right number of entries
1252 git ls-files -s >out &&
1253 test_line_count = 3 out &&
1254 git ls-files -u >out &&
1255 test_line_count = 2 out &&
1256 # Ensure we have the correct number of untracked files
1257 git ls-files -o >out &&
1258 test_line_count = 1 out &&
1260 # Nothing should have touched irrelevant_file
1261 git rev-parse >actual \
1262 :0:irrelevant_file \
1265 git rev-parse >expected \
1266 main:irrelevant_file \
1269 test_cmp expected actual &&
1271 # Make sure we have the correct merged contents for
1273 git show file_v1 >expected &&
1274 cat <<-\EOF >>expected &&
1283 test_cmp expected three
1288 test_conflicts_with_adds_and_renames rename rename
1289 test_conflicts_with_adds_and_renames rename add
1290 test_conflicts_with_adds_and_renames add rename
1291 test_conflicts_with_adds_and_renames add add
1301 # main has two files, named 'one' and 'two'.
1302 # branches L and R both modify 'one', in conflicting ways.
1303 # branches L and R both modify 'two', in conflicting ways.
1304 # branch L also renames 'one' to 'three'.
1305 # branch R also renames 'two' to 'three'.
1307 # So, we have four different conflicting files that all end up at path
1309 test_setup_nested_conflicts_from_rename_rename
() {
1310 test_create_repo nested_conflicts_from_rename_rename
&&
1312 cd nested_conflicts_from_rename_rename
&&
1314 # Create some related files now
1315 for i
in $
(test_seq
1 10)
1317 echo Random base content line
$i
1320 cp file_v1 file_v2
&&
1321 cp file_v1 file_v3
&&
1322 cp file_v1 file_v4
&&
1323 cp file_v1 file_v5
&&
1324 cp file_v1 file_v6
&&
1326 echo one
>>file_v1
&&
1327 echo uno
>>file_v2
&&
1328 echo eins
>>file_v3
&&
1330 echo two
>>file_v4
&&
1331 echo dos
>>file_v5
&&
1332 echo zwei
>>file_v6
&&
1334 # Setup original commit (or merge-base), consisting of
1335 # files named "one" and "two".
1339 test_tick
&& git commit
-m english
&&
1344 # Handle the left side
1347 mv -f file_v2 three
&&
1348 mv -f file_v5 two
&&
1349 git add two three
&&
1350 test_tick
&& git commit
-m spanish
&&
1352 # Handle the right side
1355 mv -f file_v3 one
&&
1356 mv -f file_v6 three
&&
1357 git add one three
&&
1358 test_tick
&& git commit
-m german
1362 test_expect_success
'check nested conflicts from rename/rename(2to1)' '
1363 test_setup_nested_conflicts_from_rename_rename &&
1365 cd nested_conflicts_from_rename_rename &&
1369 # Merge must fail; there is a conflict
1370 test_must_fail git merge -s recursive R^0 &&
1372 # Make sure the index has the right number of entries
1373 git ls-files -s >out &&
1374 test_line_count = 2 out &&
1375 git ls-files -u >out &&
1376 test_line_count = 2 out &&
1377 # Ensure we have the correct number of untracked files
1378 git ls-files -o >out &&
1379 test_line_count = 1 out &&
1381 # Compare :2:three to expected values
1382 git cat-file -p main:one >base &&
1383 git cat-file -p L:three >ours &&
1384 git cat-file -p R:one >theirs &&
1385 test_must_fail git merge-file \
1386 -L "HEAD:three" -L "" -L "R^0:one" \
1388 sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
1389 git cat-file -p :2:three >expect &&
1390 test_cmp expect L-three &&
1392 # Compare :2:three to expected values
1393 git cat-file -p main:two >base &&
1394 git cat-file -p L:two >ours &&
1395 git cat-file -p R:three >theirs &&
1396 test_must_fail git merge-file \
1397 -L "HEAD:two" -L "" -L "R^0:three" \
1399 sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
1400 git cat-file -p :3:three >expect &&
1401 test_cmp expect R-three &&
1403 # Compare three to expected contents
1405 test_must_fail git merge-file \
1406 -L "HEAD" -L "" -L "R^0" \
1407 L-three empty R-three &&
1408 test_cmp three L-three
1412 # Testcase rename/rename(1to2) of a binary file
1416 # Expected: CONFLICT(rename/rename) message, three unstaged entries in the
1417 # index, and contents of orig-[AB] at path orig-[AB]
1418 test_setup_rename_rename_1_to_2_binary
() {
1419 test_create_repo rename_rename_1_to_2_binary
&&
1421 cd rename_rename_1_to_2_binary
&&
1423 echo '* binary' >.gitattributes
&&
1424 git add .gitattributes
&&
1426 test_seq
1 10 >orig
&&
1428 git commit
-m orig
&&
1434 git
mv orig orig-A
&&
1435 test_seq
1 11 >orig-A
&&
1437 git commit
-m orig-A
&&
1440 git
mv orig orig-B
&&
1441 test_seq
0 10 >orig-B
&&
1443 git commit
-m orig-B
1448 test_expect_success
'rename/rename(1to2) with a binary file' '
1449 test_setup_rename_rename_1_to_2_binary &&
1451 cd rename_rename_1_to_2_binary &&
1455 test_must_fail git merge -s recursive B^0 &&
1457 # Make sure the index has the right number of entries
1458 git ls-files -s >actual &&
1459 test_line_count = 4 actual &&
1461 git rev-parse A:orig-A B:orig-B >expect &&
1462 git hash-object orig-A orig-B >actual &&
1463 test_cmp expect actual