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_expect_success
'setup rename/delete + untracked file' '
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?" '
36 cd rename-delete-untracked &&
38 test_must_fail git merge -s recursive rename-the-ring &&
40 # Make sure git did not delete an untracked file
41 test_path_is_file ring
45 # Testcase setup for rename/modify/add-source:
46 # Commit A: new file: a
47 # Commit B: modify a slightly
48 # Commit C: rename a->b, add completely different a
50 # We should be able to merge B & C cleanly
52 test_expect_success
'setup rename/modify/add-source conflict' '
53 test_create_repo rename-modify-add-source &&
55 cd rename-modify-add-source &&
57 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
62 git checkout -b B A &&
67 git checkout -b C A &&
69 echo something completely different >a &&
75 test_expect_failure
'rename/modify/add-source conflict resolvable' '
77 cd rename-modify-add-source &&
81 git merge -s recursive C^0 &&
83 git rev-parse >expect \
85 git rev-parse >actual \
87 test_cmp expect actual
91 test_expect_success
'setup resolvable conflict missed if rename missed' '
92 test_create_repo break-detection-1 &&
94 cd break-detection-1 &&
96 printf "1\n2\n3\n4\n5\n" >a &&
102 git checkout -b B A &&
104 echo "Completely different content" >a &&
108 git checkout -b C A &&
115 test_expect_failure
'conflict caused if rename not detected' '
117 cd break-detection-1 &&
119 git checkout -q C^0 &&
120 git merge -s recursive B^0 &&
122 git ls-files -s >out &&
123 test_line_count = 3 out &&
124 git ls-files -u >out &&
125 test_line_count = 0 out &&
126 git ls-files -o >out &&
127 test_line_count = 1 out &&
129 test_line_count = 6 c &&
130 git rev-parse >expect \
132 git rev-parse >actual \
134 test_cmp expect actual
138 test_expect_success
'setup conflict resolved wrong if rename missed' '
139 test_create_repo break-detection-2 &&
141 cd break-detection-2 &&
143 printf "1\n2\n3\n4\n5\n" >a &&
149 git checkout -b D A &&
153 echo "Completely different content" >a &&
157 git checkout -b E A &&
159 echo "Completely different content" >>a &&
165 test_expect_failure
'missed conflict if rename not detected' '
167 cd break-detection-2 &&
169 git checkout -q E^0 &&
170 test_must_fail git merge -s recursive D^0
174 # Tests for undetected rename/add-source causing a file to erroneously be
175 # deleted (and for mishandled rename/rename(1to1) causing the same issue).
177 # This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
178 # same file is renamed on both sides to the same thing; it should trigger
179 # the 1to2 logic, which it would do if the add-source didn't cause issues
180 # for git's rename detection):
181 # Commit A: new file: a
182 # Commit B: rename a->b
183 # Commit C: rename a->b, add unrelated a
185 test_expect_success
'setup undetected rename/add-source causes data loss' '
186 test_create_repo break-detection-3 &&
188 cd break-detection-3 &&
190 printf "1\n2\n3\n4\n5\n" >a &&
195 git checkout -b B A &&
199 git checkout -b C A &&
207 test_expect_failure
'detect rename/add-source and preserve all data' '
209 cd break-detection-3 &&
213 git merge -s recursive C^0 &&
215 git ls-files -s >out &&
216 test_line_count = 2 out &&
217 git ls-files -u >out &&
218 test_line_count = 2 out &&
219 git ls-files -o >out &&
220 test_line_count = 1 out &&
222 test_path_is_file a &&
223 test_path_is_file b &&
225 git rev-parse >expect \
227 git rev-parse >actual \
229 test_cmp expect actual
233 test_expect_failure
'detect rename/add-source and preserve all data, merge other way' '
235 cd break-detection-3 &&
239 git merge -s recursive B^0 &&
241 git ls-files -s >out &&
242 test_line_count = 2 out &&
243 git ls-files -u >out &&
244 test_line_count = 2 out &&
245 git ls-files -o >out &&
246 test_line_count = 1 out &&
248 test_path_is_file a &&
249 test_path_is_file b &&
251 git rev-parse >expect \
253 git rev-parse >actual \
255 test_cmp expect actual
259 test_expect_success
'setup content merge + rename/directory conflict' '
260 test_create_repo rename-directory-1 &&
262 cd rename-directory-1 &&
264 printf "1\n2\n3\n4\n5\n6\n" >file &&
267 git commit -m base &&
270 git checkout -b right &&
273 echo junk >newfile/realfile &&
274 git add file newfile/realfile &&
276 git commit -m right &&
278 git checkout -b left-conflict base &&
281 git mv file newfile &&
283 git commit -m left &&
285 git checkout -b left-clean base &&
287 cat file >>newfile &&
295 test_expect_success
'rename/directory conflict + clean content merge' '
297 cd rename-directory-1 &&
299 git checkout left-clean^0 &&
301 test_must_fail git merge -s recursive right^0 &&
303 git ls-files -s >out &&
304 test_line_count = 2 out &&
305 git ls-files -u >out &&
306 test_line_count = 1 out &&
307 git ls-files -o >out &&
308 test_line_count = 2 out &&
311 git cat-file -p base:file >>expect &&
313 test_cmp expect newfile~HEAD &&
315 test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
317 test_path_is_file newfile/realfile &&
318 test_path_is_file newfile~HEAD
322 test_expect_success
'rename/directory conflict + content merge conflict' '
324 cd rename-directory-1 &&
329 git checkout left-conflict^0 &&
331 test_must_fail git merge -s recursive right^0 &&
333 git ls-files -s >out &&
334 test_line_count = 4 out &&
335 git ls-files -u >out &&
336 test_line_count = 3 out &&
337 git ls-files -o >out &&
338 test_line_count = 2 out &&
340 git cat-file -p left-conflict:newfile >left &&
341 git cat-file -p base:file >base &&
342 git cat-file -p right:file >right &&
343 test_must_fail git merge-file \
348 test_cmp left newfile~HEAD &&
350 git rev-parse >expect \
351 base:file left-conflict:newfile right:file &&
352 git rev-parse >actual \
353 :1:newfile :2:newfile :3:newfile &&
354 test_cmp expect actual &&
356 test_path_is_file newfile/realfile &&
357 test_path_is_file newfile~HEAD
361 test_expect_success
'setup content merge + rename/directory conflict w/ disappearing dir' '
362 test_create_repo rename-directory-2 &&
364 cd rename-directory-2 &&
367 printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
370 git commit -m base &&
373 git checkout -b right &&
377 git commit -m right &&
379 git checkout -b left base &&
381 cat sub/file >>newfile &&
390 test_expect_success
'disappearing dir in rename/directory conflict handled' '
392 cd rename-directory-2 &&
394 git checkout left^0 &&
396 git merge -s recursive right^0 &&
398 git ls-files -s >out &&
399 test_line_count = 1 out &&
400 git ls-files -u >out &&
401 test_line_count = 0 out &&
402 git ls-files -o >out &&
403 test_line_count = 1 out &&
406 git cat-file -p base:sub/file >>expect &&
408 test_cmp expect sub &&
410 test_path_is_file sub
414 # Test for basic rename/add-dest conflict, with rename needing content merge:
416 # Commit A: rename a->b, modifying b too
417 # Commit B: modify a, add different b
419 test_expect_success
'setup rename-with-content-merge vs. add' '
420 test_create_repo rename-with-content-merge-and-add &&
422 cd rename-with-content-merge-and-add &&
429 git checkout -b A O &&
435 git checkout -b B O &&
437 echo hello world >b &&
443 test_expect_success
'handle rename-with-content-merge vs. add' '
445 cd rename-with-content-merge-and-add &&
449 test_must_fail git merge -s recursive B^0 >out &&
450 test_i18ngrep "CONFLICT (rename/add)" out &&
452 git ls-files -s >out &&
453 test_line_count = 2 out &&
454 git ls-files -u >out &&
455 test_line_count = 2 out &&
456 # Also, make sure both unmerged entries are for "b"
457 git ls-files -u b >out &&
458 test_line_count = 2 out &&
459 git ls-files -o >out &&
460 test_line_count = 1 out &&
462 test_path_is_missing a &&
463 test_path_is_file b &&
466 git hash-object tmp >expect &&
467 git rev-parse B:b >>expect &&
468 git rev-parse >actual \
470 test_cmp expect actual &&
472 # Test that the two-way merge in b is as expected
473 git cat-file -p :2:b >>ours &&
474 git cat-file -p :3:b >>theirs &&
476 test_must_fail git merge-file \
485 test_expect_success
'handle rename-with-content-merge vs. add, merge other way' '
487 cd rename-with-content-merge-and-add &&
494 test_must_fail git merge -s recursive A^0 >out &&
495 test_i18ngrep "CONFLICT (rename/add)" out &&
497 git ls-files -s >out &&
498 test_line_count = 2 out &&
499 git ls-files -u >out &&
500 test_line_count = 2 out &&
501 # Also, make sure both unmerged entries are for "b"
502 git ls-files -u b >out &&
503 test_line_count = 2 out &&
504 git ls-files -o >out &&
505 test_line_count = 1 out &&
507 test_path_is_missing a &&
508 test_path_is_file b &&
511 git rev-parse B:b >expect &&
512 git hash-object tmp >>expect &&
513 git rev-parse >actual \
515 test_cmp expect actual &&
517 # Test that the two-way merge in b is as expected
518 git cat-file -p :2:b >>ours &&
519 git cat-file -p :3:b >>theirs &&
521 test_must_fail git merge-file \
530 # Test for all kinds of things that can go wrong with rename/rename (2to1):
531 # Commit A: new files: a & b
532 # Commit B: rename a->c, modify b
533 # Commit C: rename b->c, modify a
535 # Merging of B & C should NOT be clean. Questions:
536 # * Both a & b should be removed by the merge; are they?
537 # * The two c's should contain modifications to a & b; do they?
538 # * The index should contain two files, both for c; does it?
539 # * The working copy should have two files, both of form c~<unique>; does it?
540 # * Nothing else should be present. Is anything?
542 test_expect_success
'setup rename/rename (2to1) + modify/modify' '
543 test_create_repo rename-rename-2to1 &&
545 cd rename-rename-2to1 &&
547 printf "1\n2\n3\n4\n5\n" >a &&
548 printf "5\n4\n3\n2\n1\n" >b &&
553 git checkout -b B A &&
559 git checkout -b C A &&
567 test_expect_success
'handle rename/rename (2to1) conflict correctly' '
569 cd rename-rename-2to1 &&
573 test_must_fail git merge -s recursive C^0 >out &&
574 test_i18ngrep "CONFLICT (rename/rename)" out &&
576 git ls-files -s >out &&
577 test_line_count = 2 out &&
578 git ls-files -u >out &&
579 test_line_count = 2 out &&
580 git ls-files -u c >out &&
581 test_line_count = 2 out &&
582 git ls-files -o >out &&
583 test_line_count = 1 out &&
585 test_path_is_missing a &&
586 test_path_is_missing b &&
588 git rev-parse >expect \
590 git rev-parse >actual \
592 test_cmp expect actual &&
594 # Test that the two-way merge in new_a is as expected
595 git cat-file -p :2:c >>ours &&
596 git cat-file -p :3:c >>theirs &&
598 test_must_fail git merge-file \
603 git hash-object c >actual &&
604 git hash-object ours >expect &&
605 test_cmp expect actual
609 # Testcase setup for simple rename/rename (1to2) conflict:
610 # Commit A: new file: a
611 # Commit B: rename a->b
612 # Commit C: rename a->c
613 test_expect_success
'setup simple rename/rename (1to2) conflict' '
614 test_create_repo rename-rename-1to2 &&
616 cd rename-rename-1to2 &&
624 git checkout -b B A &&
629 git checkout -b C A &&
636 test_expect_success
'merge has correct working tree contents' '
638 cd rename-rename-1to2 &&
642 test_must_fail git merge -s recursive B^0 &&
644 git ls-files -s >out &&
645 test_line_count = 3 out &&
646 git ls-files -u >out &&
647 test_line_count = 3 out &&
648 git ls-files -o >out &&
649 test_line_count = 1 out &&
651 test_path_is_missing a &&
652 git rev-parse >expect \
655 git rev-parse >actual \
657 git hash-object >>actual \
659 test_cmp expect actual
663 # Testcase setup for rename/rename(1to2)/add-source conflict:
664 # Commit A: new file: a
665 # Commit B: rename a->b
666 # Commit C: rename a->c, add completely different a
668 # Merging of B & C should NOT be clean; there's a rename/rename conflict
670 test_expect_success
'setup rename/rename(1to2)/add-source conflict' '
671 test_create_repo rename-rename-1to2-add-source-1 &&
673 cd rename-rename-1to2-add-source-1 &&
675 printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
680 git checkout -b B A &&
684 git checkout -b C A &&
686 echo something completely different >a &&
692 test_expect_failure
'detect conflict with rename/rename(1to2)/add-source merge' '
694 cd rename-rename-1to2-add-source-1 &&
698 test_must_fail git merge -s recursive C^0 &&
700 git ls-files -s >out &&
701 test_line_count = 4 out &&
702 git ls-files -o >out &&
703 test_line_count = 1 out &&
705 git rev-parse >expect \
707 git rev-parse >actual \
708 :3:a :1:a :2:b :3:c &&
709 test_cmp expect actual &&
711 test_path_is_file a &&
712 test_path_is_file b &&
717 test_expect_success
'setup rename/rename(1to2)/add-source resolvable conflict' '
718 test_create_repo rename-rename-1to2-add-source-2 &&
720 cd rename-rename-1to2-add-source-2 &&
725 git commit -m base &&
728 git checkout -b B A &&
733 git checkout -b C A &&
735 echo important-info >a &&
742 test_expect_failure
'rename/rename/add-source still tracks new a file' '
744 cd rename-rename-1to2-add-source-2 &&
747 git merge -s recursive B^0 &&
749 git ls-files -s >out &&
750 test_line_count = 2 out &&
751 git ls-files -o >out &&
752 test_line_count = 1 out &&
754 git rev-parse >expect \
756 git rev-parse >actual \
758 test_cmp expect actual
762 test_expect_success
'setup rename/rename(1to2)/add-dest conflict' '
763 test_create_repo rename-rename-1to2-add-dest &&
765 cd rename-rename-1to2-add-dest &&
770 git commit -m base &&
773 git checkout -b B A &&
775 echo precious-data >c &&
780 git checkout -b C A &&
782 echo important-info >b &&
789 test_expect_success
'rename/rename/add-dest merge still knows about conflicting file versions' '
791 cd rename-rename-1to2-add-dest &&
794 test_must_fail git merge -s recursive B^0 &&
796 git ls-files -s >out &&
797 test_line_count = 5 out &&
798 git ls-files -u b >out &&
799 test_line_count = 2 out &&
800 git ls-files -u c >out &&
801 test_line_count = 2 out &&
802 git ls-files -o >out &&
803 test_line_count = 1 out &&
805 git rev-parse >expect \
806 A:a C:b B:b C:c B:c &&
807 git rev-parse >actual \
808 :1:a :2:b :3:b :2:c :3:c &&
809 test_cmp expect actual &&
811 # Record some contents for re-doing merges
812 git cat-file -p A:a >stuff &&
813 git cat-file -p C:b >important_info &&
814 git cat-file -p B:c >precious_data &&
817 # Test the merge in b
818 test_must_fail git merge-file \
822 important_info empty stuff &&
823 test_cmp important_info b &&
825 # Test the merge in c
826 test_must_fail git merge-file \
830 stuff empty precious_data &&
835 # Testcase rad, rename/add/delete
837 # Commit A: rm foo, add different bar
838 # Commit B: rename foo->bar
839 # Expected: CONFLICT (rename/add/delete), two-way merged bar
841 test_expect_success
'rad-setup: rename/add/delete conflict' '
842 test_create_repo rad &&
845 echo "original file" >foo &&
847 git commit -m "original" &&
855 echo "different file" >bar &&
857 git commit -m "Remove foo, add bar" &&
861 git commit -m "rename foo to bar"
865 test_expect_failure
'rad-check: rename/add/delete conflict' '
870 test_must_fail git merge -s recursive A^0 >out 2>err &&
872 # Not sure whether the output should contain just one
873 # "CONFLICT (rename/add/delete)" line, or if it should break
874 # it into a pair of "CONFLICT (rename/delete)" and
875 # "CONFLICT (rename/add)"; allow for either.
876 test_i18ngrep "CONFLICT (rename.*add)" out &&
877 test_i18ngrep "CONFLICT (rename.*delete)" out &&
878 test_must_be_empty err &&
880 git ls-files -s >file_count &&
881 test_line_count = 2 file_count &&
882 git ls-files -u >file_count &&
883 test_line_count = 2 file_count &&
884 git ls-files -o >file_count &&
885 test_line_count = 2 file_count &&
887 git rev-parse >actual \
889 git rev-parse >expect \
892 test_cmp file_is_missing foo &&
893 # bar should have two-way merged contents of the different
894 # versions of bar; check that content from both sides is
901 # Testcase rrdd, rename/rename(2to1)/delete/delete
903 # Commit A: rename foo->baz, rm bar
904 # Commit B: rename bar->baz, rm foo
905 # Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
907 test_expect_success
'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
908 test_create_repo rrdd &&
923 git commit -m "Rename foo, remove bar" &&
928 git commit -m "Rename bar, remove foo"
932 test_expect_failure
'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
937 test_must_fail git merge -s recursive B^0 >out 2>err &&
939 # Not sure whether the output should contain just one
940 # "CONFLICT (rename/rename/delete/delete)" line, or if it
941 # should break it into three: "CONFLICT (rename/rename)" and
942 # two "CONFLICT (rename/delete)" lines; allow for either.
943 test_i18ngrep "CONFLICT (rename/rename)" out &&
944 test_i18ngrep "CONFLICT (rename.*delete)" out &&
945 test_must_be_empty err &&
947 git ls-files -s >file_count &&
948 test_line_count = 2 file_count &&
949 git ls-files -u >file_count &&
950 test_line_count = 2 file_count &&
951 git ls-files -o >file_count &&
952 test_line_count = 2 file_count &&
954 git rev-parse >actual \
956 git rev-parse >expect \
959 test_cmp file_is_missing foo &&
960 test_cmp file_is_missing bar &&
961 # baz should have two-way merged contents of the original
962 # contents of foo and bar; check that content from both sides
969 # Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
970 # Commit O: one, three, five
971 # Commit A: one->two, three->four, five->six
972 # Commit B: one->six, three->two, five->four
973 # Expected: six CONFLICT(rename/rename) messages, each path in two of the
974 # multi-way merged contents found in two, four, six
976 test_expect_success
'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
977 test_create_repo mod6 &&
980 test_seq 11 19 >one &&
981 test_seq 31 39 >three &&
982 test_seq 51 59 >five &&
992 test_seq 10 19 >one &&
1003 echo forty >>three &&
1005 git add one three five &&
1014 test_expect_failure
'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
1020 test_must_fail git merge -s recursive B^0 >out 2>err &&
1022 test_i18ngrep "CONFLICT (rename/rename)" out &&
1023 test_must_be_empty err &&
1025 git ls-files -s >file_count &&
1026 test_line_count = 6 file_count &&
1027 git ls-files -u >file_count &&
1028 test_line_count = 6 file_count &&
1029 git ls-files -o >file_count &&
1030 test_line_count = 3 file_count &&
1032 test_seq 10 20 >merged-one &&
1033 test_seq 51 60 >merged-five &&
1034 # Determine what the merge of three would give us.
1035 test_seq 30 40 >three-side-A &&
1036 test_seq 31 39 >three-side-B &&
1037 echo forty >three-side-B &&
1039 test_must_fail git merge-file \
1043 three-side-A empty three-side-B &&
1044 sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
1046 # Verify the index is as expected
1047 git rev-parse >actual \
1051 git hash-object >expect \
1052 merged-one merged-three \
1053 merged-three merged-five \
1054 merged-five merged-one &&
1055 test_cmp expect actual &&
1057 git cat-file -p :2:two >expect &&
1058 git cat-file -p :3:two >other &&
1059 test_must_fail git merge-file \
1060 -L "HEAD" -L "" -L "B^0" \
1061 expect empty other &&
1062 test_cmp expect two &&
1064 git cat-file -p :2:four >expect &&
1065 git cat-file -p :3:four >other &&
1066 test_must_fail git merge-file \
1067 -L "HEAD" -L "" -L "B^0" \
1068 expect empty other &&
1069 test_cmp expect four &&
1071 git cat-file -p :2:six >expect &&
1072 git cat-file -p :3:six >other &&
1073 test_must_fail git merge-file \
1074 -L "HEAD" -L "" -L "B^0" \
1075 expect empty other &&
1080 test_conflicts_with_adds_and_renames
() {
1092 # Both L and R have files named 'three' which collide. Each of
1093 # the colliding files could have been involved in a rename, in
1094 # which case there was a file named 'one' or 'two' that was
1095 # modified on the opposite side of history and renamed into the
1096 # collision on this side of history.
1099 # 1) The index should contain both a stage 2 and stage 3 entry
1100 # for the colliding file. Does it?
1101 # 2) When renames are involved, the content merges are clean, so
1102 # the index should reflect the content merges, not merely the
1103 # version of the colliding file from the prior commit. Does
1105 # 3) There should be a file in the worktree named 'three'
1106 # containing the two-way merged contents of the content-merged
1107 # versions of 'three' from each of the two colliding
1108 # files. Is it present?
1109 # 4) There should not be any three~* files in the working
1111 test_expect_success
"setup simple $sideL/$sideR conflict" '
1112 test_create_repo simple_${sideL}_${sideR} &&
1114 cd simple_${sideL}_${sideR} &&
1116 # Create some related files now
1117 for i in $(test_seq 1 10)
1119 echo Random base content line $i
1121 cp file_v1 file_v2 &&
1122 echo modification >>file_v2 &&
1124 cp file_v1 file_v3 &&
1125 echo more stuff >>file_v3 &&
1126 cp file_v3 file_v4 &&
1127 echo yet more stuff >>file_v4 &&
1129 # Use a tag to record both these files for simple
1130 # access, and clean out these untracked files
1131 git tag file_v1 $(git hash-object -w file_v1) &&
1132 git tag file_v2 $(git hash-object -w file_v2) &&
1133 git tag file_v3 $(git hash-object -w file_v3) &&
1134 git tag file_v4 $(git hash-object -w file_v4) &&
1137 # Setup original commit (or merge-base), consisting of
1138 # files named "one" and "two" if renames were involved.
1139 touch irrelevant_file &&
1140 git add irrelevant_file &&
1141 if [ $sideL = "rename" ]
1143 git show file_v1 >one &&
1146 if [ $sideR = "rename" ]
1148 git show file_v3 >two &&
1151 test_tick && git commit -m initial &&
1156 # Handle the left side
1158 if [ $sideL = "rename" ]
1162 git show file_v2 >three &&
1165 if [ $sideR = "rename" ]
1167 git show file_v4 >two &&
1170 test_tick && git commit -m L &&
1172 # Handle the right side
1174 if [ $sideL = "rename" ]
1176 git show file_v2 >one &&
1179 if [ $sideR = "rename" ]
1183 git show file_v4 >three &&
1186 test_tick && git commit -m R
1190 test_expect_success
"check simple $sideL/$sideR conflict" '
1192 cd simple_${sideL}_${sideR} &&
1196 # Merge must fail; there is a conflict
1197 test_must_fail git merge -s recursive R^0 &&
1199 # Make sure the index has the right number of entries
1200 git ls-files -s >out &&
1201 test_line_count = 3 out &&
1202 git ls-files -u >out &&
1203 test_line_count = 2 out &&
1204 # Ensure we have the correct number of untracked files
1205 git ls-files -o >out &&
1206 test_line_count = 1 out &&
1208 # Nothing should have touched irrelevant_file
1209 git rev-parse >actual \
1210 :0:irrelevant_file \
1213 git rev-parse >expected \
1214 master:irrelevant_file \
1217 test_cmp expected actual &&
1219 # Make sure we have the correct merged contents for
1221 git show file_v1 >expected &&
1222 cat <<-\EOF >>expected &&
1231 test_cmp expected three
1236 test_conflicts_with_adds_and_renames rename rename
1237 test_conflicts_with_adds_and_renames rename add
1238 test_conflicts_with_adds_and_renames add rename
1239 test_conflicts_with_adds_and_renames add add
1249 # master has two files, named 'one' and 'two'.
1250 # branches L and R both modify 'one', in conflicting ways.
1251 # branches L and R both modify 'two', in conflicting ways.
1252 # branch L also renames 'one' to 'three'.
1253 # branch R also renames 'two' to 'three'.
1255 # So, we have four different conflicting files that all end up at path
1257 test_expect_success
'setup nested conflicts from rename/rename(2to1)' '
1258 test_create_repo nested_conflicts_from_rename_rename &&
1260 cd nested_conflicts_from_rename_rename &&
1262 # Create some related files now
1263 for i in $(test_seq 1 10)
1265 echo Random base content line $i
1268 cp file_v1 file_v2 &&
1269 cp file_v1 file_v3 &&
1270 cp file_v1 file_v4 &&
1271 cp file_v1 file_v5 &&
1272 cp file_v1 file_v6 &&
1274 echo one >>file_v1 &&
1275 echo uno >>file_v2 &&
1276 echo eins >>file_v3 &&
1278 echo two >>file_v4 &&
1279 echo dos >>file_v5 &&
1280 echo zwei >>file_v6 &&
1282 # Setup original commit (or merge-base), consisting of
1283 # files named "one" and "two".
1287 test_tick && git commit -m english &&
1292 # Handle the left side
1295 mv -f file_v2 three &&
1296 mv -f file_v5 two &&
1297 git add two three &&
1298 test_tick && git commit -m spanish &&
1300 # Handle the right side
1303 mv -f file_v3 one &&
1304 mv -f file_v6 three &&
1305 git add one three &&
1306 test_tick && git commit -m german
1310 test_expect_success
'check nested conflicts from rename/rename(2to1)' '
1312 cd nested_conflicts_from_rename_rename &&
1316 # Merge must fail; there is a conflict
1317 test_must_fail git merge -s recursive R^0 &&
1319 # Make sure the index has the right number of entries
1320 git ls-files -s >out &&
1321 test_line_count = 2 out &&
1322 git ls-files -u >out &&
1323 test_line_count = 2 out &&
1324 # Ensure we have the correct number of untracked files
1325 git ls-files -o >out &&
1326 test_line_count = 1 out &&
1328 # Compare :2:three to expected values
1329 git cat-file -p master:one >base &&
1330 git cat-file -p L:three >ours &&
1331 git cat-file -p R:one >theirs &&
1332 test_must_fail git merge-file \
1333 -L "HEAD:three" -L "" -L "R^0:one" \
1335 sed -e "s/^\([<=>]\)/\1\1/" ours >L-three &&
1336 git cat-file -p :2:three >expect &&
1337 test_cmp expect L-three &&
1339 # Compare :2:three to expected values
1340 git cat-file -p master:two >base &&
1341 git cat-file -p L:two >ours &&
1342 git cat-file -p R:three >theirs &&
1343 test_must_fail git merge-file \
1344 -L "HEAD:two" -L "" -L "R^0:three" \
1346 sed -e "s/^\([<=>]\)/\1\1/" ours >R-three &&
1347 git cat-file -p :3:three >expect &&
1348 test_cmp expect R-three &&
1350 # Compare three to expected contents
1352 test_must_fail git merge-file \
1353 -L "HEAD" -L "" -L "R^0" \
1354 L-three empty R-three &&
1355 test_cmp three L-three