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
8 test_setup_rename_delete_untracked () {
9 test_create_repo rename-delete-untracked &&
11 cd rename-delete-untracked &&
13 echo "A pretty inscription" >ring &&
16 git commit -m beginning &&
19 git checkout -b rename-the-ring &&
20 git mv ring one-ring-to-rule-them-all &&
22 git commit -m fullname &&
24 git checkout people &&
29 git commit -m track-people-instead-of-objects &&
30 echo "Myyy PRECIOUSSS" >ring
34 test_expect_success "Does git preserve Gollum's precious artifact?" '
35 test_setup_rename_delete_untracked &&
37 cd rename-delete-untracked &&
39 test_must_fail git merge -s recursive rename-the-ring &&
41 # Make sure git did not delete an untracked file
42 test_path_is_file ring
46 # Testcase setup for rename/modify/add-source:
47 # Commit A: new file: a
48 # Commit B: modify a slightly
49 # Commit C: rename a->b, add completely different a
51 # We should be able to merge B & C cleanly
53 test_setup_rename_modify_add_source () {
54 test_create_repo rename-modify-add-source &&
56 cd rename-modify-add-source &&
58 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
63 git checkout -b B A &&
68 git checkout -b C A &&
70 echo something completely different >a &&
76 test_expect_failure 'rename/modify/add-source conflict resolvable' '
77 test_setup_rename_modify_add_source &&
79 cd rename-modify-add-source &&
83 git merge -s recursive C^0 &&
85 git rev-parse >expect \
87 git rev-parse >actual \
89 test_cmp expect actual
93 test_setup_break_detection_1 () {
94 test_create_repo break-detection-1 &&
96 cd break-detection-1 &&
98 printf "1\n2\n3\n4\n5\n" >a &&
104 git checkout -b B A &&
106 echo "Completely different content" >a &&
110 git checkout -b C A &&
117 test_expect_failure 'conflict caused if rename not detected' '
118 test_setup_break_detection_1 &&
120 cd break-detection-1 &&
122 git checkout -q C^0 &&
123 git merge -s recursive B^0 &&
125 git ls-files -s >out &&
126 test_line_count = 3 out &&
127 git ls-files -u >out &&
128 test_line_count = 0 out &&
129 git ls-files -o >out &&
130 test_line_count = 1 out &&
132 test_line_count = 6 c &&
133 git rev-parse >expect \
135 git rev-parse >actual \
137 test_cmp expect actual
141 test_setup_break_detection_2 () {
142 test_create_repo break-detection-2 &&
144 cd break-detection-2 &&
146 printf "1\n2\n3\n4\n5\n" >a &&
152 git checkout -b D A &&
156 echo "Completely different content" >a &&
160 git checkout -b E A &&
162 echo "Completely different content" >>a &&
168 test_expect_failure 'missed conflict if rename not detected' '
169 test_setup_break_detection_2 &&
171 cd break-detection-2 &&
173 git checkout -q E^0 &&
174 test_must_fail git merge -s recursive D^0
178 # Tests for undetected rename/add-source causing a file to erroneously be
179 # deleted (and for mishandled rename/rename(1to1) causing the same issue).
181 # This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
182 # same file is renamed on both sides to the same thing; it should trigger
183 # the 1to2 logic, which it would do if the add-source didn't cause issues
184 # for git's rename detection):
185 # Commit A: new file: a
186 # Commit B: rename a->b
187 # Commit C: rename a->b, add unrelated a
189 test_setup_break_detection_3 () {
190 test_create_repo break-detection-3 &&
192 cd break-detection-3 &&
194 printf "1\n2\n3\n4\n5\n" >a &&
199 git checkout -b B A &&
203 git checkout -b C A &&
211 test_expect_failure 'detect rename/add-source and preserve all data' '
212 test_setup_break_detection_3 &&
214 cd break-detection-3 &&
218 git merge -s recursive C^0 &&
220 git ls-files -s >out &&
221 test_line_count = 2 out &&
222 git ls-files -u >out &&
223 test_line_count = 2 out &&
224 git ls-files -o >out &&
225 test_line_count = 1 out &&
227 test_path_is_file a &&
228 test_path_is_file b &&
230 git rev-parse >expect \
232 git rev-parse >actual \
234 test_cmp expect actual
238 test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
239 test_setup_break_detection_3 &&
241 cd break-detection-3 &&
245 git merge -s recursive B^0 &&
247 git ls-files -s >out &&
248 test_line_count = 2 out &&
249 git ls-files -u >out &&
250 test_line_count = 2 out &&
251 git ls-files -o >out &&
252 test_line_count = 1 out &&
254 test_path_is_file a &&
255 test_path_is_file b &&
257 git rev-parse >expect \
259 git rev-parse >actual \
261 test_cmp expect actual
265 test_setup_rename_directory () {
266 test_create_repo rename-directory-$1 &&
268 cd rename-directory-$1 &&
270 printf "1\n2\n3\n4\n5\n6\n" >file &&
273 git commit -m base &&
276 git checkout -b right &&
279 echo junk >newfile/realfile &&
280 git add file newfile/realfile &&
282 git commit -m right &&
284 git checkout -b left-conflict base &&
287 git mv file newfile &&
289 git commit -m left &&
291 git checkout -b left-clean base &&
293 cat file >>newfile &&
301 test_expect_success 'rename/directory conflict + clean content merge' '
302 test_setup_rename_directory 1a &&
304 cd rename-directory-1a &&
306 git checkout left-clean^0 &&
308 test_must_fail git merge -s recursive right^0 &&
310 git ls-files -s >out &&
311 test_line_count = 2 out &&
312 git ls-files -u >out &&
313 test_line_count = 1 out &&
314 git ls-files -o >out &&
315 test_line_count = 2 out &&
318 git cat-file -p base:file >>expect &&
320 test_cmp expect newfile~HEAD &&
322 test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
324 test_path_is_file newfile/realfile &&
325 test_path_is_file newfile~HEAD
329 test_expect_success 'rename/directory conflict + content merge conflict' '
330 test_setup_rename_directory 1b &&
332 cd rename-directory-1b &&
337 git checkout left-conflict^0 &&
339 test_must_fail git merge -s recursive right^0 &&
341 git ls-files -s >out &&
342 test_line_count = 4 out &&
343 git ls-files -u >out &&
344 test_line_count = 3 out &&
345 git ls-files -o >out &&
346 test_line_count = 2 out &&
348 git cat-file -p left-conflict:newfile >left &&
349 git cat-file -p base:file >base &&
350 git cat-file -p right:file >right &&
351 test_must_fail git merge-file \
356 test_cmp left newfile~HEAD &&
358 git rev-parse >expect \
359 base:file left-conflict:newfile right:file &&
360 git rev-parse >actual \
361 :1:newfile :2:newfile :3:newfile &&
362 test_cmp expect actual &&
364 test_path_is_file newfile/realfile &&
365 test_path_is_file newfile~HEAD
369 test_setup_rename_directory_2 () {
370 test_create_repo rename-directory-2 &&
372 cd rename-directory-2 &&
375 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
378 git commit -m base &&
381 git checkout -b right &&
385 git commit -m right &&
387 git checkout -b left base &&
389 cat sub/file >>newfile &&
398 test_expect_success 'disappearing dir in rename/directory conflict handled' '
399 test_setup_rename_directory_2 &&
401 cd rename-directory-2 &&
403 git checkout left^0 &&
405 git merge -s recursive right^0 &&
407 git ls-files -s >out &&
408 test_line_count = 1 out &&
409 git ls-files -u >out &&
410 test_line_count = 0 out &&
411 git ls-files -o >out &&
412 test_line_count = 1 out &&
415 git cat-file -p base:sub/file >>expect &&
417 test_cmp expect sub &&
419 test_path_is_file sub
423 # Test for basic rename/add-dest conflict, with rename needing content merge:
425 # Commit A: rename a->b, modifying b too
426 # Commit B: modify a, add different b
428 test_setup_rename_with_content_merge_and_add () {
429 test_create_repo rename-with-content-merge-and-add-$1 &&
431 cd rename-with-content-merge-and-add-$1 &&
438 git checkout -b A O &&
444 git checkout -b B O &&
446 echo hello world >b &&
452 test_expect_success 'handle rename-with-content-merge vs. add' '
453 test_setup_rename_with_content_merge_and_add AB &&
455 cd rename-with-content-merge-and-add-AB &&
459 test_must_fail git merge -s recursive B^0 >out &&
460 test_i18ngrep "CONFLICT (rename/add)" out &&
462 git ls-files -s >out &&
463 test_line_count = 2 out &&
464 git ls-files -u >out &&
465 test_line_count = 2 out &&
466 # Also, make sure both unmerged entries are for "b"
467 git ls-files -u b >out &&
468 test_line_count = 2 out &&
469 git ls-files -o >out &&
470 test_line_count = 1 out &&
472 test_path_is_missing a &&
473 test_path_is_file b &&
476 git hash-object tmp >expect &&
477 git rev-parse B:b >>expect &&
478 git rev-parse >actual \
480 test_cmp expect actual &&
482 # Test that the two-way merge in b is as expected
483 git cat-file -p :2:b >>ours &&
484 git cat-file -p :3:b >>theirs &&
486 test_must_fail git merge-file \
495 test_expect_success 'handle rename-with-content-merge vs. add, merge other way' '
496 test_setup_rename_with_content_merge_and_add BA &&
498 cd rename-with-content-merge-and-add-BA &&
505 test_must_fail git merge -s recursive A^0 >out &&
506 test_i18ngrep "CONFLICT (rename/add)" out &&
508 git ls-files -s >out &&
509 test_line_count = 2 out &&
510 git ls-files -u >out &&
511 test_line_count = 2 out &&
512 # Also, make sure both unmerged entries are for "b"
513 git ls-files -u b >out &&
514 test_line_count = 2 out &&
515 git ls-files -o >out &&
516 test_line_count = 1 out &&
518 test_path_is_missing a &&
519 test_path_is_file b &&
522 git rev-parse B:b >expect &&
523 git hash-object tmp >>expect &&
524 git rev-parse >actual \
526 test_cmp expect actual &&
528 # Test that the two-way merge in b is as expected
529 git cat-file -p :2:b >>ours &&
530 git cat-file -p :3:b >>theirs &&
532 test_must_fail git merge-file \
541 # Test for all kinds of things that can go wrong with rename/rename (2to1):
542 # Commit A: new files: a & b
543 # Commit B: rename a->c, modify b
544 # Commit C: rename b->c, modify a
546 # Merging of B & C should NOT be clean. Questions:
547 # * Both a & b should be removed by the merge; are they?
548 # * The two c's should contain modifications to a & b; do they?
549 # * The index should contain two files, both for c; does it?
550 # * The working copy should have two files, both of form c~<unique>; does it?
551 # * Nothing else should be present. Is anything?
553 test_setup_rename_rename_2to1 () {
554 test_create_repo rename-rename-2to1 &&
556 cd rename-rename-2to1 &&
558 printf "1\n2\n3\n4\n5\n" >a &&
559 printf "5\n4\n3\n2\n1\n" >b &&
564 git checkout -b B A &&
570 git checkout -b C A &&
578 test_expect_success 'handle rename/rename (2to1) conflict correctly' '
579 test_setup_rename_rename_2to1 &&
581 cd rename-rename-2to1 &&
585 test_must_fail git merge -s recursive C^0 >out &&
586 test_i18ngrep "CONFLICT (rename/rename)" out &&
588 git ls-files -s >out &&
589 test_line_count = 2 out &&
590 git ls-files -u >out &&
591 test_line_count = 2 out &&
592 git ls-files -u c >out &&
593 test_line_count = 2 out &&
594 git ls-files -o >out &&
595 test_line_count = 1 out &&
597 test_path_is_missing a &&
598 test_path_is_missing b &&
600 git rev-parse >expect \
602 git rev-parse >actual \
604 test_cmp expect actual &&
606 # Test that the two-way merge in new_a is as expected
607 git cat-file -p :2:c >>ours &&
608 git cat-file -p :3:c >>theirs &&
610 test_must_fail git merge-file \
615 git hash-object c >actual &&
616 git hash-object ours >expect &&
617 test_cmp expect actual
621 # Testcase setup for simple rename/rename (1to2) conflict:
622 # Commit A: new file: a
623 # Commit B: rename a->b
624 # Commit C: rename a->c
625 test_setup_rename_rename_1to2 () {
626 test_create_repo rename-rename-1to2 &&
628 cd rename-rename-1to2 &&
636 git checkout -b B A &&
641 git checkout -b C A &&
648 test_expect_success 'merge has correct working tree contents' '
649 test_setup_rename_rename_1to2 &&
651 cd rename-rename-1to2 &&
655 test_must_fail git merge -s recursive B^0 &&
657 git ls-files -s >out &&
658 test_line_count = 3 out &&
659 git ls-files -u >out &&
660 test_line_count = 3 out &&
661 git ls-files -o >out &&
662 test_line_count = 1 out &&
664 test_path_is_missing a &&
665 git rev-parse >expect \
668 git rev-parse >actual \
670 git hash-object >>actual \
672 test_cmp expect actual
676 # Testcase setup for rename/rename(1to2)/add-source conflict:
677 # Commit A: new file: a
678 # Commit B: rename a->b
679 # Commit C: rename a->c, add completely different a
681 # Merging of B & C should NOT be clean; there's a rename/rename conflict
683 test_setup_rename_rename_1to2_add_source_1 () {
684 test_create_repo rename-rename-1to2-add-source-1 &&
686 cd rename-rename-1to2-add-source-1 &&
688 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
693 git checkout -b B A &&
697 git checkout -b C A &&
699 echo something completely different >a &&
705 test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
706 test_setup_rename_rename_1to2_add_source_1 &&
708 cd rename-rename-1to2-add-source-1 &&
712 test_must_fail git merge -s recursive C^0 &&
714 git ls-files -s >out &&
715 test_line_count = 4 out &&
716 git ls-files -o >out &&
717 test_line_count = 1 out &&
719 git rev-parse >expect \
721 git rev-parse >actual \
722 :3:a :1:a :2:b :3:c &&
723 test_cmp expect actual &&
725 test_path_is_file a &&
726 test_path_is_file b &&
731 test_setup_rename_rename_1to2_add_source_2 () {
732 test_create_repo rename-rename-1to2-add-source-2 &&
734 cd rename-rename-1to2-add-source-2 &&
739 git commit -m base &&
742 git checkout -b B A &&
747 git checkout -b C A &&
749 echo important-info >a &&
756 test_expect_failure 'rename/rename/add-source still tracks new a file' '
757 test_setup_rename_rename_1to2_add_source_2 &&
759 cd rename-rename-1to2-add-source-2 &&
762 git merge -s recursive B^0 &&
764 git ls-files -s >out &&
765 test_line_count = 2 out &&
766 git ls-files -o >out &&
767 test_line_count = 1 out &&
769 git rev-parse >expect \
771 git rev-parse >actual \
773 test_cmp expect actual
777 test_setup_rename_rename_1to2_add_dest () {
778 test_create_repo rename-rename-1to2-add-dest &&
780 cd rename-rename-1to2-add-dest &&
785 git commit -m base &&
788 git checkout -b B A &&
790 echo precious-data >c &&
795 git checkout -b C A &&
797 echo important-info >b &&
804 test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
805 test_setup_rename_rename_1to2_add_dest &&
807 cd rename-rename-1to2-add-dest &&
810 test_must_fail git merge -s recursive B^0 &&
812 git ls-files -s >out &&
813 test_line_count = 5 out &&
814 git ls-files -u b >out &&
815 test_line_count = 2 out &&
816 git ls-files -u c >out &&
817 test_line_count = 2 out &&
818 git ls-files -o >out &&
819 test_line_count = 1 out &&
821 git rev-parse >expect \
822 A:a C:b B:b C:c B:c &&
823 git rev-parse >actual \
824 :1:a :2:b :3:b :2:c :3:c &&
825 test_cmp expect actual &&
827 # Record some contents for re-doing merges
828 git cat-file -p A:a >stuff &&
829 git cat-file -p C:b >important_info &&
830 git cat-file -p B:c >precious_data &&
833 # Test the merge in b
834 test_must_fail git merge-file \
838 important_info empty stuff &&
839 test_cmp important_info b &&
841 # Test the merge in c
842 test_must_fail git merge-file \
846 stuff empty precious_data &&
851 # Testcase rad, rename/add/delete
853 # Commit A: rm foo, add different bar
854 # Commit B: rename foo->bar
855 # Expected: CONFLICT (rename/add/delete), two-way merged bar
858 test_create_repo rad &&
861 echo "original file" >foo &&
863 git commit -m "original" &&
871 echo "different file" >bar &&
873 git commit -m "Remove foo, add bar" &&
877 git commit -m "rename foo to bar"
881 test_expect_failure 'rad-check: rename/add/delete conflict' '
887 test_must_fail git merge -s recursive A^0 >out 2>err &&
889 # Not sure whether the output should contain just one
890 # "CONFLICT (rename/add/delete)" line, or if it should break
891 # it into a pair of "CONFLICT (rename/delete)" and
892 # "CONFLICT (rename/add)"; allow for either.
893 test_i18ngrep "CONFLICT (rename.*add)" out &&
894 test_i18ngrep "CONFLICT (rename.*delete)" out &&
895 test_must_be_empty err &&
897 git ls-files -s >file_count &&
898 test_line_count = 2 file_count &&
899 git ls-files -u >file_count &&
900 test_line_count = 2 file_count &&
901 git ls-files -o >file_count &&
902 test_line_count = 2 file_count &&
904 git rev-parse >actual \
906 git rev-parse >expect \
909 test_cmp file_is_missing foo &&
910 # bar should have two-way merged contents of the different
911 # versions of bar; check that content from both sides is
918 # Testcase rrdd, rename/rename(2to1)/delete/delete
920 # Commit A: rename foo->baz, rm bar
921 # Commit B: rename bar->baz, rm foo
922 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
925 test_create_repo rrdd &&
940 git commit -m "Rename foo, remove bar" &&
945 git commit -m "Rename bar, remove foo"
949 test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
955 test_must_fail git merge -s recursive B^0 >out 2>err &&
957 # Not sure whether the output should contain just one
958 # "CONFLICT (rename/rename/delete/delete)" line, or if it
959 # should break it into three: "CONFLICT (rename/rename)" and
960 # two "CONFLICT (rename/delete)" lines; allow for either.
961 test_i18ngrep "CONFLICT (rename/rename)" out &&
962 test_i18ngrep "CONFLICT (rename.*delete)" out &&
963 test_must_be_empty err &&
965 git ls-files -s >file_count &&
966 test_line_count = 2 file_count &&
967 git ls-files -u >file_count &&
968 test_line_count = 2 file_count &&
969 git ls-files -o >file_count &&
970 test_line_count = 2 file_count &&
972 git rev-parse >actual \
974 git rev-parse >expect \
977 test_cmp file_is_missing foo &&
978 test_cmp file_is_missing bar &&
979 # baz should have two-way merged contents of the original
980 # contents of foo and bar; check that content from both sides
987 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
988 # Commit O: one, three, five
989 # Commit A: one->two, three->four, five->six
990 # Commit B: one->six, three->two, five->four
991 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
992 # multi-way merged contents found in two, four, six
995 test_create_repo mod6 &&
998 test_seq 11 19 >one &&
999 test_seq 31 39 >three &&
1000 test_seq 51 59 >five &&
1003 git commit -m "O" &&
1010 test_seq 10 19 >one &&
1012 git add one three &&
1014 git mv three four &&
1017 git commit -m "A" &&
1021 echo forty >>three &&
1023 git add one three five &&
1032 test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
1039 test_must_fail git merge -s recursive B^0 >out 2>err &&
1041 test_i18ngrep "CONFLICT (rename/rename)" out &&
1042 test_must_be_empty err &&
1044 git ls-files -s >file_count &&
1045 test_line_count = 6 file_count &&
1046 git ls-files -u >file_count &&
1047 test_line_count = 6 file_count &&
1048 git ls-files -o >file_count &&
1049 test_line_count = 3 file_count &&
1051 test_seq 10 20 >merged-one &&
1052 test_seq 51 60 >merged-five &&
1053 # Determine what the merge of three would give us.
1054 test_seq 30 40 >three-side-A &&
1055 test_seq 31 39 >three-side-B &&
1056 echo forty >three-side-B &&
1058 test_must_fail git merge-file \
1062 three-side-A empty three-side-B &&
1063 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
1065 # Verify the index is as expected
1066 git rev-parse >actual \
1070 git hash-object >expect \
1071 merged-one merged-three \
1072 merged-three merged-five \
1073 merged-five merged-one &&
1074 test_cmp expect actual &&
1076 git cat-file -p :2:two >expect &&
1077 git cat-file -p :3:two >other &&
1078 test_must_fail git merge-file \
1079 -L "HEAD" -L "" -L "B^0" \
1080 expect empty other &&
1081 test_cmp expect two &&
1083 git cat-file -p :2:four >expect &&
1084 git cat-file -p :3:four >other &&
1085 test_must_fail git merge-file \
1086 -L "HEAD" -L "" -L "B^0" \
1087 expect empty other &&
1088 test_cmp expect four &&
1090 git cat-file -p :2:six >expect &&
1091 git cat-file -p :3:six >other &&
1092 test_must_fail git merge-file \
1093 -L "HEAD" -L "" -L "B^0" \
1094 expect empty other &&
1099 test_conflicts_with_adds_and_renames() {
1111 # Both L and R have files named 'three' which collide. Each of
1112 # the colliding files could have been involved in a rename, in
1113 # which case there was a file named 'one' or 'two' that was
1114 # modified on the opposite side of history and renamed into the
1115 # collision on this side of history.
1118 # 1) The index should contain both a stage 2 and stage 3 entry
1119 # for the colliding file. Does it?
1120 # 2) When renames are involved, the content merges are clean, so
1121 # the index should reflect the content merges, not merely the
1122 # version of the colliding file from the prior commit. Does
1124 # 3) There should be a file in the worktree named 'three'
1125 # containing the two-way merged contents of the content-merged
1126 # versions of 'three' from each of the two colliding
1127 # files. Is it present?
1128 # 4) There should not be any three~* files in the working
1130 test_setup_collision_conflict () {
1131 #test_expect_success "setup simple $sideL/$sideR conflict" '
1132 test_create_repo simple_${sideL}_${sideR} &&
1134 cd simple_${sideL}_${sideR} &&
1136 # Create some related files now
1137 for i in $(test_seq 1 10)
1139 echo Random base content line $i
1141 cp file_v1 file_v2 &&
1142 echo modification >>file_v2 &&
1144 cp file_v1 file_v3 &&
1145 echo more stuff >>file_v3 &&
1146 cp file_v3 file_v4 &&
1147 echo yet more stuff >>file_v4 &&
1149 # Use a tag to record both these files for simple
1150 # access, and clean out these untracked files
1151 git tag file_v1 $(git hash-object -w file_v1) &&
1152 git tag file_v2 $(git hash-object -w file_v2) &&
1153 git tag file_v3 $(git hash-object -w file_v3) &&
1154 git tag file_v4 $(git hash-object -w file_v4) &&
1157 # Setup original commit (or merge-base), consisting of
1158 # files named "one" and "two" if renames were involved.
1159 touch irrelevant_file &&
1160 git add irrelevant_file &&
1161 if [ $sideL = "rename" ]
1163 git show file_v1 >one &&
1166 if [ $sideR = "rename" ]
1168 git show file_v3 >two &&
1171 test_tick && git commit -m initial &&
1176 # Handle the left side
1178 if [ $sideL = "rename" ]
1182 git show file_v2 >three &&
1185 if [ $sideR = "rename" ]
1187 git show file_v4 >two &&
1190 test_tick && git commit -m L &&
1192 # Handle the right side
1194 if [ $sideL = "rename" ]
1196 git show file_v2 >one &&
1199 if [ $sideR = "rename" ]
1203 git show file_v4 >three &&
1206 test_tick && git commit -m R
1211 test_expect_success "check simple $sideL/$sideR conflict" '
1212 test_setup_collision_conflict &&
1214 cd simple_${sideL}_${sideR} &&
1218 # Merge must fail; there is a conflict
1219 test_must_fail git merge -s recursive R^0 &&
1221 # Make sure the index has the right number of entries
1222 git ls-files -s >out &&
1223 test_line_count = 3 out &&
1224 git ls-files -u >out &&
1225 test_line_count = 2 out &&
1226 # Ensure we have the correct number of untracked files
1227 git ls-files -o >out &&
1228 test_line_count = 1 out &&
1230 # Nothing should have touched irrelevant_file
1231 git rev-parse >actual \
1232 :0:irrelevant_file \
1235 git rev-parse >expected \
1236 master:irrelevant_file \
1239 test_cmp expected actual &&
1241 # Make sure we have the correct merged contents for
1243 git show file_v1 >expected &&
1244 cat <<-\EOF >>expected &&
1253 test_cmp expected three
1258 test_conflicts_with_adds_and_renames rename rename
1259 test_conflicts_with_adds_and_renames rename add
1260 test_conflicts_with_adds_and_renames add rename
1261 test_conflicts_with_adds_and_renames add add
1271 # master has two files, named 'one' and 'two'.
1272 # branches L and R both modify 'one', in conflicting ways.
1273 # branches L and R both modify 'two', in conflicting ways.
1274 # branch L also renames 'one' to 'three'.
1275 # branch R also renames 'two' to 'three'.
1277 # So, we have four different conflicting files that all end up at path
1279 test_setup_nested_conflicts_from_rename_rename () {
1280 test_create_repo nested_conflicts_from_rename_rename &&
1282 cd nested_conflicts_from_rename_rename &&
1284 # Create some related files now
1285 for i in $(test_seq 1 10)
1287 echo Random base content line $i
1290 cp file_v1 file_v2 &&
1291 cp file_v1 file_v3 &&
1292 cp file_v1 file_v4 &&
1293 cp file_v1 file_v5 &&
1294 cp file_v1 file_v6 &&
1296 echo one >>file_v1 &&
1297 echo uno >>file_v2 &&
1298 echo eins >>file_v3 &&
1300 echo two >>file_v4 &&
1301 echo dos >>file_v5 &&
1302 echo zwei >>file_v6 &&
1304 # Setup original commit (or merge-base), consisting of
1305 # files named "one" and "two".
1309 test_tick && git commit -m english &&
1314 # Handle the left side
1317 mv -f file_v2 three &&
1318 mv -f file_v5 two &&
1319 git add two three &&
1320 test_tick && git commit -m spanish &&
1322 # Handle the right side
1325 mv -f file_v3 one &&
1326 mv -f file_v6 three &&
1327 git add one three &&
1328 test_tick && git commit -m german
1332 test_expect_success 'check nested conflicts from rename/rename(2to1)' '
1333 test_setup_nested_conflicts_from_rename_rename &&
1335 cd nested_conflicts_from_rename_rename &&
1339 # Merge must fail; there is a conflict
1340 test_must_fail git merge -s recursive R^0 &&
1342 # Make sure the index has the right number of entries
1343 git ls-files -s >out &&
1344 test_line_count = 2 out &&
1345 git ls-files -u >out &&
1346 test_line_count = 2 out &&
1347 # Ensure we have the correct number of untracked files
1348 git ls-files -o >out &&
1349 test_line_count = 1 out &&
1351 # Compare :2:three to expected values
1352 git cat-file -p master:one >base &&
1353 git cat-file -p L:three >ours &&
1354 git cat-file -p R:one >theirs &&
1355 test_must_fail git merge-file \
1356 -L "HEAD:three" -L "" -L "R^0:one" \
1358 sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
1359 git cat-file -p :2:three >expect &&
1360 test_cmp expect L-three &&
1362 # Compare :2:three to expected values
1363 git cat-file -p master:two >base &&
1364 git cat-file -p L:two >ours &&
1365 git cat-file -p R:three >theirs &&
1366 test_must_fail git merge-file \
1367 -L "HEAD:two" -L "" -L "R^0:three" \
1369 sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
1370 git cat-file -p :3:three >expect &&
1371 test_cmp expect R-three &&
1373 # Compare three to expected contents
1375 test_must_fail git merge-file \
1376 -L "HEAD" -L "" -L "R^0" \
1377 L-three empty R-three &&
1378 test_cmp three L-three
1382 # Testcase rename/rename(1to2) of a binary file
1386 # Expected: CONFLICT(rename/rename) message, three unstaged entries in the
1387 # index, and contents of orig-[AB] at path orig-[AB]
1388 test_setup_rename_rename_1_to_2_binary () {
1389 test_create_repo rename_rename_1_to_2_binary &&
1391 cd rename_rename_1_to_2_binary &&
1393 echo '* binary' >.gitattributes &&
1394 git add .gitattributes &&
1396 test_seq 1 10 >orig &&
1398 git commit -m orig &&
1404 git mv orig orig-A &&
1405 test_seq 1 11 >orig-A &&
1407 git commit -m orig-A &&
1410 git mv orig orig-B &&
1411 test_seq 0 10 >orig-B &&
1413 git commit -m orig-B
1418 test_expect_success 'rename/rename(1to2) with a binary file' '
1419 test_setup_rename_rename_1_to_2_binary &&
1421 cd rename_rename_1_to_2_binary &&
1425 test_must_fail git merge -s recursive B^0 &&
1427 # Make sure the index has the right number of entries
1428 git ls-files -s >actual &&
1429 test_line_count = 4 actual &&
1431 git rev-parse A:orig-A B:orig-B >expect &&
1432 git hash-object orig-A orig-B >actual &&
1433 test_cmp expect actual