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_failure '1a-check: Simple directory rename detection' '
78 git merge -s recursive B^0 &&
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_failure '1b-check: Merge a directory with another' '
145 git 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 # Commit O: z/{b,c}, x/d
163 # Commit A: y/{b,c}, x/d
164 # Commit B: z/{b,c,d}
165 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
167 test_expect_success '1c-setup: Transitive renaming' '
168 test_create_repo 1c &&
197 test_expect_failure '1c-check: Transitive renaming' '
203 git merge -s recursive B^0 &&
205 git ls-files -s >out &&
206 test_line_count = 3 out &&
208 git rev-parse >actual \
209 HEAD:y/b HEAD:y/c HEAD:y/d &&
210 git rev-parse >expect \
212 test_cmp expect actual &&
213 test_must_fail git rev-parse HEAD:x/d &&
214 test_must_fail git rev-parse HEAD:z/d &&
215 test_path_is_missing z/d
219 # Testcase 1d, Directory renames (merging two directories into one new one)
220 # cause a rename/rename(2to1) conflict
221 # (Related to testcases 1c and 7b)
222 # Commit O. z/{b,c}, y/{d,e}
223 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
224 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
225 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
226 # Note: y/m & z/n should definitely move into x. By the same token, both
227 # y/wham_1 & z/wham_2 should too...giving us a conflict.
229 test_expect_success '1d-setup: Directory renames cause a rename/rename(2to1) conflict' '
230 test_create_repo 1d &&
251 echo wham1 >y/wham &&
259 echo wham2 >z/wham &&
266 test_expect_failure '1d-check: Directory renames cause a rename/rename(2to1) conflict' '
272 test_must_fail git merge -s recursive B^0 >out &&
273 test_i18ngrep "CONFLICT (rename/rename)" out &&
275 git ls-files -s >out &&
276 test_line_count = 8 out &&
277 git ls-files -u >out &&
278 test_line_count = 2 out &&
279 git ls-files -o >out &&
280 test_line_count = 3 out &&
282 git rev-parse >actual \
283 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
284 git rev-parse >expect \
285 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
286 test_cmp expect actual &&
288 test_must_fail git rev-parse :0:x/wham &&
289 git rev-parse >actual \
290 :2:x/wham :3:x/wham &&
291 git rev-parse >expect \
293 test_cmp expect actual &&
295 test_path_is_missing x/wham &&
296 test_path_is_file x/wham~HEAD &&
297 test_path_is_file x/wham~B^0 &&
299 git hash-object >actual \
300 x/wham~HEAD x/wham~B^0 &&
301 git rev-parse >expect \
303 test_cmp expect actual
307 # Testcase 1e, Renamed directory, with all filenames being renamed too
308 # (Related to testcases 9f & 9g)
309 # Commit O: z/{oldb,oldc}
310 # Commit A: y/{newb,newc}
311 # Commit B: z/{oldb,oldc,d}
312 # Expected: y/{newb,newc,d}
314 test_expect_success '1e-setup: Renamed directory, with all files being renamed too' '
315 test_create_repo 1e &&
332 git mv z/oldb y/newb &&
333 git mv z/oldc y/newc &&
345 test_expect_failure '1e-check: Renamed directory, with all files being renamed too' '
351 git merge -s recursive B^0 &&
353 git ls-files -s >out &&
354 test_line_count = 3 out &&
356 git rev-parse >actual \
357 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
358 git rev-parse >expect \
359 O:z/oldb O:z/oldc B:z/d &&
360 test_cmp expect actual &&
361 test_must_fail git rev-parse HEAD:z/d
365 # Testcase 1f, Split a directory into two other directories
366 # (Related to testcases 3a, all of section 2, and all of section 4)
367 # Commit O: z/{b,c,d,e,f}
368 # Commit A: z/{b,c,d,e,f,g}
369 # Commit B: y/{b,c}, x/{d,e,f}
370 # Expected: y/{b,c}, x/{d,e,f,g}
372 test_expect_success '1f-setup: Split a directory into two other directories' '
373 test_create_repo 1f &&
411 test_expect_failure '1f-check: Split a directory into two other directories' '
417 git merge -s recursive B^0 &&
419 git ls-files -s >out &&
420 test_line_count = 6 out &&
422 git rev-parse >actual \
423 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
424 git rev-parse >expect \
425 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
426 test_cmp expect actual &&
427 test_path_is_missing z/g &&
428 test_must_fail git rev-parse HEAD:z/g
432 ###########################################################################
433 # Rules suggested by testcases in section 1:
435 # We should still detect the directory rename even if it wasn't just
436 # the directory renamed, but the files within it. (see 1b)
438 # If renames split a directory into two or more others, the directory
439 # with the most renames, "wins" (see 1c). However, see the testcases
440 # in section 2, plus testcases 3a and 4a.
441 ###########################################################################
444 ###########################################################################
445 # SECTION 2: Split into multiple directories, with equal number of paths
447 # Explore the splitting-a-directory rules a bit; what happens in the
450 # Note that there is a closely related case of a directory not being
451 # split on either side of history, but being renamed differently on
452 # each side. See testcase 8e for that.
453 ###########################################################################
455 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
458 # Commit B: z/{b,c,d}
459 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
460 test_expect_success '2a-setup: Directory split into two on one side, with equal numbers of paths' '
461 test_create_repo 2a &&
492 test_expect_failure '2a-check: Directory split into two on one side, with equal numbers of paths' '
498 test_must_fail git merge -s recursive B^0 >out &&
499 test_i18ngrep "CONFLICT.*directory rename split" out &&
501 git ls-files -s >out &&
502 test_line_count = 3 out &&
503 git ls-files -u >out &&
504 test_line_count = 0 out &&
505 git ls-files -o >out &&
506 test_line_count = 1 out &&
508 git rev-parse >actual \
509 :0:y/b :0:w/c :0:z/d &&
510 git rev-parse >expect \
512 test_cmp expect actual
516 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
519 # Commit B: z/{b,c}, x/d
520 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
521 test_expect_success '2b-setup: Directory split into two on one side, with equal numbers of paths' '
522 test_create_repo 2b &&
554 test_expect_success '2b-check: Directory split into two on one side, with equal numbers of paths' '
560 git merge -s recursive B^0 >out &&
562 git ls-files -s >out &&
563 test_line_count = 3 out &&
564 git ls-files -u >out &&
565 test_line_count = 0 out &&
566 git ls-files -o >out &&
567 test_line_count = 1 out &&
569 git rev-parse >actual \
570 :0:y/b :0:w/c :0:x/d &&
571 git rev-parse >expect \
573 test_cmp expect actual &&
574 test_i18ngrep ! "CONFLICT.*directory rename split" out
578 ###########################################################################
579 # Rules suggested by section 2:
581 # None; the rule was already covered in section 1. These testcases are
582 # here just to make sure the conflict resolution and necessary warning
583 # messages are handled correctly.
584 ###########################################################################
587 ###########################################################################
588 # SECTION 3: Path in question is the source path for some rename already
590 # Combining cases from Section 1 and trying to handle them could lead to
591 # directory renaming detection being over-applied. So, this section
592 # provides some good testcases to check that the implementation doesn't go
594 ###########################################################################
596 # Testcase 3a, Avoid implicit rename if involved as source on other side
597 # (Related to testcases 1c, 1f, and 9h)
598 # Commit O: z/{b,c,d}
599 # Commit A: z/{b,c,d} (no change)
600 # Commit B: y/{b,c}, x/d
601 # Expected: y/{b,c}, x/d
602 test_expect_success '3a-setup: Avoid implicit rename if involved as source on other side' '
603 test_create_repo 3a &&
621 git commit --allow-empty -m "A" &&
635 test_expect_success '3a-check: Avoid implicit rename if involved as source on other side' '
641 git merge -s recursive B^0 &&
643 git ls-files -s >out &&
644 test_line_count = 3 out &&
646 git rev-parse >actual \
647 HEAD:y/b HEAD:y/c HEAD:x/d &&
648 git rev-parse >expect \
650 test_cmp expect actual
654 # Testcase 3b, Avoid implicit rename if involved as source on other side
655 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
656 # Commit O: z/{b,c,d}
657 # Commit A: y/{b,c}, x/d
658 # Commit B: z/{b,c}, w/d
659 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
660 # NOTE: We're particularly checking that since z/d is already involved as
661 # a source in a file rename on the same side of history, that we don't
662 # get it involved in directory rename detection. If it were, we might
663 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
664 # rename/rename/rename(1to3) conflict, which is just weird.
665 test_expect_success '3b-setup: Avoid implicit rename if involved as source on current side' '
666 test_create_repo 3b &&
700 test_expect_success '3b-check: Avoid implicit rename if involved as source on current side' '
706 test_must_fail git merge -s recursive B^0 >out &&
707 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
708 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
710 git ls-files -s >out &&
711 test_line_count = 5 out &&
712 git ls-files -u >out &&
713 test_line_count = 3 out &&
714 git ls-files -o >out &&
715 test_line_count = 1 out &&
717 git rev-parse >actual \
718 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
719 git rev-parse >expect \
720 O:z/b O:z/c O:z/d O:z/d O:z/d &&
721 test_cmp expect actual &&
723 test_path_is_missing z/d &&
724 git hash-object >actual \
726 git rev-parse >expect \
728 test_cmp expect actual
732 ###########################################################################
733 # Rules suggested by section 3:
735 # Avoid directory-rename-detection for a path, if that path is the source
736 # of a rename on either side of a merge.
737 ###########################################################################
740 ###########################################################################
741 # SECTION 4: Partially renamed directory; still exists on both sides of merge
743 # What if we were to attempt to do directory rename detection when someone
744 # "mostly" moved a directory but still left some files around, or,
745 # equivalently, fully renamed a directory in one commmit and then recreated
746 # that directory in a later commit adding some new files and then tried to
749 # It's hard to divine user intent in these cases, because you can make an
750 # argument that, depending on the intermediate history of the side being
751 # merged, that some users will want files in that directory to
752 # automatically be detected and renamed, while users with a different
753 # intermediate history wouldn't want that rename to happen.
755 # I think that it is best to simply not have directory rename detection
756 # apply to such cases. My reasoning for this is four-fold: (1) it's
757 # easiest for users in general to figure out what happened if we don't
758 # apply directory rename detection in any such case, (2) it's an easy rule
759 # to explain ["We don't do directory rename detection if the directory
760 # still exists on both sides of the merge"], (3) we can get some hairy
761 # edge/corner cases that would be really confusing and possibly not even
762 # representable in the index if we were to even try, and [related to 3] (4)
763 # attempting to resolve this issue of divining user intent by examining
764 # intermediate history goes against the spirit of three-way merges and is a
765 # path towards crazy corner cases that are far more complex than what we're
766 # already dealing with.
768 # Note that the wording of the rule ("We don't do directory rename
769 # detection if the directory still exists on both sides of the merge.")
770 # also excludes "renaming" of a directory into a subdirectory of itself
771 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
772 # out an exception for "renaming"-beneath-itself cases without opening
773 # weird edge/corner cases for other partial directory renames, but for now
774 # we are keeping the rule simple.
776 # This section contains a test for a partially-renamed-directory case.
777 ###########################################################################
779 # Testcase 4a, Directory split, with original directory still present
780 # (Related to testcase 1f)
781 # Commit O: z/{b,c,d,e}
782 # Commit A: y/{b,c,d}, z/e
783 # Commit B: z/{b,c,d,e,f}
784 # Expected: y/{b,c,d}, z/{e,f}
785 # NOTE: Even though most files from z moved to y, we don't want f to follow.
787 test_expect_success '4a-setup: Directory split, with original directory still present' '
788 test_create_repo 4a &&
821 test_expect_success '4a-check: Directory split, with original directory still present' '
827 git merge -s recursive B^0 &&
829 git ls-files -s >out &&
830 test_line_count = 5 out &&
831 git ls-files -u >out &&
832 test_line_count = 0 out &&
833 git ls-files -o >out &&
834 test_line_count = 1 out &&
836 git rev-parse >actual \
837 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
838 git rev-parse >expect \
839 O:z/b O:z/c O:z/d O:z/e B:z/f &&
840 test_cmp expect actual
844 ###########################################################################
845 # Rules suggested by section 4:
847 # Directory-rename-detection should be turned off for any directories (as
848 # a source for renames) that exist on both sides of the merge. (The "as
849 # a source for renames" clarification is due to cases like 1c where
850 # the target directory exists on both sides and we do want the rename
851 # detection.) But, sadly, see testcase 8b.
852 ###########################################################################
855 ###########################################################################
856 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
858 # Implicitly renaming files due to a detected directory rename could run
859 # into problems if there are files or directories in the way of the paths
860 # we want to rename. Explore such cases in this section.
861 ###########################################################################
863 # Testcase 5a, Merge directories, other side adds files to original and target
864 # Commit O: z/{b,c}, y/d
865 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
866 # Commit B: y/{b,c,d}
867 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
868 # NOTE: While directory rename detection is active here causing z/f to
869 # become y/f, we did not apply this for z/e_1 because that would
870 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
871 # this add/add, is that both versions of y/e are from the same side
872 # of history, giving us no way to represent this conflict in the
875 test_expect_success '5a-setup: Merge directories, other side adds files to original and target' '
876 test_create_repo 5a &&
897 git add z/e z/f y/e &&
910 test_expect_failure '5a-check: Merge directories, other side adds files to original and target' '
916 test_must_fail git merge -s recursive B^0 >out &&
917 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
919 git ls-files -s >out &&
920 test_line_count = 6 out &&
921 git ls-files -u >out &&
922 test_line_count = 0 out &&
923 git ls-files -o >out &&
924 test_line_count = 1 out &&
926 git rev-parse >actual \
927 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
928 git rev-parse >expect \
929 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
930 test_cmp expect actual
934 # Testcase 5b, Rename/delete in order to get add/add/add conflict
935 # (Related to testcase 8d; these may appear slightly inconsistent to users;
936 # Also related to testcases 7d and 7e)
937 # Commit O: z/{b,c,d_1}
938 # Commit A: y/{b,c,d_2}
939 # Commit B: z/{b,c,d_1,e}, y/d_3
940 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
941 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
942 # we normaly would since z/ is being renamed to y/, then this would be
943 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
944 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
945 # representable in the index, so the existence of y/d_3 needs to
946 # cause us to bail on directory rename detection for that path, falling
947 # back to git behavior without the directory rename detection.
949 test_expect_success '5b-setup: Rename/delete in order to get add/add/add conflict' '
950 test_create_repo 5b &&
984 test_expect_failure '5b-check: Rename/delete in order to get add/add/add conflict' '
990 test_must_fail git merge -s recursive B^0 >out &&
991 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
993 git ls-files -s >out &&
994 test_line_count = 5 out &&
995 git ls-files -u >out &&
996 test_line_count = 2 out &&
997 git ls-files -o >out &&
998 test_line_count = 1 out &&
1000 git rev-parse >actual \
1001 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1002 git rev-parse >expect \
1003 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1004 test_cmp expect actual &&
1006 test_must_fail git rev-parse :1:y/d &&
1007 test_path_is_file y/d
1011 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1012 # (Directory rename detection would result in transitive rename vs.
1013 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1014 # rename paths conflict with separate adds on the other side)
1015 # (Related to testcases 3b and 7c)
1016 # Commit O: z/{b,c}, x/d_1
1017 # Commit A: y/{b,c,d_2}, w/d_1
1018 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1019 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1020 # presence of y/d_4 in B to avoid doing transitive rename of
1021 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1022 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1023 # though, because it doesn't have anything in the way.
1025 test_expect_success '5c-setup: Transitive rename would cause rename/rename/rename/add/add/add' '
1026 test_create_repo 5c &&
1037 git commit -m "O" &&
1049 git commit -m "A" &&
1058 git add w/ y/ z/e &&
1064 test_expect_failure '5c-check: Transitive rename would cause rename/rename/rename/add/add/add' '
1070 test_must_fail git merge -s recursive B^0 >out &&
1071 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1072 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1074 git ls-files -s >out &&
1075 test_line_count = 9 out &&
1076 git ls-files -u >out &&
1077 test_line_count = 6 out &&
1078 git ls-files -o >out &&
1079 test_line_count = 3 out &&
1081 git rev-parse >actual \
1082 :0:y/b :0:y/c :0:y/e &&
1083 git rev-parse >expect \
1084 O:z/b O:z/c B:z/e &&
1085 test_cmp expect actual &&
1087 test_must_fail git rev-parse :1:y/d &&
1088 git rev-parse >actual \
1089 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1090 git rev-parse >expect \
1091 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1092 test_cmp expect actual &&
1094 git hash-object >actual \
1095 w/d~HEAD w/d~B^0 z/d &&
1096 git rev-parse >expect \
1097 O:x/d B:w/d O:x/d &&
1098 test_cmp expect actual &&
1099 test_path_is_missing x/d &&
1100 test_path_is_file y/d &&
1101 grep -q "<<<<" y/d # conflict markers should be present
1105 # Testcase 5d, Directory/file/file conflict due to directory rename
1107 # Commit A: y/{b,c,d_1}
1108 # Commit B: z/{b,c,d_2,f}, y/d/e
1109 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1110 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1111 # detection for z/d_2, but that doesn't prevent us from applying the
1112 # directory rename detection for z/f -> y/f.
1114 test_expect_success '5d-setup: Directory/file/file conflict due to directory rename' '
1115 test_create_repo 5d &&
1124 git commit -m "O" &&
1135 git commit -m "A" &&
1142 git add y/d/e z/d z/f &&
1148 test_expect_failure '5d-check: Directory/file/file conflict due to directory rename' '
1154 test_must_fail git merge -s recursive B^0 >out &&
1155 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1157 git ls-files -s >out &&
1158 test_line_count = 6 out &&
1159 git ls-files -u >out &&
1160 test_line_count = 1 out &&
1161 git ls-files -o >out &&
1162 test_line_count = 2 out &&
1164 git rev-parse >actual \
1165 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1166 git rev-parse >expect \
1167 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1168 test_cmp expect actual &&
1170 git hash-object y/d~HEAD >actual &&
1171 git rev-parse A:y/d >expect &&
1172 test_cmp expect actual
1176 ###########################################################################
1177 # Rules suggested by section 5:
1179 # If a subset of to-be-renamed files have a file or directory in the way,
1180 # "turn off" the directory rename for those specific sub-paths, falling
1181 # back to old handling. But, sadly, see testcases 8a and 8b.
1182 ###########################################################################
1185 ###########################################################################
1186 # SECTION 6: Same side of the merge was the one that did the rename
1188 # It may sound obvious that you only want to apply implicit directory
1189 # renames to directories if the _other_ side of history did the renaming.
1190 # If you did make an implementation that didn't explicitly enforce this
1191 # rule, the majority of cases that would fall under this section would
1192 # also be solved by following the rules from the above sections. But
1193 # there are still a few that stick out, so this section covers them just
1194 # to make sure we also get them right.
1195 ###########################################################################
1197 # Testcase 6a, Tricky rename/delete
1198 # Commit O: z/{b,c,d}
1200 # Commit B: y/{b,c}, z/d
1201 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1202 # Note: We're just checking here that the rename of z/b and z/c to put
1203 # them under y/ doesn't accidentally catch z/d and make it look like
1204 # it is also involved in a rename/delete conflict.
1206 test_expect_success '6a-setup: Tricky rename/delete' '
1207 test_create_repo 6a &&
1217 git commit -m "O" &&
1227 git commit -m "A" &&
1238 test_expect_success '6a-check: Tricky rename/delete' '
1244 test_must_fail git merge -s recursive B^0 >out &&
1245 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1247 git ls-files -s >out &&
1248 test_line_count = 2 out &&
1249 git ls-files -u >out &&
1250 test_line_count = 1 out &&
1251 git ls-files -o >out &&
1252 test_line_count = 1 out &&
1254 git rev-parse >actual \
1256 git rev-parse >expect \
1258 test_cmp expect actual
1262 # Testcase 6b, Same rename done on both sides
1263 # (Related to testcases 6c and 8e)
1266 # Commit B: y/{b,c}, z/d
1267 # Expected: y/{b,c}, z/d
1268 # Note: If we did directory rename detection here, we'd move z/d into y/,
1269 # but B did that rename and still decided to put the file into z/,
1270 # so we probably shouldn't apply directory rename detection for it.
1272 test_expect_success '6b-setup: Same rename done on both sides' '
1273 test_create_repo 6b &&
1282 git commit -m "O" &&
1291 git commit -m "A" &&
1303 test_expect_success '6b-check: Same rename done on both sides' '
1309 git merge -s recursive B^0 &&
1311 git ls-files -s >out &&
1312 test_line_count = 3 out &&
1313 git ls-files -u >out &&
1314 test_line_count = 0 out &&
1315 git ls-files -o >out &&
1316 test_line_count = 1 out &&
1318 git rev-parse >actual \
1319 HEAD:y/b HEAD:y/c HEAD:z/d &&
1320 git rev-parse >expect \
1321 O:z/b O:z/c B:z/d &&
1322 test_cmp expect actual
1326 # Testcase 6c, Rename only done on same side
1327 # (Related to testcases 6b and 8e)
1329 # Commit A: z/{b,c} (no change)
1330 # Commit B: y/{b,c}, z/d
1331 # Expected: y/{b,c}, z/d
1332 # NOTE: Seems obvious, but just checking that the implementation doesn't
1333 # "accidentally detect a rename" and give us y/{b,c,d}.
1335 test_expect_success '6c-setup: Rename only done on same side' '
1336 test_create_repo 6c &&
1345 git commit -m "O" &&
1353 git commit --allow-empty -m "A" &&
1365 test_expect_success '6c-check: Rename only done on same side' '
1371 git merge -s recursive B^0 &&
1373 git ls-files -s >out &&
1374 test_line_count = 3 out &&
1375 git ls-files -u >out &&
1376 test_line_count = 0 out &&
1377 git ls-files -o >out &&
1378 test_line_count = 1 out &&
1380 git rev-parse >actual \
1381 HEAD:y/b HEAD:y/c HEAD:z/d &&
1382 git rev-parse >expect \
1383 O:z/b O:z/c B:z/d &&
1384 test_cmp expect actual
1388 # Testcase 6d, We don't always want transitive renaming
1389 # (Related to testcase 1c)
1390 # Commit O: z/{b,c}, x/d
1391 # Commit A: z/{b,c}, x/d (no change)
1392 # Commit B: y/{b,c}, z/d
1393 # Expected: y/{b,c}, z/d
1394 # NOTE: Again, this seems obvious but just checking that the implementation
1395 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1397 test_expect_success '6d-setup: We do not always want transitive renaming' '
1398 test_create_repo 6d &&
1409 git commit -m "O" &&
1417 git commit --allow-empty -m "A" &&
1427 test_expect_success '6d-check: We do not always want transitive renaming' '
1433 git merge -s recursive B^0 &&
1435 git ls-files -s >out &&
1436 test_line_count = 3 out &&
1437 git ls-files -u >out &&
1438 test_line_count = 0 out &&
1439 git ls-files -o >out &&
1440 test_line_count = 1 out &&
1442 git rev-parse >actual \
1443 HEAD:y/b HEAD:y/c HEAD:z/d &&
1444 git rev-parse >expect \
1445 O:z/b O:z/c O:x/d &&
1446 test_cmp expect actual
1450 # Testcase 6e, Add/add from one-side
1452 # Commit A: z/{b,c} (no change)
1453 # Commit B: y/{b,c,d_1}, z/d_2
1454 # Expected: y/{b,c,d_1}, z/d_2
1455 # NOTE: Again, this seems obvious but just checking that the implementation
1456 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1457 # add/add conflict on y/d_1 vs y/d_2.
1459 test_expect_success '6e-setup: Add/add from one side' '
1460 test_create_repo 6e &&
1469 git commit -m "O" &&
1477 git commit --allow-empty -m "A" &&
1490 test_expect_success '6e-check: Add/add from one side' '
1496 git merge -s recursive B^0 &&
1498 git ls-files -s >out &&
1499 test_line_count = 4 out &&
1500 git ls-files -u >out &&
1501 test_line_count = 0 out &&
1502 git ls-files -o >out &&
1503 test_line_count = 1 out &&
1505 git rev-parse >actual \
1506 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1507 git rev-parse >expect \
1508 O:z/b O:z/c B:y/d B:z/d &&
1509 test_cmp expect actual
1513 ###########################################################################
1514 # Rules suggested by section 6:
1516 # Only apply implicit directory renames to directories if the other
1517 # side of history is the one doing the renaming.
1518 ###########################################################################
1521 ###########################################################################
1522 # SECTION 7: More involved Edge/Corner cases
1524 # The ruleset we have generated in the above sections seems to provide
1525 # well-defined merges. But can we find edge/corner cases that either (a)
1526 # are harder for users to understand, or (b) have a resolution that is
1527 # non-intuitive or suboptimal?
1529 # The testcases in this section dive into cases that I've tried to craft in
1530 # a way to find some that might be surprising to users or difficult for
1531 # them to understand (the next section will look at non-intuitive or
1532 # suboptimal merge results). Some of the testcases are similar to ones
1533 # from past sections, but have been simplified to try to highlight error
1534 # messages using a "modified" path (due to the directory rename). Are
1535 # users okay with these?
1537 # In my opinion, testcases that are difficult to understand from this
1538 # section is due to difficulty in the testcase rather than the directory
1539 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1540 # to the problem setup itself being complex). And I don't think the
1541 # error messages are a problem.
1543 # On the other hand, the testcases in section 8 worry me slightly more...
1544 ###########################################################################
1546 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1549 # Commit B: w/b, x/c, z/d
1550 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1551 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1553 test_expect_success '7a-setup: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1554 test_create_repo 7a &&
1563 git commit -m "O" &&
1572 git commit -m "A" &&
1586 test_expect_failure '7a-check: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1592 test_must_fail git merge -s recursive B^0 >out &&
1593 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1594 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1596 git ls-files -s >out &&
1597 test_line_count = 7 out &&
1598 git ls-files -u >out &&
1599 test_line_count = 6 out &&
1600 git ls-files -o >out &&
1601 test_line_count = 1 out &&
1603 git rev-parse >actual \
1604 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1605 git rev-parse >expect \
1606 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1607 test_cmp expect actual &&
1609 git hash-object >actual \
1611 git rev-parse >expect \
1612 O:z/b O:z/b O:z/c O:z/c &&
1613 test_cmp expect actual
1617 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1618 # (Related to testcase 1d)
1619 # Commit O: z/{b,c}, x/d_1, w/d_2
1620 # Commit A: y/{b,c,d_2}, x/d_1
1621 # Commit B: z/{b,c,d_1}, w/d_2
1622 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1624 test_expect_success '7b-setup: rename/rename(2to1), but only due to transitive rename' '
1625 test_create_repo 7b &&
1638 git commit -m "O" &&
1648 git commit -m "A" &&
1658 test_expect_failure '7b-check: rename/rename(2to1), but only due to transitive rename' '
1664 test_must_fail git merge -s recursive B^0 >out &&
1665 test_i18ngrep "CONFLICT (rename/rename)" out &&
1667 git ls-files -s >out &&
1668 test_line_count = 4 out &&
1669 git ls-files -u >out &&
1670 test_line_count = 2 out &&
1671 git ls-files -o >out &&
1672 test_line_count = 3 out &&
1674 git rev-parse >actual \
1675 :0:y/b :0:y/c :2:y/d :3:y/d &&
1676 git rev-parse >expect \
1677 O:z/b O:z/c O:w/d O:x/d &&
1678 test_cmp expect actual &&
1680 test_path_is_missing y/d &&
1681 test_path_is_file y/d~HEAD &&
1682 test_path_is_file y/d~B^0 &&
1684 git hash-object >actual \
1686 git rev-parse >expect \
1688 test_cmp expect actual
1692 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1693 # (Related to testcases 3b and 5c)
1694 # Commit O: z/{b,c}, x/d
1695 # Commit A: y/{b,c}, w/d
1696 # Commit B: z/{b,c,d}
1697 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1698 # NOTE: z/ was renamed to y/ so we do want to report
1699 # neither CONFLICT(x/d -> w/d vs. z/d)
1700 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1702 test_expect_success '7c-setup: rename/rename(1to...2or3); transitive rename may add complexity' '
1703 test_create_repo 7c &&
1714 git commit -m "O" &&
1724 git commit -m "A" &&
1734 test_expect_failure '7c-check: rename/rename(1to...2or3); transitive rename may add complexity' '
1740 test_must_fail git merge -s recursive B^0 >out &&
1741 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1743 git ls-files -s >out &&
1744 test_line_count = 5 out &&
1745 git ls-files -u >out &&
1746 test_line_count = 3 out &&
1747 git ls-files -o >out &&
1748 test_line_count = 1 out &&
1750 git rev-parse >actual \
1751 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1752 git rev-parse >expect \
1753 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1754 test_cmp expect actual
1758 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1759 # (Related somewhat to testcases 5b and 8d)
1760 # Commit O: z/{b,c}, x/d
1762 # Commit B: z/{b,c,d}
1763 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1764 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1766 test_expect_success '7d-setup: transitive rename involved in rename/delete; how is it reported?' '
1767 test_create_repo 7d &&
1778 git commit -m "O" &&
1788 git commit -m "A" &&
1798 test_expect_failure '7d-check: transitive rename involved in rename/delete; how is it reported?' '
1804 test_must_fail git merge -s recursive B^0 >out &&
1805 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1807 git ls-files -s >out &&
1808 test_line_count = 3 out &&
1809 git ls-files -u >out &&
1810 test_line_count = 1 out &&
1811 git ls-files -o >out &&
1812 test_line_count = 1 out &&
1814 git rev-parse >actual \
1815 :0:y/b :0:y/c :3:y/d &&
1816 git rev-parse >expect \
1817 O:z/b O:z/c O:x/d &&
1818 test_cmp expect actual
1822 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1823 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1824 # (Also related to testcases 9c and 9d)
1825 # Commit O: z/{b,c}, x/d_1
1826 # Commit A: y/{b,c,d/g}, x/d/f
1827 # Commit B: z/{b,c,d_1}
1828 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1829 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1831 # NOTE: The main path of interest here is d_1 and where it ends up, but
1832 # this is actually a case that has two potential directory renames
1833 # involved and D/F conflict(s), so it makes sense to walk through
1836 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1837 # should be instead moved to y/. This gives us the D/F conflict on
1838 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1840 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1841 # should instead be moved to z/...BUT we removed z/ and renamed it
1842 # to y/, so maybe everything should move not from x/ to z/, but
1843 # from x/ to z/ to y/. Doing so might make sense from the logic so
1844 # far, but note that commit A had both an x/ and a y/; it did the
1845 # renaming of z/ to y/ and created x/d/f and it clearly made these
1846 # things separate, so it doesn't make much sense to push these
1847 # together. Doing so is what I'd call a doubly transitive rename;
1848 # see testcases 9c and 9d for further discussion of this issue and
1849 # how it's resolved.
1851 test_expect_success '7e-setup: transitive rename in rename/delete AND dirs in the way' '
1852 test_create_repo 7e &&
1863 git commit -m "O" &&
1876 git add x/d/f y/d/g &&
1878 git commit -m "A" &&
1888 test_expect_failure '7e-check: transitive rename in rename/delete AND dirs in the way' '
1894 test_must_fail git merge -s recursive B^0 >out &&
1895 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1897 git ls-files -s >out &&
1898 test_line_count = 5 out &&
1899 git ls-files -u >out &&
1900 test_line_count = 1 out &&
1901 git ls-files -o >out &&
1902 test_line_count = 2 out &&
1904 git rev-parse >actual \
1905 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
1906 git rev-parse >expect \
1907 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
1908 test_cmp expect actual &&
1910 git hash-object y/d~B^0 >actual &&
1911 git rev-parse O:x/d >expect &&
1912 test_cmp expect actual
1916 ###########################################################################
1917 # SECTION 8: Suboptimal merges
1919 # As alluded to in the last section, the ruleset we have built up for
1920 # detecting directory renames unfortunately has some special cases where it
1921 # results in slightly suboptimal or non-intuitive behavior. This section
1922 # explores these cases.
1924 # To be fair, we already had non-intuitive or suboptimal behavior for most
1925 # of these cases in git before introducing implicit directory rename
1926 # detection, but it'd be nice if there was a modified ruleset out there
1927 # that handled these cases a bit better.
1928 ###########################################################################
1930 # Testcase 8a, Dual-directory rename, one into the others' way
1931 # Commit O. x/{a,b}, y/{c,d}
1932 # Commit A. x/{a,b,e}, y/{c,d,f}
1933 # Commit B. y/{a,b}, z/{c,d}
1935 # Possible Resolutions:
1936 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
1937 # Currently expected: y/{a,b,e,f}, z/{c,d}
1938 # Optimal: y/{a,b,e}, z/{c,d,f}
1940 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
1941 # better with directory rename detection than git did without, but the
1942 # simple rule from section 5 prevents me from handling this as optimally as
1943 # we potentially could.
1945 test_expect_success '8a-setup: Dual-directory rename, one into the others way' '
1946 test_create_repo 8a &&
1958 git commit -m "O" &&
1969 git commit -m "A" &&
1979 test_expect_failure '8a-check: Dual-directory rename, one into the others way' '
1985 git merge -s recursive B^0 &&
1987 git ls-files -s >out &&
1988 test_line_count = 6 out &&
1989 git ls-files -u >out &&
1990 test_line_count = 0 out &&
1991 git ls-files -o >out &&
1992 test_line_count = 1 out &&
1994 git rev-parse >actual \
1995 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
1996 git rev-parse >expect \
1997 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
1998 test_cmp expect actual
2002 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2003 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2004 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2005 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2007 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2008 # Currently expected: <same>
2009 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2010 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2012 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2013 # y, both are named 'e'. Without directory rename detection, neither file
2014 # moves directories. Implement directory rename detection suboptimally, and
2015 # you get an add/add conflict, but both files were added in commit A, so this
2016 # is an add/add conflict where one side of history added both files --
2017 # something we can't represent in the index. Obviously, we'd prefer the last
2018 # resolution, but our previous rules are too coarse to allow it. Using both
2019 # the rules from section 4 and section 5 save us from the Scary resolution,
2020 # making us fall back to pre-directory-rename-detection behavior for both
2023 test_expect_success '8b-setup: Dual-directory rename, one into the others way, with conflicting filenames' '
2024 test_create_repo 8b &&
2036 git commit -m "O" &&
2047 git commit -m "A" &&
2057 test_expect_success '8b-check: Dual-directory rename, one into the others way, with conflicting filenames' '
2063 git merge -s recursive B^0 &&
2065 git ls-files -s >out &&
2066 test_line_count = 6 out &&
2067 git ls-files -u >out &&
2068 test_line_count = 0 out &&
2069 git ls-files -o >out &&
2070 test_line_count = 1 out &&
2072 git rev-parse >actual \
2073 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2074 git rev-parse >expect \
2075 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2076 test_cmp expect actual
2080 # Testcase 8c, rename+modify/delete
2081 # (Related to testcases 5b and 8d)
2082 # Commit O: z/{b,c,d}
2084 # Commit B: z/{b,c,d_modified,e}
2085 # Expected: y/{b,c,e}, CONFLICT(rename+modify/delete: x/d -> y/d or deleted)
2087 # Note: This testcase doesn't present any concerns for me...until you
2088 # compare it with testcases 5b and 8d. See notes in 8d for more
2091 test_expect_success '8c-setup: rename+modify/delete' '
2092 test_create_repo 8c &&
2099 test_seq 1 10 >z/d &&
2102 git commit -m "O" &&
2112 git commit -m "A" &&
2116 test_chmod +x z/d &&
2124 test_expect_failure '8c-check: rename+modify/delete' '
2130 test_must_fail git merge -s recursive B^0 >out &&
2131 test_i18ngrep "CONFLICT (rename/delete).* z/d.*y/d" out &&
2133 git ls-files -s >out &&
2134 test_line_count = 4 out &&
2135 git ls-files -u >out &&
2136 test_line_count = 1 out &&
2137 git ls-files -o >out &&
2138 test_line_count = 1 out &&
2140 git rev-parse >actual \
2141 :0:y/b :0:y/c :0:y/e :3:y/d &&
2142 git rev-parse >expect \
2143 O:z/b O:z/c B:z/e B:z/d &&
2144 test_cmp expect actual &&
2146 test_must_fail git rev-parse :1:y/d &&
2147 test_must_fail git rev-parse :2:y/d &&
2148 git ls-files -s y/d | grep ^100755 &&
2149 test_path_is_file y/d
2153 # Testcase 8d, rename/delete...or not?
2154 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2155 # Also related to testcases 7d and 7e)
2156 # Commit O: z/{b,c,d}
2158 # Commit B: z/{b,c,d,e}
2159 # Expected: y/{b,c,e}
2161 # Note: It would also be somewhat reasonable to resolve this as
2162 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2163 # The logic being that the only difference between this testcase and 8c
2164 # is that there is no modification to d. That suggests that instead of a
2165 # rename/modify vs. delete conflict, we should just have a rename/delete
2166 # conflict, otherwise we are being inconsistent.
2168 # However...as far as consistency goes, we didn't report a conflict for
2169 # path d_1 in testcase 5b due to a different file being in the way. So,
2170 # we seem to be forced to have cases where users can change things
2171 # slightly and get what they may perceive as inconsistent results. It
2172 # would be nice to avoid that, but I'm not sure I see how.
2174 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2175 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2176 # delete) are both coming from commit A, which is illogical. Conflicts
2177 # during merging are supposed to be about opposite sides doing things
2180 test_expect_success '8d-setup: rename/delete...or not?' '
2181 test_create_repo 8d &&
2188 test_seq 1 10 >z/d &&
2191 git commit -m "O" &&
2201 git commit -m "A" &&
2211 test_expect_failure '8d-check: rename/delete...or not?' '
2217 git merge -s recursive B^0 &&
2219 git ls-files -s >out &&
2220 test_line_count = 3 out &&
2222 git rev-parse >actual \
2223 HEAD:y/b HEAD:y/c HEAD:y/e &&
2224 git rev-parse >expect \
2225 O:z/b O:z/c B:z/e &&
2226 test_cmp expect actual
2230 # Testcase 8e, Both sides rename, one side adds to original directory
2233 # Commit B: w/{b,c}, z/d
2235 # Possible Resolutions:
2236 # w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2237 # CONFLICT(z/c -> y/c vs. w/c)
2238 # Currently expected: y/d, CONFLICT(z/b -> y/b vs. w/b),
2239 # CONFLICT(z/c -> y/c vs. w/c)
2242 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2243 # did NOT get renamed; the directory is still present; instead it is
2244 # considered to have just renamed a subset of paths in directory z
2245 # elsewhere. Therefore, the directory rename done in commit A to z/
2246 # applies to z/d and maps it to y/d.
2248 # It's possible that users would get confused about this, but what
2249 # should we do instead? Silently leaving at z/d seems just as bad or
2250 # maybe even worse. Perhaps we could print a big warning about z/d
2251 # and how we're moving to y/d in this case, but when I started thinking
2252 # about the ramifications of doing that, I didn't know how to rule out
2253 # that opening other weird edge and corner cases so I just punted.
2255 test_expect_success '8e-setup: Both sides rename, one side adds to original directory' '
2256 test_create_repo 8e &&
2265 git commit -m "O" &&
2274 git commit -m "A" &&
2286 test_expect_failure '8e-check: Both sides rename, one side adds to original directory' '
2292 test_must_fail git merge -s recursive B^0 >out 2>err &&
2293 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2294 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2296 git ls-files -s >out &&
2297 test_line_count = 7 out &&
2298 git ls-files -u >out &&
2299 test_line_count = 6 out &&
2300 git ls-files -o >out &&
2301 test_line_count = 2 out &&
2303 git rev-parse >actual \
2304 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2305 git rev-parse >expect \
2306 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2307 test_cmp expect actual &&
2309 git hash-object >actual \
2311 git rev-parse >expect \
2312 O:z/b O:z/b O:z/c O:z/c &&
2313 test_cmp expect actual &&
2315 test_path_is_missing z/b &&
2316 test_path_is_missing z/c
2320 ###########################################################################
2321 # SECTION 9: Other testcases
2323 # This section consists of miscellaneous testcases I thought of during
2324 # the implementation which round out the testing.
2325 ###########################################################################
2327 # Testcase 9a, Inner renamed directory within outer renamed directory
2328 # (Related to testcase 1f)
2329 # Commit O: z/{b,c,d/{e,f,g}}
2330 # Commit A: y/{b,c}, x/w/{e,f,g}
2331 # Commit B: z/{b,c,d/{e,f,g,h},i}
2332 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2333 # NOTE: The only reason this one is interesting is because when a directory
2334 # is split into multiple other directories, we determine by the weight
2335 # of which one had the most paths going to it. A naive implementation
2336 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2338 test_expect_success '9a-setup: Inner renamed directory within outer renamed directory' '
2339 test_create_repo 9a &&
2351 git commit -m "O" &&
2362 git commit -m "A" &&
2373 test_expect_failure '9a-check: Inner renamed directory within outer renamed directory' '
2379 git merge -s recursive B^0 &&
2381 git ls-files -s >out &&
2382 test_line_count = 7 out &&
2383 git ls-files -u >out &&
2384 test_line_count = 0 out &&
2385 git ls-files -o >out &&
2386 test_line_count = 1 out &&
2388 git rev-parse >actual \
2389 HEAD:y/b HEAD:y/c HEAD:y/i &&
2390 git rev-parse >expect \
2391 O:z/b O:z/c B:z/i &&
2392 test_cmp expect actual &&
2394 git rev-parse >actual \
2395 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2396 git rev-parse >expect \
2397 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2398 test_cmp expect actual
2402 # Testcase 9b, Transitive rename with content merge
2403 # (Related to testcase 1c)
2404 # Commit O: z/{b,c}, x/d_1
2405 # Commit A: y/{b,c}, x/d_2
2406 # Commit B: z/{b,c,d_3}
2407 # Expected: y/{b,c,d_merged}
2409 test_expect_success '9b-setup: Transitive rename with content merge' '
2410 test_create_repo 9b &&
2418 test_seq 1 10 >x/d &&
2421 git commit -m "O" &&
2429 test_seq 1 11 >x/d &&
2432 git commit -m "A" &&
2435 test_seq 0 10 >x/d &&
2443 test_expect_failure '9b-check: Transitive rename with content merge' '
2449 git merge -s recursive B^0 &&
2451 git ls-files -s >out &&
2452 test_line_count = 3 out &&
2454 test_seq 0 11 >expected &&
2455 test_cmp expected y/d &&
2457 git rev-parse >actual \
2458 HEAD:y/b HEAD:y/c HEAD:y/d &&
2459 git rev-parse >expect \
2460 O:z/b O:z/c :0:expected &&
2461 test_cmp expect actual &&
2462 test_must_fail git rev-parse HEAD:x/d &&
2463 test_must_fail git rev-parse HEAD:z/d &&
2464 test_path_is_missing z/d &&
2466 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2467 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2468 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2472 # Testcase 9c, Doubly transitive rename?
2473 # (Related to testcase 1c, 7e, and 9d)
2474 # Commit O: z/{b,c}, x/{d,e}, w/f
2475 # Commit A: y/{b,c}, x/{d,e,f,g}
2476 # Commit B: z/{b,c,d,e}, w/f
2477 # Expected: y/{b,c,d,e}, x/{f,g}
2479 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2480 # x/f is clear. Let's look beyond that. Here's the logic:
2481 # Commit B renamed x/ -> z/
2482 # Commit A renamed z/ -> y/
2483 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2484 # transient rename. However, where does it end? We can chain these
2485 # indefinitely (see testcase 9d). What if there is a D/F conflict
2486 # at z/f/ or y/f/? Or just another file conflict at one of those
2487 # paths? In the case of an N-long chain of transient renamings,
2488 # where do we "abort" the rename at? Can the user make sense of
2489 # the resulting conflict and resolve it?
2491 # To avoid this confusion I use the simple rule that if the other side
2492 # of history did a directory rename to a path that your side renamed
2493 # away, then ignore that particular rename from the other side of
2494 # history for any implicit directory renames.
2496 test_expect_success '9c-setup: Doubly transitive rename?' '
2497 test_create_repo 9c &&
2511 git commit -m "O" &&
2523 git commit -m "A" &&
2533 test_expect_failure '9c-check: Doubly transitive rename?' '
2539 git merge -s recursive B^0 >out &&
2540 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2542 git ls-files -s >out &&
2543 test_line_count = 6 out &&
2544 git ls-files -o >out &&
2545 test_line_count = 1 out &&
2547 git rev-parse >actual \
2548 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2549 git rev-parse >expect \
2550 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2551 test_cmp expect actual
2555 # Testcase 9d, N-fold transitive rename?
2556 # (Related to testcase 9c...and 1c and 7e)
2557 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2558 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2559 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2560 # Expected: <see NOTE first>
2562 # NOTE: z/ -> y/ (in commit A)
2563 # y/ -> x/ (in commit B)
2564 # x/ -> w/ (in commit A)
2565 # w/ -> v/ (in commit B)
2566 # v/ -> u/ (in commit A)
2567 # So, if we add a file to z, say z/t, where should it end up? In u?
2568 # What if there's another file or directory named 't' in one of the
2569 # intervening directories and/or in u itself? Also, shouldn't the
2570 # same logic that places 't' in u/ also move ALL other files to u/?
2571 # What if there are file or directory conflicts in any of them? If
2572 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2573 # like this, would the user have any hope of understanding any
2574 # conflicts or how their working tree ended up? I think not, so I'm
2575 # ruling out N-ary transitive renames for N>1.
2577 # Therefore our expected result is:
2578 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2579 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2580 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2581 # simple rules that are consistent with what we need for all the other
2582 # testcases and simplifies things for the user.
2584 test_expect_success '9d-setup: N-way transitive rename?' '
2585 test_create_repo 9d &&
2589 mkdir z y x w v u &&
2596 git add z y x w v u &&
2598 git commit -m "O" &&
2609 git commit -m "A" &&
2621 test_expect_failure '9d-check: N-way transitive rename?' '
2627 git merge -s recursive B^0 >out &&
2628 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2629 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2630 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2631 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2633 git ls-files -s >out &&
2634 test_line_count = 7 out &&
2635 git ls-files -o >out &&
2636 test_line_count = 1 out &&
2638 git rev-parse >actual \
2640 HEAD:y/a HEAD:x/b HEAD:w/c \
2641 HEAD:u/d HEAD:u/e HEAD:u/f &&
2642 git rev-parse >expect \
2645 O:w/d O:v/e A:u/f &&
2646 test_cmp expect actual
2650 # Testcase 9e, N-to-1 whammo
2651 # (Related to testcase 9c...and 1c and 7e)
2652 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2653 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2654 # Commit B: combined/{a,b,d,e,g,h,j,k}
2655 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2656 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2658 test_expect_success '9e-setup: N-to-1 whammo' '
2659 test_create_repo 9e &&
2663 mkdir dir1 dir2 dir3 dirN &&
2674 git commit -m "O" &&
2691 git commit -m "A" &&
2694 git mv dir1 combined &&
2695 git mv dir2/* combined/ &&
2696 git mv dir3/* combined/ &&
2697 git mv dirN/* combined/ &&
2703 test_expect_failure C_LOCALE_OUTPUT '9e-check: N-to-1 whammo' '
2709 test_must_fail git merge -s recursive B^0 >out &&
2710 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2711 grep -q dir1/yo error_line &&
2712 grep -q dir2/yo error_line &&
2713 grep -q dir3/yo error_line &&
2714 grep -q dirN/yo error_line &&
2716 git ls-files -s >out &&
2717 test_line_count = 16 out &&
2718 git ls-files -u >out &&
2719 test_line_count = 0 out &&
2720 git ls-files -o >out &&
2721 test_line_count = 2 out &&
2723 git rev-parse >actual \
2724 :0:combined/a :0:combined/b :0:combined/c \
2725 :0:combined/d :0:combined/e :0:combined/f \
2726 :0:combined/g :0:combined/h :0:combined/i \
2727 :0:combined/j :0:combined/k :0:combined/l &&
2728 git rev-parse >expect \
2729 O:dir1/a O:dir1/b A:dir1/c \
2730 O:dir2/d O:dir2/e A:dir2/f \
2731 O:dir3/g O:dir3/h A:dir3/i \
2732 O:dirN/j O:dirN/k A:dirN/l &&
2733 test_cmp expect actual &&
2735 git rev-parse >actual \
2736 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2737 git rev-parse >expect \
2738 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2739 test_cmp expect actual
2743 # Testcase 9f, Renamed directory that only contained immediate subdirs
2744 # (Related to testcases 1e & 9g)
2745 # Commit O: goal/{a,b}/$more_files
2746 # Commit A: priority/{a,b}/$more_files
2747 # Commit B: goal/{a,b}/$more_files, goal/c
2748 # Expected: priority/{a,b}/$more_files, priority/c
2750 test_expect_success '9f-setup: Renamed directory that only contained immediate subdirs' '
2751 test_create_repo 9f &&
2757 echo foo >goal/a/foo &&
2758 echo bar >goal/b/bar &&
2759 echo baz >goal/b/baz &&
2762 git commit -m "O" &&
2769 git mv goal/ priority &&
2771 git commit -m "A" &&
2781 test_expect_failure '9f-check: Renamed directory that only contained immediate subdirs' '
2787 git merge -s recursive B^0 &&
2789 git ls-files -s >out &&
2790 test_line_count = 4 out &&
2792 git rev-parse >actual \
2793 HEAD:priority/a/foo \
2794 HEAD:priority/b/bar \
2795 HEAD:priority/b/baz \
2797 git rev-parse >expect \
2802 test_cmp expect actual &&
2803 test_must_fail git rev-parse HEAD:goal/c
2807 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2808 # (Related to testcases 1e & 9f)
2809 # Commit O: goal/{a,b}/$more_files
2810 # Commit A: priority/{alpha,bravo}/$more_files
2811 # Commit B: goal/{a,b}/$more_files, goal/c
2812 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2814 test_expect_success '9g-setup: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2815 test_create_repo 9g &&
2821 echo foo >goal/a/foo &&
2822 echo bar >goal/b/bar &&
2823 echo baz >goal/b/baz &&
2826 git commit -m "O" &&
2834 git mv goal/a/ priority/alpha &&
2835 git mv goal/b/ priority/beta &&
2838 git commit -m "A" &&
2848 test_expect_failure '9g-check: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2854 git merge -s recursive B^0 &&
2856 git ls-files -s >out &&
2857 test_line_count = 4 out &&
2859 git rev-parse >actual \
2860 HEAD:priority/alpha/foo \
2861 HEAD:priority/beta/bar \
2862 HEAD:priority/beta/baz \
2864 git rev-parse >expect \
2869 test_cmp expect actual &&
2870 test_must_fail git rev-parse HEAD:goal/c
2874 ###########################################################################
2875 # Rules suggested by section 9:
2877 # If the other side of history did a directory rename to a path that your
2878 # side renamed away, then ignore that particular rename from the other
2879 # side of history for any implicit directory renames.
2880 ###########################################################################