3 test_description="recursive merge with directory renames"
4 # includes checking of many corner cases, with a similar methodology to:
5 # t6042: corner cases with renames but not criss-cross merges
6 # t6036: corner cases with both renames and criss-cross merges
8 # The setup for all of them, pictorially, is:
18 # To help make it easier to follow the flow of tests, they have been
19 # divided into sections and each test will start with a quick explanation
20 # of what commits O, A, and B contain.
23 # z/{b,c} means files z/b and z/c both exist
24 # x/d_1 means file x/d exists with content d1. (Purpose of the
25 # underscore notation is to differentiate different
26 # files that might be renamed into each other's paths.)
31 ###########################################################################
32 # SECTION 1: Basic cases we should be able to handle
33 ###########################################################################
35 # Testcase 1a, Basic directory rename.
38 # Commit B: z/{b,c,d,e/f}
39 # Expected: y/{b,c,d,e/f}
41 test_expect_success '1a-setup: Simple directory rename detection' '
42 test_create_repo 1a &&
72 test_expect_success '1a-check: Simple directory rename detection' '
78 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
80 git ls-files -s >out &&
81 test_line_count = 4 out &&
83 git rev-parse >actual \
84 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
85 git rev-parse >expect \
86 O:z/b O:z/c B:z/d B:z/e/f &&
87 test_cmp expect actual &&
89 git hash-object y/d >actual &&
90 git rev-parse B:z/d >expect &&
91 test_cmp expect actual &&
93 test_must_fail git rev-parse HEAD:z/d &&
94 test_must_fail git rev-parse HEAD:z/e/f &&
95 test_path_is_missing z/d &&
96 test_path_is_missing z/e/f
100 # Testcase 1b, Merge a directory with another
101 # Commit O: z/{b,c}, y/d
102 # Commit A: z/{b,c,e}, y/d
103 # Commit B: y/{b,c,d}
104 # Expected: y/{b,c,d,e}
106 test_expect_success '1b-setup: Merge a directory with another' '
107 test_create_repo 1b &&
139 test_expect_success '1b-check: Merge a directory with another' '
145 git -c merge.directoryRenames=true merge -s recursive B^0 &&
147 git ls-files -s >out &&
148 test_line_count = 4 out &&
150 git rev-parse >actual \
151 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
152 git rev-parse >expect \
153 O:z/b O:z/c O:y/d A:z/e &&
154 test_cmp expect actual &&
155 test_must_fail git rev-parse HEAD:z/e
159 # Testcase 1c, Transitive renaming
160 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
161 # (Related to testcases 9c and 9d -- can transitivity repeat?)
162 # (Related to testcase 12b -- joint-transitivity?)
163 # Commit O: z/{b,c}, x/d
164 # Commit A: y/{b,c}, x/d
165 # Commit B: z/{b,c,d}
166 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
168 test_expect_success '1c-setup: Transitive renaming' '
169 test_create_repo 1c &&
198 test_expect_success '1c-check: Transitive renaming' '
204 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
206 git ls-files -s >out &&
207 test_line_count = 3 out &&
209 git rev-parse >actual \
210 HEAD:y/b HEAD:y/c HEAD:y/d &&
211 git rev-parse >expect \
213 test_cmp expect actual &&
214 test_must_fail git rev-parse HEAD:x/d &&
215 test_must_fail git rev-parse HEAD:z/d &&
216 test_path_is_missing z/d
220 # Testcase 1d, Directory renames (merging two directories into one new one)
221 # cause a rename/rename(2to1) conflict
222 # (Related to testcases 1c and 7b)
223 # Commit O. z/{b,c}, y/{d,e}
224 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
225 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
226 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
227 # Note: y/m & z/n should definitely move into x. By the same token, both
228 # y/wham_1 & z/wham_2 should too...giving us a conflict.
230 test_expect_success '1d-setup: Directory renames cause a rename/rename(2to1) conflict' '
231 test_create_repo 1d &&
252 echo wham1 >y/wham &&
260 echo wham2 >z/wham &&
267 test_expect_success '1d-check: Directory renames cause a rename/rename(2to1) conflict' '
273 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
274 test_i18ngrep "CONFLICT (rename/rename)" out &&
276 git ls-files -s >out &&
277 test_line_count = 8 out &&
278 git ls-files -u >out &&
279 test_line_count = 2 out &&
280 git ls-files -o >out &&
281 test_line_count = 1 out &&
283 git rev-parse >actual \
284 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
285 git rev-parse >expect \
286 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
287 test_cmp expect actual &&
289 test_must_fail git rev-parse :0:x/wham &&
290 git rev-parse >actual \
291 :2:x/wham :3:x/wham &&
292 git rev-parse >expect \
294 test_cmp expect actual &&
296 # Test that the two-way merge in x/wham is as expected
297 git cat-file -p :2:x/wham >expect &&
298 git cat-file -p :3:x/wham >other &&
300 test_must_fail git merge-file \
304 expect empty other &&
305 test_cmp expect x/wham
309 # Testcase 1e, Renamed directory, with all filenames being renamed too
310 # (Related to testcases 9f & 9g)
311 # Commit O: z/{oldb,oldc}
312 # Commit A: y/{newb,newc}
313 # Commit B: z/{oldb,oldc,d}
314 # Expected: y/{newb,newc,d}
316 test_expect_success '1e-setup: Renamed directory, with all files being renamed too' '
317 test_create_repo 1e &&
334 git mv z/oldb y/newb &&
335 git mv z/oldc y/newc &&
347 test_expect_success '1e-check: Renamed directory, with all files being renamed too' '
353 git -c merge.directoryRenames=true merge -s recursive B^0 &&
355 git ls-files -s >out &&
356 test_line_count = 3 out &&
358 git rev-parse >actual \
359 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
360 git rev-parse >expect \
361 O:z/oldb O:z/oldc B:z/d &&
362 test_cmp expect actual &&
363 test_must_fail git rev-parse HEAD:z/d
367 # Testcase 1f, Split a directory into two other directories
368 # (Related to testcases 3a, all of section 2, and all of section 4)
369 # Commit O: z/{b,c,d,e,f}
370 # Commit A: z/{b,c,d,e,f,g}
371 # Commit B: y/{b,c}, x/{d,e,f}
372 # Expected: y/{b,c}, x/{d,e,f,g}
374 test_expect_success '1f-setup: Split a directory into two other directories' '
375 test_create_repo 1f &&
413 test_expect_success '1f-check: Split a directory into two other directories' '
419 git -c merge.directoryRenames=true merge -s recursive B^0 &&
421 git ls-files -s >out &&
422 test_line_count = 6 out &&
424 git rev-parse >actual \
425 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
426 git rev-parse >expect \
427 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
428 test_cmp expect actual &&
429 test_path_is_missing z/g &&
430 test_must_fail git rev-parse HEAD:z/g
434 ###########################################################################
435 # Rules suggested by testcases in section 1:
437 # We should still detect the directory rename even if it wasn't just
438 # the directory renamed, but the files within it. (see 1b)
440 # If renames split a directory into two or more others, the directory
441 # with the most renames, "wins" (see 1c). However, see the testcases
442 # in section 2, plus testcases 3a and 4a.
443 ###########################################################################
446 ###########################################################################
447 # SECTION 2: Split into multiple directories, with equal number of paths
449 # Explore the splitting-a-directory rules a bit; what happens in the
452 # Note that there is a closely related case of a directory not being
453 # split on either side of history, but being renamed differently on
454 # each side. See testcase 8e for that.
455 ###########################################################################
457 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
460 # Commit B: z/{b,c,d}
461 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
462 test_expect_success '2a-setup: Directory split into two on one side, with equal numbers of paths' '
463 test_create_repo 2a &&
494 test_expect_success '2a-check: Directory split into two on one side, with equal numbers of paths' '
500 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
501 test_i18ngrep "CONFLICT.*directory rename split" out &&
503 git ls-files -s >out &&
504 test_line_count = 3 out &&
505 git ls-files -u >out &&
506 test_line_count = 0 out &&
507 git ls-files -o >out &&
508 test_line_count = 1 out &&
510 git rev-parse >actual \
511 :0:y/b :0:w/c :0:z/d &&
512 git rev-parse >expect \
514 test_cmp expect actual
518 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
521 # Commit B: z/{b,c}, x/d
522 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
523 test_expect_success '2b-setup: Directory split into two on one side, with equal numbers of paths' '
524 test_create_repo 2b &&
556 test_expect_success '2b-check: Directory split into two on one side, with equal numbers of paths' '
562 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
564 git ls-files -s >out &&
565 test_line_count = 3 out &&
566 git ls-files -u >out &&
567 test_line_count = 0 out &&
568 git ls-files -o >out &&
569 test_line_count = 1 out &&
571 git rev-parse >actual \
572 :0:y/b :0:w/c :0:x/d &&
573 git rev-parse >expect \
575 test_cmp expect actual &&
576 test_i18ngrep ! "CONFLICT.*directory rename split" out
580 ###########################################################################
581 # Rules suggested by section 2:
583 # None; the rule was already covered in section 1. These testcases are
584 # here just to make sure the conflict resolution and necessary warning
585 # messages are handled correctly.
586 ###########################################################################
589 ###########################################################################
590 # SECTION 3: Path in question is the source path for some rename already
592 # Combining cases from Section 1 and trying to handle them could lead to
593 # directory renaming detection being over-applied. So, this section
594 # provides some good testcases to check that the implementation doesn't go
596 ###########################################################################
598 # Testcase 3a, Avoid implicit rename if involved as source on other side
599 # (Related to testcases 1c, 1f, and 9h)
600 # Commit O: z/{b,c,d}
601 # Commit A: z/{b,c,d} (no change)
602 # Commit B: y/{b,c}, x/d
603 # Expected: y/{b,c}, x/d
604 test_expect_success '3a-setup: Avoid implicit rename if involved as source on other side' '
605 test_create_repo 3a &&
623 git commit --allow-empty -m "A" &&
637 test_expect_success '3a-check: Avoid implicit rename if involved as source on other side' '
643 git -c merge.directoryRenames=true merge -s recursive B^0 &&
645 git ls-files -s >out &&
646 test_line_count = 3 out &&
648 git rev-parse >actual \
649 HEAD:y/b HEAD:y/c HEAD:x/d &&
650 git rev-parse >expect \
652 test_cmp expect actual
656 # Testcase 3b, Avoid implicit rename if involved as source on other side
657 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
658 # Commit O: z/{b,c,d}
659 # Commit A: y/{b,c}, x/d
660 # Commit B: z/{b,c}, w/d
661 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
662 # NOTE: We're particularly checking that since z/d is already involved as
663 # a source in a file rename on the same side of history, that we don't
664 # get it involved in directory rename detection. If it were, we might
665 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
666 # rename/rename/rename(1to3) conflict, which is just weird.
667 test_expect_success '3b-setup: Avoid implicit rename if involved as source on current side' '
668 test_create_repo 3b &&
702 test_expect_success '3b-check: Avoid implicit rename if involved as source on current side' '
708 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
709 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
710 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
712 git ls-files -s >out &&
713 test_line_count = 5 out &&
714 git ls-files -u >out &&
715 test_line_count = 3 out &&
716 git ls-files -o >out &&
717 test_line_count = 1 out &&
719 git rev-parse >actual \
720 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
721 git rev-parse >expect \
722 O:z/b O:z/c O:z/d O:z/d O:z/d &&
723 test_cmp expect actual &&
725 test_path_is_missing z/d &&
726 git hash-object >actual \
728 git rev-parse >expect \
730 test_cmp expect actual
734 ###########################################################################
735 # Rules suggested by section 3:
737 # Avoid directory-rename-detection for a path, if that path is the source
738 # of a rename on either side of a merge.
739 ###########################################################################
742 ###########################################################################
743 # SECTION 4: Partially renamed directory; still exists on both sides of merge
745 # What if we were to attempt to do directory rename detection when someone
746 # "mostly" moved a directory but still left some files around, or,
747 # equivalently, fully renamed a directory in one commmit and then recreated
748 # that directory in a later commit adding some new files and then tried to
751 # It's hard to divine user intent in these cases, because you can make an
752 # argument that, depending on the intermediate history of the side being
753 # merged, that some users will want files in that directory to
754 # automatically be detected and renamed, while users with a different
755 # intermediate history wouldn't want that rename to happen.
757 # I think that it is best to simply not have directory rename detection
758 # apply to such cases. My reasoning for this is four-fold: (1) it's
759 # easiest for users in general to figure out what happened if we don't
760 # apply directory rename detection in any such case, (2) it's an easy rule
761 # to explain ["We don't do directory rename detection if the directory
762 # still exists on both sides of the merge"], (3) we can get some hairy
763 # edge/corner cases that would be really confusing and possibly not even
764 # representable in the index if we were to even try, and [related to 3] (4)
765 # attempting to resolve this issue of divining user intent by examining
766 # intermediate history goes against the spirit of three-way merges and is a
767 # path towards crazy corner cases that are far more complex than what we're
768 # already dealing with.
770 # Note that the wording of the rule ("We don't do directory rename
771 # detection if the directory still exists on both sides of the merge.")
772 # also excludes "renaming" of a directory into a subdirectory of itself
773 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
774 # out an exception for "renaming"-beneath-itself cases without opening
775 # weird edge/corner cases for other partial directory renames, but for now
776 # we are keeping the rule simple.
778 # This section contains a test for a partially-renamed-directory case.
779 ###########################################################################
781 # Testcase 4a, Directory split, with original directory still present
782 # (Related to testcase 1f)
783 # Commit O: z/{b,c,d,e}
784 # Commit A: y/{b,c,d}, z/e
785 # Commit B: z/{b,c,d,e,f}
786 # Expected: y/{b,c,d}, z/{e,f}
787 # NOTE: Even though most files from z moved to y, we don't want f to follow.
789 test_expect_success '4a-setup: Directory split, with original directory still present' '
790 test_create_repo 4a &&
823 test_expect_success '4a-check: Directory split, with original directory still present' '
829 git -c merge.directoryRenames=true merge -s recursive B^0 &&
831 git ls-files -s >out &&
832 test_line_count = 5 out &&
833 git ls-files -u >out &&
834 test_line_count = 0 out &&
835 git ls-files -o >out &&
836 test_line_count = 1 out &&
838 git rev-parse >actual \
839 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
840 git rev-parse >expect \
841 O:z/b O:z/c O:z/d O:z/e B:z/f &&
842 test_cmp expect actual
846 ###########################################################################
847 # Rules suggested by section 4:
849 # Directory-rename-detection should be turned off for any directories (as
850 # a source for renames) that exist on both sides of the merge. (The "as
851 # a source for renames" clarification is due to cases like 1c where
852 # the target directory exists on both sides and we do want the rename
853 # detection.) But, sadly, see testcase 8b.
854 ###########################################################################
857 ###########################################################################
858 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
860 # Implicitly renaming files due to a detected directory rename could run
861 # into problems if there are files or directories in the way of the paths
862 # we want to rename. Explore such cases in this section.
863 ###########################################################################
865 # Testcase 5a, Merge directories, other side adds files to original and target
866 # Commit O: z/{b,c}, y/d
867 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
868 # Commit B: y/{b,c,d}
869 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
870 # NOTE: While directory rename detection is active here causing z/f to
871 # become y/f, we did not apply this for z/e_1 because that would
872 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
873 # this add/add, is that both versions of y/e are from the same side
874 # of history, giving us no way to represent this conflict in the
877 test_expect_success '5a-setup: Merge directories, other side adds files to original and target' '
878 test_create_repo 5a &&
899 git add z/e z/f y/e &&
912 test_expect_success '5a-check: Merge directories, other side adds files to original and target' '
918 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
919 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
921 git ls-files -s >out &&
922 test_line_count = 6 out &&
923 git ls-files -u >out &&
924 test_line_count = 0 out &&
925 git ls-files -o >out &&
926 test_line_count = 1 out &&
928 git rev-parse >actual \
929 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
930 git rev-parse >expect \
931 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
932 test_cmp expect actual
936 # Testcase 5b, Rename/delete in order to get add/add/add conflict
937 # (Related to testcase 8d; these may appear slightly inconsistent to users;
938 # Also related to testcases 7d and 7e)
939 # Commit O: z/{b,c,d_1}
940 # Commit A: y/{b,c,d_2}
941 # Commit B: z/{b,c,d_1,e}, y/d_3
942 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
943 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
944 # we normaly would since z/ is being renamed to y/, then this would be
945 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
946 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
947 # representable in the index, so the existence of y/d_3 needs to
948 # cause us to bail on directory rename detection for that path, falling
949 # back to git behavior without the directory rename detection.
951 test_expect_success '5b-setup: Rename/delete in order to get add/add/add conflict' '
952 test_create_repo 5b &&
986 test_expect_success '5b-check: Rename/delete in order to get add/add/add conflict' '
992 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
993 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
995 git ls-files -s >out &&
996 test_line_count = 5 out &&
997 git ls-files -u >out &&
998 test_line_count = 2 out &&
999 git ls-files -o >out &&
1000 test_line_count = 1 out &&
1002 git rev-parse >actual \
1003 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1004 git rev-parse >expect \
1005 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1006 test_cmp expect actual &&
1008 test_must_fail git rev-parse :1:y/d &&
1009 test_path_is_file y/d
1013 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1014 # (Directory rename detection would result in transitive rename vs.
1015 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1016 # rename paths conflict with separate adds on the other side)
1017 # (Related to testcases 3b and 7c)
1018 # Commit O: z/{b,c}, x/d_1
1019 # Commit A: y/{b,c,d_2}, w/d_1
1020 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1021 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1022 # presence of y/d_4 in B to avoid doing transitive rename of
1023 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1024 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1025 # though, because it doesn't have anything in the way.
1027 test_expect_success '5c-setup: Transitive rename would cause rename/rename/rename/add/add/add' '
1028 test_create_repo 5c &&
1039 git commit -m "O" &&
1051 git commit -m "A" &&
1060 git add w/ y/ z/e &&
1066 test_expect_success '5c-check: Transitive rename would cause rename/rename/rename/add/add/add' '
1072 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1073 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1074 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1076 git ls-files -s >out &&
1077 test_line_count = 9 out &&
1078 git ls-files -u >out &&
1079 test_line_count = 6 out &&
1080 git ls-files -o >out &&
1081 test_line_count = 1 out &&
1083 git rev-parse >actual \
1084 :0:y/b :0:y/c :0:y/e &&
1085 git rev-parse >expect \
1086 O:z/b O:z/c B:z/e &&
1087 test_cmp expect actual &&
1089 test_must_fail git rev-parse :1:y/d &&
1090 git rev-parse >actual \
1091 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1092 git rev-parse >expect \
1093 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1094 test_cmp expect actual &&
1096 git hash-object >actual \
1098 git rev-parse >expect \
1100 test_cmp expect actual &&
1101 test_path_is_missing x/d &&
1102 test_path_is_file y/d &&
1103 grep -q "<<<<" y/d # conflict markers should be present
1107 # Testcase 5d, Directory/file/file conflict due to directory rename
1109 # Commit A: y/{b,c,d_1}
1110 # Commit B: z/{b,c,d_2,f}, y/d/e
1111 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1112 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1113 # detection for z/d_2, but that doesn't prevent us from applying the
1114 # directory rename detection for z/f -> y/f.
1116 test_expect_success '5d-setup: Directory/file/file conflict due to directory rename' '
1117 test_create_repo 5d &&
1126 git commit -m "O" &&
1137 git commit -m "A" &&
1144 git add y/d/e z/d z/f &&
1150 test_expect_success '5d-check: Directory/file/file conflict due to directory rename' '
1156 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1157 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1159 git ls-files -s >out &&
1160 test_line_count = 6 out &&
1161 git ls-files -u >out &&
1162 test_line_count = 1 out &&
1163 git ls-files -o >out &&
1164 test_line_count = 2 out &&
1166 git rev-parse >actual \
1167 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1168 git rev-parse >expect \
1169 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1170 test_cmp expect actual &&
1172 git hash-object y/d~HEAD >actual &&
1173 git rev-parse A:y/d >expect &&
1174 test_cmp expect actual
1178 ###########################################################################
1179 # Rules suggested by section 5:
1181 # If a subset of to-be-renamed files have a file or directory in the way,
1182 # "turn off" the directory rename for those specific sub-paths, falling
1183 # back to old handling. But, sadly, see testcases 8a and 8b.
1184 ###########################################################################
1187 ###########################################################################
1188 # SECTION 6: Same side of the merge was the one that did the rename
1190 # It may sound obvious that you only want to apply implicit directory
1191 # renames to directories if the _other_ side of history did the renaming.
1192 # If you did make an implementation that didn't explicitly enforce this
1193 # rule, the majority of cases that would fall under this section would
1194 # also be solved by following the rules from the above sections. But
1195 # there are still a few that stick out, so this section covers them just
1196 # to make sure we also get them right.
1197 ###########################################################################
1199 # Testcase 6a, Tricky rename/delete
1200 # Commit O: z/{b,c,d}
1202 # Commit B: y/{b,c}, z/d
1203 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1204 # Note: We're just checking here that the rename of z/b and z/c to put
1205 # them under y/ doesn't accidentally catch z/d and make it look like
1206 # it is also involved in a rename/delete conflict.
1208 test_expect_success '6a-setup: Tricky rename/delete' '
1209 test_create_repo 6a &&
1219 git commit -m "O" &&
1229 git commit -m "A" &&
1240 test_expect_success '6a-check: Tricky rename/delete' '
1246 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1247 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1249 git ls-files -s >out &&
1250 test_line_count = 2 out &&
1251 git ls-files -u >out &&
1252 test_line_count = 1 out &&
1253 git ls-files -o >out &&
1254 test_line_count = 1 out &&
1256 git rev-parse >actual \
1258 git rev-parse >expect \
1260 test_cmp expect actual
1264 # Testcase 6b, Same rename done on both sides
1265 # (Related to testcases 6c and 8e)
1268 # Commit B: y/{b,c}, z/d
1269 # Expected: y/{b,c}, z/d
1270 # Note: If we did directory rename detection here, we'd move z/d into y/,
1271 # but B did that rename and still decided to put the file into z/,
1272 # so we probably shouldn't apply directory rename detection for it.
1274 test_expect_success '6b-setup: Same rename done on both sides' '
1275 test_create_repo 6b &&
1284 git commit -m "O" &&
1293 git commit -m "A" &&
1305 test_expect_success '6b-check: Same rename done on both sides' '
1311 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1313 git ls-files -s >out &&
1314 test_line_count = 3 out &&
1315 git ls-files -u >out &&
1316 test_line_count = 0 out &&
1317 git ls-files -o >out &&
1318 test_line_count = 1 out &&
1320 git rev-parse >actual \
1321 HEAD:y/b HEAD:y/c HEAD:z/d &&
1322 git rev-parse >expect \
1323 O:z/b O:z/c B:z/d &&
1324 test_cmp expect actual
1328 # Testcase 6c, Rename only done on same side
1329 # (Related to testcases 6b and 8e)
1331 # Commit A: z/{b,c} (no change)
1332 # Commit B: y/{b,c}, z/d
1333 # Expected: y/{b,c}, z/d
1334 # NOTE: Seems obvious, but just checking that the implementation doesn't
1335 # "accidentally detect a rename" and give us y/{b,c,d}.
1337 test_expect_success '6c-setup: Rename only done on same side' '
1338 test_create_repo 6c &&
1347 git commit -m "O" &&
1355 git commit --allow-empty -m "A" &&
1367 test_expect_success '6c-check: Rename only done on same side' '
1373 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1375 git ls-files -s >out &&
1376 test_line_count = 3 out &&
1377 git ls-files -u >out &&
1378 test_line_count = 0 out &&
1379 git ls-files -o >out &&
1380 test_line_count = 1 out &&
1382 git rev-parse >actual \
1383 HEAD:y/b HEAD:y/c HEAD:z/d &&
1384 git rev-parse >expect \
1385 O:z/b O:z/c B:z/d &&
1386 test_cmp expect actual
1390 # Testcase 6d, We don't always want transitive renaming
1391 # (Related to testcase 1c)
1392 # Commit O: z/{b,c}, x/d
1393 # Commit A: z/{b,c}, x/d (no change)
1394 # Commit B: y/{b,c}, z/d
1395 # Expected: y/{b,c}, z/d
1396 # NOTE: Again, this seems obvious but just checking that the implementation
1397 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1399 test_expect_success '6d-setup: We do not always want transitive renaming' '
1400 test_create_repo 6d &&
1411 git commit -m "O" &&
1419 git commit --allow-empty -m "A" &&
1429 test_expect_success '6d-check: We do not always want transitive renaming' '
1435 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1437 git ls-files -s >out &&
1438 test_line_count = 3 out &&
1439 git ls-files -u >out &&
1440 test_line_count = 0 out &&
1441 git ls-files -o >out &&
1442 test_line_count = 1 out &&
1444 git rev-parse >actual \
1445 HEAD:y/b HEAD:y/c HEAD:z/d &&
1446 git rev-parse >expect \
1447 O:z/b O:z/c O:x/d &&
1448 test_cmp expect actual
1452 # Testcase 6e, Add/add from one-side
1454 # Commit A: z/{b,c} (no change)
1455 # Commit B: y/{b,c,d_1}, z/d_2
1456 # Expected: y/{b,c,d_1}, z/d_2
1457 # NOTE: Again, this seems obvious but just checking that the implementation
1458 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1459 # add/add conflict on y/d_1 vs y/d_2.
1461 test_expect_success '6e-setup: Add/add from one side' '
1462 test_create_repo 6e &&
1471 git commit -m "O" &&
1479 git commit --allow-empty -m "A" &&
1492 test_expect_success '6e-check: Add/add from one side' '
1498 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1500 git ls-files -s >out &&
1501 test_line_count = 4 out &&
1502 git ls-files -u >out &&
1503 test_line_count = 0 out &&
1504 git ls-files -o >out &&
1505 test_line_count = 1 out &&
1507 git rev-parse >actual \
1508 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1509 git rev-parse >expect \
1510 O:z/b O:z/c B:y/d B:z/d &&
1511 test_cmp expect actual
1515 ###########################################################################
1516 # Rules suggested by section 6:
1518 # Only apply implicit directory renames to directories if the other
1519 # side of history is the one doing the renaming.
1520 ###########################################################################
1523 ###########################################################################
1524 # SECTION 7: More involved Edge/Corner cases
1526 # The ruleset we have generated in the above sections seems to provide
1527 # well-defined merges. But can we find edge/corner cases that either (a)
1528 # are harder for users to understand, or (b) have a resolution that is
1529 # non-intuitive or suboptimal?
1531 # The testcases in this section dive into cases that I've tried to craft in
1532 # a way to find some that might be surprising to users or difficult for
1533 # them to understand (the next section will look at non-intuitive or
1534 # suboptimal merge results). Some of the testcases are similar to ones
1535 # from past sections, but have been simplified to try to highlight error
1536 # messages using a "modified" path (due to the directory rename). Are
1537 # users okay with these?
1539 # In my opinion, testcases that are difficult to understand from this
1540 # section is due to difficulty in the testcase rather than the directory
1541 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1542 # to the problem setup itself being complex). And I don't think the
1543 # error messages are a problem.
1545 # On the other hand, the testcases in section 8 worry me slightly more...
1546 ###########################################################################
1548 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1551 # Commit B: w/b, x/c, z/d
1552 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1553 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1555 test_expect_success '7a-setup: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1556 test_create_repo 7a &&
1565 git commit -m "O" &&
1574 git commit -m "A" &&
1588 test_expect_success '7a-check: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1594 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1595 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1596 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1598 git ls-files -s >out &&
1599 test_line_count = 7 out &&
1600 git ls-files -u >out &&
1601 test_line_count = 6 out &&
1602 git ls-files -o >out &&
1603 test_line_count = 1 out &&
1605 git rev-parse >actual \
1606 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1607 git rev-parse >expect \
1608 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1609 test_cmp expect actual &&
1611 git hash-object >actual \
1613 git rev-parse >expect \
1614 O:z/b O:z/b O:z/c O:z/c &&
1615 test_cmp expect actual
1619 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1620 # (Related to testcase 1d)
1621 # Commit O: z/{b,c}, x/d_1, w/d_2
1622 # Commit A: y/{b,c,d_2}, x/d_1
1623 # Commit B: z/{b,c,d_1}, w/d_2
1624 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1626 test_expect_success '7b-setup: rename/rename(2to1), but only due to transitive rename' '
1627 test_create_repo 7b &&
1640 git commit -m "O" &&
1650 git commit -m "A" &&
1660 test_expect_success '7b-check: rename/rename(2to1), but only due to transitive rename' '
1666 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1667 test_i18ngrep "CONFLICT (rename/rename)" out &&
1669 git ls-files -s >out &&
1670 test_line_count = 4 out &&
1671 git ls-files -u >out &&
1672 test_line_count = 2 out &&
1673 git ls-files -o >out &&
1674 test_line_count = 1 out &&
1676 git rev-parse >actual \
1677 :0:y/b :0:y/c :2:y/d :3:y/d &&
1678 git rev-parse >expect \
1679 O:z/b O:z/c O:w/d O:x/d &&
1680 test_cmp expect actual &&
1682 # Test that the two-way merge in y/d is as expected
1683 git cat-file -p :2:y/d >expect &&
1684 git cat-file -p :3:y/d >other &&
1686 test_must_fail git merge-file \
1690 expect empty other &&
1695 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1696 # (Related to testcases 3b and 5c)
1697 # Commit O: z/{b,c}, x/d
1698 # Commit A: y/{b,c}, w/d
1699 # Commit B: z/{b,c,d}
1700 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1701 # NOTE: z/ was renamed to y/ so we do want to report
1702 # neither CONFLICT(x/d -> w/d vs. z/d)
1703 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1705 test_expect_success '7c-setup: rename/rename(1to...2or3); transitive rename may add complexity' '
1706 test_create_repo 7c &&
1717 git commit -m "O" &&
1727 git commit -m "A" &&
1737 test_expect_success '7c-check: rename/rename(1to...2or3); transitive rename may add complexity' '
1743 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1744 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1746 git ls-files -s >out &&
1747 test_line_count = 5 out &&
1748 git ls-files -u >out &&
1749 test_line_count = 3 out &&
1750 git ls-files -o >out &&
1751 test_line_count = 1 out &&
1753 git rev-parse >actual \
1754 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1755 git rev-parse >expect \
1756 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1757 test_cmp expect actual
1761 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1762 # (Related somewhat to testcases 5b and 8d)
1763 # Commit O: z/{b,c}, x/d
1765 # Commit B: z/{b,c,d}
1766 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1767 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1769 test_expect_success '7d-setup: transitive rename involved in rename/delete; how is it reported?' '
1770 test_create_repo 7d &&
1781 git commit -m "O" &&
1791 git commit -m "A" &&
1801 test_expect_success '7d-check: transitive rename involved in rename/delete; how is it reported?' '
1807 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1808 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1810 git ls-files -s >out &&
1811 test_line_count = 3 out &&
1812 git ls-files -u >out &&
1813 test_line_count = 1 out &&
1814 git ls-files -o >out &&
1815 test_line_count = 1 out &&
1817 git rev-parse >actual \
1818 :0:y/b :0:y/c :3:y/d &&
1819 git rev-parse >expect \
1820 O:z/b O:z/c O:x/d &&
1821 test_cmp expect actual
1825 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1826 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1827 # (Also related to testcases 9c and 9d)
1828 # Commit O: z/{b,c}, x/d_1
1829 # Commit A: y/{b,c,d/g}, x/d/f
1830 # Commit B: z/{b,c,d_1}
1831 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1832 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1834 # NOTE: The main path of interest here is d_1 and where it ends up, but
1835 # this is actually a case that has two potential directory renames
1836 # involved and D/F conflict(s), so it makes sense to walk through
1839 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1840 # should be instead moved to y/. This gives us the D/F conflict on
1841 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1843 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1844 # should instead be moved to z/...BUT we removed z/ and renamed it
1845 # to y/, so maybe everything should move not from x/ to z/, but
1846 # from x/ to z/ to y/. Doing so might make sense from the logic so
1847 # far, but note that commit A had both an x/ and a y/; it did the
1848 # renaming of z/ to y/ and created x/d/f and it clearly made these
1849 # things separate, so it doesn't make much sense to push these
1850 # together. Doing so is what I'd call a doubly transitive rename;
1851 # see testcases 9c and 9d for further discussion of this issue and
1852 # how it's resolved.
1854 test_expect_success '7e-setup: transitive rename in rename/delete AND dirs in the way' '
1855 test_create_repo 7e &&
1866 git commit -m "O" &&
1879 git add x/d/f y/d/g &&
1881 git commit -m "A" &&
1891 test_expect_success '7e-check: transitive rename in rename/delete AND dirs in the way' '
1897 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1898 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1900 git ls-files -s >out &&
1901 test_line_count = 5 out &&
1902 git ls-files -u >out &&
1903 test_line_count = 1 out &&
1904 git ls-files -o >out &&
1905 test_line_count = 2 out &&
1907 git rev-parse >actual \
1908 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
1909 git rev-parse >expect \
1910 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
1911 test_cmp expect actual &&
1913 git hash-object y/d~B^0 >actual &&
1914 git rev-parse O:x/d >expect &&
1915 test_cmp expect actual
1919 ###########################################################################
1920 # SECTION 8: Suboptimal merges
1922 # As alluded to in the last section, the ruleset we have built up for
1923 # detecting directory renames unfortunately has some special cases where it
1924 # results in slightly suboptimal or non-intuitive behavior. This section
1925 # explores these cases.
1927 # To be fair, we already had non-intuitive or suboptimal behavior for most
1928 # of these cases in git before introducing implicit directory rename
1929 # detection, but it'd be nice if there was a modified ruleset out there
1930 # that handled these cases a bit better.
1931 ###########################################################################
1933 # Testcase 8a, Dual-directory rename, one into the others' way
1934 # Commit O. x/{a,b}, y/{c,d}
1935 # Commit A. x/{a,b,e}, y/{c,d,f}
1936 # Commit B. y/{a,b}, z/{c,d}
1938 # Possible Resolutions:
1939 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
1940 # Currently expected: y/{a,b,e,f}, z/{c,d}
1941 # Optimal: y/{a,b,e}, z/{c,d,f}
1943 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
1944 # better with directory rename detection than git did without, but the
1945 # simple rule from section 5 prevents me from handling this as optimally as
1946 # we potentially could.
1948 test_expect_success '8a-setup: Dual-directory rename, one into the others way' '
1949 test_create_repo 8a &&
1961 git commit -m "O" &&
1972 git commit -m "A" &&
1982 test_expect_success '8a-check: Dual-directory rename, one into the others way' '
1988 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1990 git ls-files -s >out &&
1991 test_line_count = 6 out &&
1992 git ls-files -u >out &&
1993 test_line_count = 0 out &&
1994 git ls-files -o >out &&
1995 test_line_count = 1 out &&
1997 git rev-parse >actual \
1998 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
1999 git rev-parse >expect \
2000 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2001 test_cmp expect actual
2005 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2006 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2007 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2008 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2010 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2011 # Currently expected: <same>
2012 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2013 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2015 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2016 # y, both are named 'e'. Without directory rename detection, neither file
2017 # moves directories. Implement directory rename detection suboptimally, and
2018 # you get an add/add conflict, but both files were added in commit A, so this
2019 # is an add/add conflict where one side of history added both files --
2020 # something we can't represent in the index. Obviously, we'd prefer the last
2021 # resolution, but our previous rules are too coarse to allow it. Using both
2022 # the rules from section 4 and section 5 save us from the Scary resolution,
2023 # making us fall back to pre-directory-rename-detection behavior for both
2026 test_expect_success '8b-setup: Dual-directory rename, one into the others way, with conflicting filenames' '
2027 test_create_repo 8b &&
2039 git commit -m "O" &&
2050 git commit -m "A" &&
2060 test_expect_success '8b-check: Dual-directory rename, one into the others way, with conflicting filenames' '
2066 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2068 git ls-files -s >out &&
2069 test_line_count = 6 out &&
2070 git ls-files -u >out &&
2071 test_line_count = 0 out &&
2072 git ls-files -o >out &&
2073 test_line_count = 1 out &&
2075 git rev-parse >actual \
2076 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2077 git rev-parse >expect \
2078 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2079 test_cmp expect actual
2083 # Testcase 8c, modify/delete or rename+modify/delete?
2084 # (Related to testcases 5b, 8d, and 9h)
2085 # Commit O: z/{b,c,d}
2087 # Commit B: z/{b,c,d_modified,e}
2088 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2090 # Note: It could easily be argued that the correct resolution here is
2091 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2092 # and that the modifed version of d should be present in y/ after
2093 # the merge, just marked as conflicted. Indeed, I previously did
2094 # argue that. But applying directory renames to the side of
2095 # history where a file is merely modified results in spurious
2096 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2099 test_expect_success '8c-setup: modify/delete or rename+modify/delete?' '
2100 test_create_repo 8c &&
2107 test_seq 1 10 >z/d &&
2110 git commit -m "O" &&
2120 git commit -m "A" &&
2124 test_chmod +x z/d &&
2132 test_expect_success '8c-check: modify/delete or rename+modify/delete' '
2138 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2139 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2141 git ls-files -s >out &&
2142 test_line_count = 5 out &&
2143 git ls-files -u >out &&
2144 test_line_count = 2 out &&
2145 git ls-files -o >out &&
2146 test_line_count = 1 out &&
2148 git rev-parse >actual \
2149 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2150 git rev-parse >expect \
2151 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2152 test_cmp expect actual &&
2154 test_must_fail git rev-parse :2:z/d &&
2155 git ls-files -s z/d | grep ^100755 &&
2156 test_path_is_file z/d &&
2157 test_path_is_missing y/d
2161 # Testcase 8d, rename/delete...or not?
2162 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2163 # Also related to testcases 7d and 7e)
2164 # Commit O: z/{b,c,d}
2166 # Commit B: z/{b,c,d,e}
2167 # Expected: y/{b,c,e}
2169 # Note: It would also be somewhat reasonable to resolve this as
2170 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2172 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2173 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2174 # delete) are both coming from commit A, which is illogical. Conflicts
2175 # during merging are supposed to be about opposite sides doing things
2178 test_expect_success '8d-setup: rename/delete...or not?' '
2179 test_create_repo 8d &&
2186 test_seq 1 10 >z/d &&
2189 git commit -m "O" &&
2199 git commit -m "A" &&
2209 test_expect_success '8d-check: rename/delete...or not?' '
2215 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2217 git ls-files -s >out &&
2218 test_line_count = 3 out &&
2220 git rev-parse >actual \
2221 HEAD:y/b HEAD:y/c HEAD:y/e &&
2222 git rev-parse >expect \
2223 O:z/b O:z/c B:z/e &&
2224 test_cmp expect actual
2228 # Testcase 8e, Both sides rename, one side adds to original directory
2231 # Commit B: w/{b,c}, z/d
2233 # Possible Resolutions:
2234 # w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2235 # CONFLICT(z/c -> y/c vs. w/c)
2236 # Currently expected: y/d, CONFLICT(z/b -> y/b vs. w/b),
2237 # CONFLICT(z/c -> y/c vs. w/c)
2240 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2241 # did NOT get renamed; the directory is still present; instead it is
2242 # considered to have just renamed a subset of paths in directory z
2243 # elsewhere. Therefore, the directory rename done in commit A to z/
2244 # applies to z/d and maps it to y/d.
2246 # It's possible that users would get confused about this, but what
2247 # should we do instead? Silently leaving at z/d seems just as bad or
2248 # maybe even worse. Perhaps we could print a big warning about z/d
2249 # and how we're moving to y/d in this case, but when I started thinking
2250 # about the ramifications of doing that, I didn't know how to rule out
2251 # that opening other weird edge and corner cases so I just punted.
2253 test_expect_success '8e-setup: Both sides rename, one side adds to original directory' '
2254 test_create_repo 8e &&
2263 git commit -m "O" &&
2272 git commit -m "A" &&
2284 test_expect_success '8e-check: Both sides rename, one side adds to original directory' '
2290 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2291 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2292 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2294 git ls-files -s >out &&
2295 test_line_count = 7 out &&
2296 git ls-files -u >out &&
2297 test_line_count = 6 out &&
2298 git ls-files -o >out &&
2299 test_line_count = 2 out &&
2301 git rev-parse >actual \
2302 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2303 git rev-parse >expect \
2304 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2305 test_cmp expect actual &&
2307 git hash-object >actual \
2309 git rev-parse >expect \
2310 O:z/b O:z/b O:z/c O:z/c &&
2311 test_cmp expect actual &&
2313 test_path_is_missing z/b &&
2314 test_path_is_missing z/c
2318 ###########################################################################
2319 # SECTION 9: Other testcases
2321 # This section consists of miscellaneous testcases I thought of during
2322 # the implementation which round out the testing.
2323 ###########################################################################
2325 # Testcase 9a, Inner renamed directory within outer renamed directory
2326 # (Related to testcase 1f)
2327 # Commit O: z/{b,c,d/{e,f,g}}
2328 # Commit A: y/{b,c}, x/w/{e,f,g}
2329 # Commit B: z/{b,c,d/{e,f,g,h},i}
2330 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2331 # NOTE: The only reason this one is interesting is because when a directory
2332 # is split into multiple other directories, we determine by the weight
2333 # of which one had the most paths going to it. A naive implementation
2334 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2336 test_expect_success '9a-setup: Inner renamed directory within outer renamed directory' '
2337 test_create_repo 9a &&
2349 git commit -m "O" &&
2360 git commit -m "A" &&
2371 test_expect_success '9a-check: Inner renamed directory within outer renamed directory' '
2377 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2379 git ls-files -s >out &&
2380 test_line_count = 7 out &&
2381 git ls-files -u >out &&
2382 test_line_count = 0 out &&
2383 git ls-files -o >out &&
2384 test_line_count = 1 out &&
2386 git rev-parse >actual \
2387 HEAD:y/b HEAD:y/c HEAD:y/i &&
2388 git rev-parse >expect \
2389 O:z/b O:z/c B:z/i &&
2390 test_cmp expect actual &&
2392 git rev-parse >actual \
2393 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2394 git rev-parse >expect \
2395 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2396 test_cmp expect actual
2400 # Testcase 9b, Transitive rename with content merge
2401 # (Related to testcase 1c)
2402 # Commit O: z/{b,c}, x/d_1
2403 # Commit A: y/{b,c}, x/d_2
2404 # Commit B: z/{b,c,d_3}
2405 # Expected: y/{b,c,d_merged}
2407 test_expect_success '9b-setup: Transitive rename with content merge' '
2408 test_create_repo 9b &&
2416 test_seq 1 10 >x/d &&
2419 git commit -m "O" &&
2427 test_seq 1 11 >x/d &&
2430 git commit -m "A" &&
2433 test_seq 0 10 >x/d &&
2441 test_expect_success '9b-check: Transitive rename with content merge' '
2447 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2449 git ls-files -s >out &&
2450 test_line_count = 3 out &&
2452 test_seq 0 11 >expected &&
2453 test_cmp expected y/d &&
2455 git rev-parse >actual \
2456 HEAD:y/b HEAD:y/c HEAD:y/d &&
2457 git rev-parse >expect \
2458 O:z/b O:z/c :0:expected &&
2459 test_cmp expect actual &&
2460 test_must_fail git rev-parse HEAD:x/d &&
2461 test_must_fail git rev-parse HEAD:z/d &&
2462 test_path_is_missing z/d &&
2464 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2465 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2466 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2470 # Testcase 9c, Doubly transitive rename?
2471 # (Related to testcase 1c, 7e, and 9d)
2472 # Commit O: z/{b,c}, x/{d,e}, w/f
2473 # Commit A: y/{b,c}, x/{d,e,f,g}
2474 # Commit B: z/{b,c,d,e}, w/f
2475 # Expected: y/{b,c,d,e}, x/{f,g}
2477 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2478 # x/f is clear. Let's look beyond that. Here's the logic:
2479 # Commit B renamed x/ -> z/
2480 # Commit A renamed z/ -> y/
2481 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2482 # transient rename. However, where does it end? We can chain these
2483 # indefinitely (see testcase 9d). What if there is a D/F conflict
2484 # at z/f/ or y/f/? Or just another file conflict at one of those
2485 # paths? In the case of an N-long chain of transient renamings,
2486 # where do we "abort" the rename at? Can the user make sense of
2487 # the resulting conflict and resolve it?
2489 # To avoid this confusion I use the simple rule that if the other side
2490 # of history did a directory rename to a path that your side renamed
2491 # away, then ignore that particular rename from the other side of
2492 # history for any implicit directory renames.
2494 test_expect_success '9c-setup: Doubly transitive rename?' '
2495 test_create_repo 9c &&
2509 git commit -m "O" &&
2521 git commit -m "A" &&
2531 test_expect_success '9c-check: Doubly transitive rename?' '
2537 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2538 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2540 git ls-files -s >out &&
2541 test_line_count = 6 out &&
2542 git ls-files -o >out &&
2543 test_line_count = 1 out &&
2545 git rev-parse >actual \
2546 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2547 git rev-parse >expect \
2548 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2549 test_cmp expect actual
2553 # Testcase 9d, N-fold transitive rename?
2554 # (Related to testcase 9c...and 1c and 7e)
2555 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2556 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2557 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2558 # Expected: <see NOTE first>
2560 # NOTE: z/ -> y/ (in commit A)
2561 # y/ -> x/ (in commit B)
2562 # x/ -> w/ (in commit A)
2563 # w/ -> v/ (in commit B)
2564 # v/ -> u/ (in commit A)
2565 # So, if we add a file to z, say z/t, where should it end up? In u?
2566 # What if there's another file or directory named 't' in one of the
2567 # intervening directories and/or in u itself? Also, shouldn't the
2568 # same logic that places 't' in u/ also move ALL other files to u/?
2569 # What if there are file or directory conflicts in any of them? If
2570 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2571 # like this, would the user have any hope of understanding any
2572 # conflicts or how their working tree ended up? I think not, so I'm
2573 # ruling out N-ary transitive renames for N>1.
2575 # Therefore our expected result is:
2576 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2577 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2578 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2579 # simple rules that are consistent with what we need for all the other
2580 # testcases and simplifies things for the user.
2582 test_expect_success '9d-setup: N-way transitive rename?' '
2583 test_create_repo 9d &&
2587 mkdir z y x w v u &&
2594 git add z y x w v u &&
2596 git commit -m "O" &&
2607 git commit -m "A" &&
2619 test_expect_success '9d-check: N-way transitive rename?' '
2625 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2626 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2627 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2628 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2629 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2631 git ls-files -s >out &&
2632 test_line_count = 7 out &&
2633 git ls-files -o >out &&
2634 test_line_count = 1 out &&
2636 git rev-parse >actual \
2638 HEAD:y/a HEAD:x/b HEAD:w/c \
2639 HEAD:u/d HEAD:u/e HEAD:u/f &&
2640 git rev-parse >expect \
2643 O:w/d O:v/e A:u/f &&
2644 test_cmp expect actual
2648 # Testcase 9e, N-to-1 whammo
2649 # (Related to testcase 9c...and 1c and 7e)
2650 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2651 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2652 # Commit B: combined/{a,b,d,e,g,h,j,k}
2653 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2654 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2656 test_expect_success '9e-setup: N-to-1 whammo' '
2657 test_create_repo 9e &&
2661 mkdir dir1 dir2 dir3 dirN &&
2672 git commit -m "O" &&
2689 git commit -m "A" &&
2692 git mv dir1 combined &&
2693 git mv dir2/* combined/ &&
2694 git mv dir3/* combined/ &&
2695 git mv dirN/* combined/ &&
2701 test_expect_success C_LOCALE_OUTPUT '9e-check: N-to-1 whammo' '
2707 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2708 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2709 grep -q dir1/yo error_line &&
2710 grep -q dir2/yo error_line &&
2711 grep -q dir3/yo error_line &&
2712 grep -q dirN/yo error_line &&
2714 git ls-files -s >out &&
2715 test_line_count = 16 out &&
2716 git ls-files -u >out &&
2717 test_line_count = 0 out &&
2718 git ls-files -o >out &&
2719 test_line_count = 2 out &&
2721 git rev-parse >actual \
2722 :0:combined/a :0:combined/b :0:combined/c \
2723 :0:combined/d :0:combined/e :0:combined/f \
2724 :0:combined/g :0:combined/h :0:combined/i \
2725 :0:combined/j :0:combined/k :0:combined/l &&
2726 git rev-parse >expect \
2727 O:dir1/a O:dir1/b A:dir1/c \
2728 O:dir2/d O:dir2/e A:dir2/f \
2729 O:dir3/g O:dir3/h A:dir3/i \
2730 O:dirN/j O:dirN/k A:dirN/l &&
2731 test_cmp expect actual &&
2733 git rev-parse >actual \
2734 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2735 git rev-parse >expect \
2736 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2737 test_cmp expect actual
2741 # Testcase 9f, Renamed directory that only contained immediate subdirs
2742 # (Related to testcases 1e & 9g)
2743 # Commit O: goal/{a,b}/$more_files
2744 # Commit A: priority/{a,b}/$more_files
2745 # Commit B: goal/{a,b}/$more_files, goal/c
2746 # Expected: priority/{a,b}/$more_files, priority/c
2748 test_expect_success '9f-setup: Renamed directory that only contained immediate subdirs' '
2749 test_create_repo 9f &&
2755 echo foo >goal/a/foo &&
2756 echo bar >goal/b/bar &&
2757 echo baz >goal/b/baz &&
2760 git commit -m "O" &&
2767 git mv goal/ priority &&
2769 git commit -m "A" &&
2779 test_expect_success '9f-check: Renamed directory that only contained immediate subdirs' '
2785 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2787 git ls-files -s >out &&
2788 test_line_count = 4 out &&
2790 git rev-parse >actual \
2791 HEAD:priority/a/foo \
2792 HEAD:priority/b/bar \
2793 HEAD:priority/b/baz \
2795 git rev-parse >expect \
2800 test_cmp expect actual &&
2801 test_must_fail git rev-parse HEAD:goal/c
2805 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2806 # (Related to testcases 1e & 9f)
2807 # Commit O: goal/{a,b}/$more_files
2808 # Commit A: priority/{alpha,bravo}/$more_files
2809 # Commit B: goal/{a,b}/$more_files, goal/c
2810 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2812 test_expect_success '9g-setup: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2813 test_create_repo 9g &&
2819 echo foo >goal/a/foo &&
2820 echo bar >goal/b/bar &&
2821 echo baz >goal/b/baz &&
2824 git commit -m "O" &&
2832 git mv goal/a/ priority/alpha &&
2833 git mv goal/b/ priority/beta &&
2836 git commit -m "A" &&
2846 test_expect_failure '9g-check: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2852 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2854 git ls-files -s >out &&
2855 test_line_count = 4 out &&
2857 git rev-parse >actual \
2858 HEAD:priority/alpha/foo \
2859 HEAD:priority/beta/bar \
2860 HEAD:priority/beta/baz \
2862 git rev-parse >expect \
2867 test_cmp expect actual &&
2868 test_must_fail git rev-parse HEAD:goal/c
2872 # Testcase 9h, Avoid implicit rename if involved as source on other side
2873 # (Extremely closely related to testcase 3a)
2874 # Commit O: z/{b,c,d_1}
2875 # Commit A: z/{b,c,d_2}
2876 # Commit B: y/{b,c}, x/d_1
2877 # Expected: y/{b,c}, x/d_2
2878 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2879 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
2880 test_expect_success '9h-setup: Avoid dir rename on merely modified path' '
2881 test_create_repo 9h &&
2888 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2891 git commit -m "O" &&
2901 git commit -m "A" &&
2915 test_expect_success '9h-check: Avoid dir rename on merely modified path' '
2921 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2923 git ls-files -s >out &&
2924 test_line_count = 3 out &&
2926 git rev-parse >actual \
2927 HEAD:y/b HEAD:y/c HEAD:x/d &&
2928 git rev-parse >expect \
2929 O:z/b O:z/c A:z/d &&
2930 test_cmp expect actual
2934 ###########################################################################
2935 # Rules suggested by section 9:
2937 # If the other side of history did a directory rename to a path that your
2938 # side renamed away, then ignore that particular rename from the other
2939 # side of history for any implicit directory renames.
2940 ###########################################################################
2942 ###########################################################################
2943 # SECTION 10: Handling untracked files
2945 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
2946 # the operation if untracked or dirty files would be deleted or overwritten
2947 # by the merge. Unfortunately, unpack_trees() does not understand renames,
2948 # and if it doesn't abort, then it muddies up the working directory before
2949 # we even get to the point of detecting renames, so we need some special
2950 # handling, at least in the case of directory renames.
2951 ###########################################################################
2953 # Testcase 10a, Overwrite untracked: normal rename/delete
2954 # Commit O: z/{b,c_1}
2955 # Commit A: z/b + untracked z/c + untracked z/d
2956 # Commit B: z/{b,d_1}
2957 # Expected: Aborted Merge +
2958 # ERROR_MSG(untracked working tree files would be overwritten by merge)
2960 test_expect_success '10a-setup: Overwrite untracked with normal rename/delete' '
2961 test_create_repo 10a &&
2970 git commit -m "O" &&
2979 git commit -m "A" &&
2988 test_expect_success '10a-check: Overwrite untracked with normal rename/delete' '
2994 echo important >z/d &&
2996 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2997 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
2999 git ls-files -s >out &&
3000 test_line_count = 1 out &&
3001 git ls-files -o >out &&
3002 test_line_count = 4 out &&
3004 echo very >expect &&
3005 test_cmp expect z/c &&
3007 echo important >expect &&
3008 test_cmp expect z/d &&
3010 git rev-parse HEAD:z/b >actual &&
3011 git rev-parse O:z/b >expect &&
3012 test_cmp expect actual
3016 # Testcase 10b, Overwrite untracked: dir rename + delete
3017 # Commit O: z/{b,c_1}
3018 # Commit A: y/b + untracked y/{c,d,e}
3019 # Commit B: z/{b,d_1,e}
3020 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3021 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3022 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3024 test_expect_success '10b-setup: Overwrite untracked with dir rename + delete' '
3025 test_create_repo 10b &&
3034 git commit -m "O" &&
3044 git commit -m "A" &&
3055 test_expect_success '10b-check: Overwrite untracked with dir rename + delete' '
3061 echo important >y/d &&
3062 echo contents >y/e &&
3064 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3065 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3066 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3068 git ls-files -s >out &&
3069 test_line_count = 3 out &&
3070 git ls-files -u >out &&
3071 test_line_count = 2 out &&
3072 git ls-files -o >out &&
3073 test_line_count = 5 out &&
3075 git rev-parse >actual \
3076 :0:y/b :3:y/d :3:y/e &&
3077 git rev-parse >expect \
3078 O:z/b O:z/c B:z/e &&
3079 test_cmp expect actual &&
3081 echo very >expect &&
3082 test_cmp expect y/c &&
3084 echo important >expect &&
3085 test_cmp expect y/d &&
3087 echo contents >expect &&
3092 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3093 # Commit O: z/{a,b}, x/{c,d}
3094 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3095 # Commit B: z/{a,b,c}, x/d
3096 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3097 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3099 # ERROR_MSG(Refusing to lose untracked file at y/c)
3101 test_expect_success '10c-setup: Overwrite untracked with dir rename/rename(1to2)' '
3102 test_create_repo 10c &&
3113 git commit -m "O" &&
3124 git commit -m "A" &&
3133 test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2)' '
3138 echo important >y/c &&
3140 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3141 test_i18ngrep "CONFLICT (rename/rename)" out &&
3142 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3144 git ls-files -s >out &&
3145 test_line_count = 6 out &&
3146 git ls-files -u >out &&
3147 test_line_count = 3 out &&
3148 git ls-files -o >out &&
3149 test_line_count = 3 out &&
3151 git rev-parse >actual \
3152 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3153 git rev-parse >expect \
3154 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3155 test_cmp expect actual &&
3157 git hash-object y/c~B^0 >actual &&
3158 git rev-parse O:x/c >expect &&
3159 test_cmp expect actual &&
3161 echo important >expect &&
3166 test_expect_success '10c-check: Overwrite untracked with dir rename/rename(1to2), other direction' '
3175 echo important >y/c &&
3177 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3178 test_i18ngrep "CONFLICT (rename/rename)" out &&
3179 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3181 git ls-files -s >out &&
3182 test_line_count = 6 out &&
3183 git ls-files -u >out &&
3184 test_line_count = 3 out &&
3185 git ls-files -o >out &&
3186 test_line_count = 3 out &&
3188 git rev-parse >actual \
3189 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3190 git rev-parse >expect \
3191 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3192 test_cmp expect actual &&
3194 git hash-object y/c~HEAD >actual &&
3195 git rev-parse O:x/c >expect &&
3196 test_cmp expect actual &&
3198 echo important >expect &&
3203 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3204 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3205 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3206 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3207 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3208 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3209 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3211 test_expect_success '10d-setup: Delete untracked with dir rename/rename(2to1)' '
3212 test_create_repo 10d &&
3225 git commit -m "O" &&
3232 git mv z/c x/wham &&
3235 git commit -m "A" &&
3238 git mv x/f z/wham &&
3245 test_expect_success '10d-check: Delete untracked with dir rename/rename(2to1)' '
3250 echo important >y/wham &&
3252 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3253 test_i18ngrep "CONFLICT (rename/rename)" out &&
3254 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3256 git ls-files -s >out &&
3257 test_line_count = 6 out &&
3258 git ls-files -u >out &&
3259 test_line_count = 2 out &&
3260 git ls-files -o >out &&
3261 test_line_count = 3 out &&
3263 git rev-parse >actual \
3264 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3265 git rev-parse >expect \
3266 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3267 test_cmp expect actual &&
3269 test_must_fail git rev-parse :1:y/wham &&
3271 echo important >expect &&
3272 test_cmp expect y/wham &&
3274 # Test that the two-way merge in y/wham~merged is as expected
3275 git cat-file -p :2:y/wham >expect &&
3276 git cat-file -p :3:y/wham >other &&
3278 test_must_fail git merge-file \
3282 expect empty other &&
3283 test_cmp expect y/wham~merged
3287 # Testcase 10e, Does git complain about untracked file that's not in the way?
3289 # Commit A: y/{a,b} + untracked z/c
3290 # Commit B: z/{a,b,c}
3291 # Expected: y/{a,b,c} + untracked z/c
3293 test_expect_success '10e-setup: Does git complain about untracked file that is not really in the way?' '
3294 test_create_repo 10e &&
3303 git commit -m "O" &&
3312 git commit -m "A" &&
3322 test_expect_failure '10e-check: Does git complain about untracked file that is not really in the way?' '
3330 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3331 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3333 git ls-files -s >out &&
3334 test_line_count = 3 out &&
3335 git ls-files -u >out &&
3336 test_line_count = 0 out &&
3337 git ls-files -o >out &&
3338 test_line_count = 3 out &&
3340 git rev-parse >actual \
3341 :0:y/a :0:y/b :0:y/c &&
3342 git rev-parse >expect \
3343 O:z/a O:z/b B:z/c &&
3344 test_cmp expect actual &&
3346 echo random >expect &&
3351 ###########################################################################
3352 # SECTION 11: Handling dirty (not up-to-date) files
3354 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3355 # the operation if untracked or dirty files would be deleted or overwritten
3356 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3357 # and if it doesn't abort, then it muddies up the working directory before
3358 # we even get to the point of detecting renames, so we need some special
3359 # handling. This was true even of normal renames, but there are additional
3360 # codepaths that need special handling with directory renames. Add
3361 # testcases for both renamed-by-directory-rename-detection and standard
3363 ###########################################################################
3365 # Testcase 11a, Avoid losing dirty contents with simple rename
3366 # Commit O: z/{a,b_v1},
3367 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3368 # Commit B: z/{a,b_v2}
3369 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3370 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3371 # z/c~HEAD with contents of B:z/b_v2,
3372 # z/c with uncommitted mods on top of A:z/c_v1
3374 test_expect_success '11a-setup: Avoid losing dirty contents with simple rename' '
3375 test_create_repo 11a &&
3381 test_seq 1 10 >z/b &&
3384 git commit -m "O" &&
3393 git commit -m "A" &&
3403 test_expect_success '11a-check: Avoid losing dirty contents with simple rename' '
3410 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3411 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3413 test_seq 1 10 >expected &&
3414 echo stuff >>expected &&
3415 test_cmp expected z/c &&
3417 git ls-files -s >out &&
3418 test_line_count = 2 out &&
3419 git ls-files -u >out &&
3420 test_line_count = 1 out &&
3421 git ls-files -o >out &&
3422 test_line_count = 4 out &&
3424 git rev-parse >actual \
3426 git rev-parse >expect \
3428 test_cmp expect actual &&
3430 git hash-object z/c~HEAD >actual &&
3431 git rev-parse B:z/b >expect &&
3432 test_cmp expect actual
3436 # Testcase 11b, Avoid losing dirty file involved in directory rename
3437 # Commit O: z/a, x/{b,c_v1}
3438 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3439 # Commit B: y/a, x/{b,c_v2}
3440 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3441 # ERROR_MSG(Refusing to lose dirty file at z/c)
3444 test_expect_success '11b-setup: Avoid losing dirty file involved in directory rename' '
3445 test_create_repo 11b &&
3452 test_seq 1 10 >x/c &&
3455 git commit -m "O" &&
3464 git commit -m "A" &&
3475 test_expect_success '11b-check: Avoid losing dirty file involved in directory rename' '
3482 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3483 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3485 grep -q stuff z/c &&
3486 test_seq 1 10 >expected &&
3487 echo stuff >>expected &&
3488 test_cmp expected z/c &&
3490 git ls-files -s >out &&
3491 test_line_count = 3 out &&
3492 git ls-files -u >out &&
3493 test_line_count = 0 out &&
3494 git ls-files -m >out &&
3495 test_line_count = 0 out &&
3496 git ls-files -o >out &&
3497 test_line_count = 4 out &&
3499 git rev-parse >actual \
3500 :0:x/b :0:y/a :0:y/c &&
3501 git rev-parse >expect \
3502 O:x/b O:z/a B:x/c &&
3503 test_cmp expect actual &&
3505 git hash-object y/c >actual &&
3506 git rev-parse B:x/c >expect &&
3507 test_cmp expect actual
3511 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3512 # Commit O: y/a, x/{b,c_v1}
3513 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3514 # Commit B: y/{a,c/d}, x/{b,c_v2}
3515 # Expected: Abort_msg("following files would be overwritten by merge") +
3516 # y/c left untouched (still has uncommitted mods)
3518 test_expect_success '11c-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3519 test_create_repo 11c &&
3526 test_seq 1 10 >x/c &&
3529 git commit -m "O" &&
3538 git commit -m "A" &&
3544 git add x/c y/c/d &&
3550 test_expect_success '11c-check: Avoid losing not-uptodate with rename + D/F conflict' '
3557 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3558 test_i18ngrep "following files would be overwritten by merge" err &&
3560 grep -q stuff y/c &&
3561 test_seq 1 10 >expected &&
3562 echo stuff >>expected &&
3563 test_cmp expected y/c &&
3565 git ls-files -s >out &&
3566 test_line_count = 3 out &&
3567 git ls-files -u >out &&
3568 test_line_count = 0 out &&
3569 git ls-files -m >out &&
3570 test_line_count = 1 out &&
3571 git ls-files -o >out &&
3572 test_line_count = 3 out
3576 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3577 # Commit O: z/a, x/{b,c_v1}
3578 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3579 # Commit B: y/{a,c/d}, x/{b,c_v2}
3580 # Expected: D/F: y/c_v2 vs y/c/d) +
3581 # Warning_Msg("Refusing to lose dirty file at z/c) +
3582 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3584 test_expect_success '11d-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3585 test_create_repo 11d &&
3592 test_seq 1 10 >x/c &&
3595 git commit -m "O" &&
3604 git commit -m "A" &&
3611 git add x/c y/c/d &&
3617 test_expect_success '11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
3624 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3625 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3627 grep -q stuff z/c &&
3628 test_seq 1 10 >expected &&
3629 echo stuff >>expected &&
3630 test_cmp expected z/c &&
3632 git ls-files -s >out &&
3633 test_line_count = 4 out &&
3634 git ls-files -u >out &&
3635 test_line_count = 1 out &&
3636 git ls-files -o >out &&
3637 test_line_count = 5 out &&
3639 git rev-parse >actual \
3640 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3641 git rev-parse >expect \
3642 O:x/b O:z/a B:y/c/d B:x/c &&
3643 test_cmp expect actual &&
3645 git hash-object y/c~HEAD >actual &&
3646 git rev-parse B:x/c >expect &&
3647 test_cmp expect actual
3651 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3652 # Commit O: z/{a,b}, x/{c_1,d}
3653 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3654 # Commit B: z/{a,b,c_1}, x/d
3655 # Expected: Failed Merge; y/{a,b} + x/d +
3656 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3657 # ERROR_MSG(Refusing to lose dirty file at y/c)
3658 # y/c~B^0 has O:x/c_1 contents
3659 # y/c~HEAD has A:y/c_2 contents
3660 # y/c has dirty file from before merge
3662 test_expect_success '11e-setup: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3663 test_create_repo 11e &&
3674 git commit -m "O" &&
3682 echo different >y/c &&
3687 git commit -m "A" &&
3696 test_expect_success '11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3703 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3704 test_i18ngrep "CONFLICT (rename/rename)" out &&
3705 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3707 git ls-files -s >out &&
3708 test_line_count = 7 out &&
3709 git ls-files -u >out &&
3710 test_line_count = 4 out &&
3711 git ls-files -o >out &&
3712 test_line_count = 3 out &&
3714 echo different >expected &&
3715 echo mods >>expected &&
3716 test_cmp expected y/c &&
3718 git rev-parse >actual \
3719 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3720 git rev-parse >expect \
3721 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3722 test_cmp expect actual &&
3724 # See if y/c~merged has expected contents; requires manually
3725 # doing the expected file merge
3726 git cat-file -p A:y/c >c1 &&
3727 git cat-file -p B:z/c >c2 &&
3729 test_must_fail git merge-file \
3734 test_cmp c1 y/c~merged
3738 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3739 # Commit O: z/{a,b}, x/{c_1,d_2}
3740 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3741 # Commit B: z/{a,b,wham_2}, x/c_1
3742 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3743 # y/wham with dirty changes from before merge +
3744 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3745 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3747 test_expect_success '11f-setup: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3748 test_create_repo 11f &&
3755 test_seq 1 10 >x/c &&
3759 git commit -m "O" &&
3767 git mv x/c y/wham &&
3769 git commit -m "A" &&
3772 git mv x/d z/wham &&
3778 test_expect_success '11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3783 echo important >>y/wham &&
3785 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3786 test_i18ngrep "CONFLICT (rename/rename)" out &&
3787 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3789 git ls-files -s >out &&
3790 test_line_count = 4 out &&
3791 git ls-files -u >out &&
3792 test_line_count = 2 out &&
3793 git ls-files -o >out &&
3794 test_line_count = 3 out &&
3796 test_seq 1 10 >expected &&
3797 echo important >>expected &&
3798 test_cmp expected y/wham &&
3800 test_must_fail git rev-parse :1:y/wham &&
3802 git rev-parse >actual \
3803 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3804 git rev-parse >expect \
3805 O:z/a O:z/b O:x/c O:x/d &&
3806 test_cmp expect actual &&
3808 # Test that the two-way merge in y/wham~merged is as expected
3809 git cat-file -p :2:y/wham >expect &&
3810 git cat-file -p :3:y/wham >other &&
3812 test_must_fail git merge-file \
3816 expect empty other &&
3817 test_cmp expect y/wham~merged
3821 ###########################################################################
3822 # SECTION 12: Everything else
3824 # Tests suggested by others. Tests added after implementation completed
3825 # and submitted. Grab bag.
3826 ###########################################################################
3828 # Testcase 12a, Moving one directory hierarchy into another
3829 # (Related to testcase 9a)
3830 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3831 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3832 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3833 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3835 test_expect_success '12a-setup: Moving one directory hierarchy into another' '
3836 test_create_repo 12a &&
3840 mkdir -p node1 node2 &&
3841 echo leaf1 >node1/leaf1 &&
3842 echo leaf2 >node1/leaf2 &&
3843 echo leaf3 >node2/leaf3 &&
3844 echo leaf4 >node2/leaf4 &&
3845 git add node1 node2 &&
3847 git commit -m "O" &&
3854 git mv node2/ node1/ &&
3856 git commit -m "A" &&
3859 echo leaf5 >node1/leaf5 &&
3860 echo leaf6 >node2/leaf6 &&
3861 git add node1 node2 &&
3867 test_expect_success '12a-check: Moving one directory hierarchy into another' '
3873 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3875 git ls-files -s >out &&
3876 test_line_count = 6 out &&
3878 git rev-parse >actual \
3879 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3880 HEAD:node1/node2/leaf3 \
3881 HEAD:node1/node2/leaf4 \
3882 HEAD:node1/node2/leaf6 &&
3883 git rev-parse >expect \
3884 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3888 test_cmp expect actual
3892 # Testcase 12b, Moving two directory hierarchies into each other
3893 # (Related to testcases 1c and 12c)
3894 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3895 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3896 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3897 # Expected: node1/node2/node1/{leaf1, leaf2},
3898 # node2/node1/node2/{leaf3, leaf4}
3899 # NOTE: Without directory renames, we would expect
3900 # node2/node1/{leaf1, leaf2},
3901 # node1/node2/{leaf3, leaf4}
3902 # with directory rename detection, we note that
3903 # commit A renames node2/ -> node1/node2/
3904 # commit B renames node1/ -> node2/node1/
3905 # therefore, applying those directory renames to the initial result
3906 # (making all four paths experience a transitive renaming), yields
3907 # the expected result.
3909 # You may ask, is it weird to have two directories rename each other?
3910 # To which, I can do no more than shrug my shoulders and say that
3911 # even simple rules give weird results when given weird inputs.
3913 test_expect_success '12b-setup: Moving two directory hierarchies into each other' '
3914 test_create_repo 12b &&
3918 mkdir -p node1 node2 &&
3919 echo leaf1 >node1/leaf1 &&
3920 echo leaf2 >node1/leaf2 &&
3921 echo leaf3 >node2/leaf3 &&
3922 echo leaf4 >node2/leaf4 &&
3923 git add node1 node2 &&
3925 git commit -m "O" &&
3932 git mv node2/ node1/ &&
3934 git commit -m "A" &&
3937 git mv node1/ node2/ &&
3943 test_expect_success '12b-check: Moving two directory hierarchies into each other' '
3949 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3951 git ls-files -s >out &&
3952 test_line_count = 4 out &&
3954 git rev-parse >actual \
3955 HEAD:node1/node2/node1/leaf1 \
3956 HEAD:node1/node2/node1/leaf2 \
3957 HEAD:node2/node1/node2/leaf3 \
3958 HEAD:node2/node1/node2/leaf4 &&
3959 git rev-parse >expect \
3964 test_cmp expect actual
3968 # Testcase 12c, Moving two directory hierarchies into each other w/ content merge
3969 # (Related to testcase 12b)
3970 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
3971 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
3972 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
3973 # Expected: Content merge conflicts for each of:
3974 # node1/node2/node1/{leaf1, leaf2},
3975 # node2/node1/node2/{leaf3, leaf4}
3976 # NOTE: This is *exactly* like 12c, except that every path is modified on
3977 # each side of the merge.
3979 test_expect_success '12c-setup: Moving one directory hierarchy into another w/ content merge' '
3980 test_create_repo 12c &&
3984 mkdir -p node1 node2 &&
3985 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
3986 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
3987 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
3988 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
3989 git add node1 node2 &&
3991 git commit -m "O" &&
3998 git mv node2/ node1/ &&
3999 for i in `git ls-files`; do echo side A >>$i; done &&
4002 git commit -m "A" &&
4005 git mv node1/ node2/ &&
4006 for i in `git ls-files`; do echo side B >>$i; done &&
4013 test_expect_success '12c-check: Moving one directory hierarchy into another w/ content merge' '
4019 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4021 git ls-files -u >out &&
4022 test_line_count = 12 out &&
4024 git rev-parse >actual \
4025 :1:node1/node2/node1/leaf1 \
4026 :1:node1/node2/node1/leaf2 \
4027 :1:node2/node1/node2/leaf3 \
4028 :1:node2/node1/node2/leaf4 \
4029 :2:node1/node2/node1/leaf1 \
4030 :2:node1/node2/node1/leaf2 \
4031 :2:node2/node1/node2/leaf3 \
4032 :2:node2/node1/node2/leaf4 \
4033 :3:node1/node2/node1/leaf1 \
4034 :3:node1/node2/node1/leaf2 \
4035 :3:node2/node1/node2/leaf3 \
4036 :3:node2/node1/node2/leaf4 &&
4037 git rev-parse >expect \
4044 A:node1/node2/leaf3 \
4045 A:node1/node2/leaf4 \
4046 B:node2/node1/leaf1 \
4047 B:node2/node1/leaf2 \
4050 test_cmp expect actual
4054 ###########################################################################
4055 # SECTION 13: Checking informational and conflict messages
4057 # A year after directory rename detection became the default, it was
4058 # instead decided to report conflicts on the pathname on the basis that
4059 # some users may expect the new files added or moved into a directory to
4060 # be unrelated to all the other files in that directory, and thus that
4061 # directory rename detection is unexpected. Test that the messages printed
4062 # match our expectation.
4063 ###########################################################################
4065 # Testcase 13a, Basic directory rename with newly added files
4068 # Commit B: z/{b,c,d,e/f}
4069 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4071 test_expect_success '13a-setup: messages for newly added files' '
4072 test_create_repo 13a &&
4081 git commit -m "O" &&
4090 git commit -m "A" &&
4096 git add z/d z/e/f &&
4102 test_expect_success '13a-check(conflict): messages for newly added files' '
4108 test_must_fail git merge -s recursive B^0 >out 2>err &&
4110 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4111 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4113 git ls-files >paths &&
4115 grep "y/[de]" paths &&
4117 test_path_is_missing z/d &&
4118 test_path_is_file y/d &&
4119 test_path_is_missing z/e/f &&
4120 test_path_is_file y/e/f
4124 test_expect_success '13a-check(info): messages for newly added files' '
4131 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4133 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4134 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4136 git ls-files >paths &&
4138 grep "y/[de]" paths &&
4140 test_path_is_missing z/d &&
4141 test_path_is_file y/d &&
4142 test_path_is_missing z/e/f &&
4143 test_path_is_file y/e/f
4147 # Testcase 13b, Transitive rename with conflicted content merge and default
4148 # "conflict" setting
4149 # (Related to testcase 1c, 9b)
4150 # Commit O: z/{b,c}, x/d_1
4151 # Commit A: y/{b,c}, x/d_2
4152 # Commit B: z/{b,c,d_3}
4153 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4154 # one about content, and one about file location
4156 test_expect_success '13b-setup: messages for transitive rename with conflicted content' '
4157 test_create_repo 13b &&
4163 test_seq 1 10 >x/d &&
4168 git commit -m "O" &&
4179 git commit -m "A" &&
4182 echo eleven >>x/d &&
4190 test_expect_success '13b-check(conflict): messages for transitive rename with conflicted content' '
4196 test_must_fail git merge -s recursive B^0 >out 2>err &&
4198 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4199 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4201 git ls-files >paths &&
4205 test_path_is_missing z/d &&
4206 test_path_is_file y/d
4210 test_expect_success '13b-check(info): messages for transitive rename with conflicted content' '
4217 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4219 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4220 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4222 git ls-files >paths &&
4226 test_path_is_missing z/d &&
4227 test_path_is_file y/d
4231 # Testcase 13c, Rename/rename(1to1) due to directory rename
4232 # Commit O: z/{b,c}, x/{d,e}
4233 # Commit A: y/{b,c,d}, x/e
4234 # Commit B: z/{b,c,d}, x/e
4235 # Expected: y/{b,c,d}, with info or conflict messages for d (
4236 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4237 # One could argue A had partial knowledge of what was done with
4238 # d and B had full knowledge, but that's a slippery slope as
4239 # shown in testcase 13d.
4241 test_expect_success '13c-setup: messages for rename/rename(1to1) via transitive rename' '
4242 test_create_repo 13c &&
4248 test_seq 1 10 >x/d &&
4254 git commit -m "O" &&
4264 git commit -m "A" &&
4274 test_expect_success '13c-check(conflict): messages for rename/rename(1to1) via transitive rename' '
4280 test_must_fail git merge -s recursive B^0 >out 2>err &&
4282 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4284 git ls-files >paths &&
4288 test_path_is_missing z/d &&
4289 test_path_is_file y/d
4293 test_expect_success '13c-check(info): messages for rename/rename(1to1) via transitive rename' '
4300 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4302 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4304 git ls-files >paths &&
4308 test_path_is_missing z/d &&
4309 test_path_is_file y/d
4313 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4314 # Commit O: a/{z,y}, b/x, c/w
4315 # Commit A: a/z, b/{y,x}, d/w
4316 # Commit B: a/z, d/x, c/{y,w}
4317 # Expected: a/z, d/{y,x,w} with no file location conflict for x
4319 # * z is always in a; so it stays in a.
4320 # * x starts in b, only modified on one side to move into d/
4321 # * w starts in c, only modified on one side to move into d/
4323 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
4324 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
4325 # No conflict in where a/y ends up, so put it in d/y.
4327 test_expect_success '13d-setup: messages for rename/rename(1to1) via dual transitive rename' '
4328 test_create_repo 13d &&
4341 git commit -m "O" &&
4351 git commit -m "A" &&
4361 test_expect_success '13d-check(conflict): messages for rename/rename(1to1) via dual transitive rename' '
4367 test_must_fail git merge -s recursive B^0 >out 2>err &&
4369 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
4370 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
4372 git ls-files >paths &&
4377 test_path_is_missing b/y &&
4378 test_path_is_missing c/y &&
4379 test_path_is_file d/y
4383 test_expect_success '13d-check(info): messages for rename/rename(1to1) via dual transitive rename' '
4390 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4392 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
4393 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
4395 git ls-files >paths &&
4400 test_path_is_missing b/y &&
4401 test_path_is_missing c/y &&
4402 test_path_is_file d/y