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.)
29 . "$TEST_DIRECTORY"/lib-merge.sh
32 ###########################################################################
33 # SECTION 1: Basic cases we should be able to handle
34 ###########################################################################
36 # Testcase 1a, Basic directory rename.
39 # Commit B: z/{b,c,d,e/f}
40 # Expected: y/{b,c,d,e/f}
43 test_create_repo 1a &&
73 test_expect_success '1a: Simple directory rename detection' '
80 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
82 git ls-files -s >out &&
83 test_line_count = 4 out &&
85 git rev-parse >actual \
86 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
87 git rev-parse >expect \
88 O:z/b O:z/c B:z/d B:z/e/f &&
89 test_cmp expect actual &&
91 git hash-object y/d >actual &&
92 git rev-parse B:z/d >expect &&
93 test_cmp expect actual &&
95 test_must_fail git rev-parse HEAD:z/d &&
96 test_must_fail git rev-parse HEAD:z/e/f &&
97 test_path_is_missing z/d &&
98 test_path_is_missing z/e/f
102 # Testcase 1b, Merge a directory with another
103 # Commit O: z/{b,c}, y/d
104 # Commit A: z/{b,c,e}, y/d
105 # Commit B: y/{b,c,d}
106 # Expected: y/{b,c,d,e}
109 test_create_repo 1b &&
141 test_expect_success '1b: Merge a directory with another' '
148 git -c merge.directoryRenames=true merge -s recursive B^0 &&
150 git ls-files -s >out &&
151 test_line_count = 4 out &&
153 git rev-parse >actual \
154 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
155 git rev-parse >expect \
156 O:z/b O:z/c O:y/d A:z/e &&
157 test_cmp expect actual &&
158 test_must_fail git rev-parse HEAD:z/e
162 # Testcase 1c, Transitive renaming
163 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
164 # (Related to testcases 9c and 9d -- can transitivity repeat?)
165 # (Related to testcase 12b -- joint-transitivity?)
166 # Commit O: z/{b,c}, x/d
167 # Commit A: y/{b,c}, x/d
168 # Commit B: z/{b,c,d}
169 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
172 test_create_repo 1c &&
201 test_expect_success '1c: Transitive renaming' '
208 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
210 git ls-files -s >out &&
211 test_line_count = 3 out &&
213 git rev-parse >actual \
214 HEAD:y/b HEAD:y/c HEAD:y/d &&
215 git rev-parse >expect \
217 test_cmp expect actual &&
218 test_must_fail git rev-parse HEAD:x/d &&
219 test_must_fail git rev-parse HEAD:z/d &&
220 test_path_is_missing z/d
224 # Testcase 1d, Directory renames (merging two directories into one new one)
225 # cause a rename/rename(2to1) conflict
226 # (Related to testcases 1c and 7b)
227 # Commit O. z/{b,c}, y/{d,e}
228 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
229 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
230 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
231 # Note: y/m & z/n should definitely move into x. By the same token, both
232 # y/wham_1 & z/wham_2 should too...giving us a conflict.
235 test_create_repo 1d &&
256 echo wham1 >y/wham &&
264 echo wham2 >z/wham &&
271 test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict' '
278 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
279 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
281 git ls-files -s >out &&
282 test_line_count = 8 out &&
283 git ls-files -u >out &&
284 test_line_count = 2 out &&
285 git ls-files -o >out &&
286 test_line_count = 1 out &&
288 git rev-parse >actual \
289 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
290 git rev-parse >expect \
291 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
292 test_cmp expect actual &&
294 test_must_fail git rev-parse :0:x/wham &&
295 git rev-parse >actual \
296 :2:x/wham :3:x/wham &&
297 git rev-parse >expect \
299 test_cmp expect actual &&
301 # Test that the two-way merge in x/wham is as expected
302 git cat-file -p :2:x/wham >expect &&
303 git cat-file -p :3:x/wham >other &&
305 test_must_fail git merge-file \
309 expect empty other &&
310 test_cmp expect x/wham
314 # Testcase 1e, Renamed directory, with all filenames being renamed too
315 # (Related to testcases 9f & 9g)
316 # Commit O: z/{oldb,oldc}
317 # Commit A: y/{newb,newc}
318 # Commit B: z/{oldb,oldc,d}
319 # Expected: y/{newb,newc,d}
322 test_create_repo 1e &&
339 git mv z/oldb y/newb &&
340 git mv z/oldc y/newc &&
352 test_expect_success '1e: Renamed directory, with all files being renamed too' '
359 git -c merge.directoryRenames=true merge -s recursive B^0 &&
361 git ls-files -s >out &&
362 test_line_count = 3 out &&
364 git rev-parse >actual \
365 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
366 git rev-parse >expect \
367 O:z/oldb O:z/oldc B:z/d &&
368 test_cmp expect actual &&
369 test_must_fail git rev-parse HEAD:z/d
373 # Testcase 1f, Split a directory into two other directories
374 # (Related to testcases 3a, all of section 2, and all of section 4)
375 # Commit O: z/{b,c,d,e,f}
376 # Commit A: z/{b,c,d,e,f,g}
377 # Commit B: y/{b,c}, x/{d,e,f}
378 # Expected: y/{b,c}, x/{d,e,f,g}
381 test_create_repo 1f &&
419 test_expect_success '1f: Split a directory into two other directories' '
426 git -c merge.directoryRenames=true merge -s recursive B^0 &&
428 git ls-files -s >out &&
429 test_line_count = 6 out &&
431 git rev-parse >actual \
432 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
433 git rev-parse >expect \
434 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
435 test_cmp expect actual &&
436 test_path_is_missing z/g &&
437 test_must_fail git rev-parse HEAD:z/g
441 ###########################################################################
442 # Rules suggested by testcases in section 1:
444 # We should still detect the directory rename even if it wasn't just
445 # the directory renamed, but the files within it. (see 1b)
447 # If renames split a directory into two or more others, the directory
448 # with the most renames, "wins" (see 1c). However, see the testcases
449 # in section 2, plus testcases 3a and 4a.
450 ###########################################################################
453 ###########################################################################
454 # SECTION 2: Split into multiple directories, with equal number of paths
456 # Explore the splitting-a-directory rules a bit; what happens in the
459 # Note that there is a closely related case of a directory not being
460 # split on either side of history, but being renamed differently on
461 # each side. See testcase 8e for that.
462 ###########################################################################
464 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
467 # Commit B: z/{b,c,d}
468 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
470 test_create_repo 2a &&
501 test_expect_success '2a: Directory split into two on one side, with equal numbers of paths' '
508 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
509 test_i18ngrep "CONFLICT.*directory rename split" out &&
511 git ls-files -s >out &&
512 test_line_count = 3 out &&
513 git ls-files -u >out &&
514 test_line_count = 0 out &&
515 git ls-files -o >out &&
516 test_line_count = 1 out &&
518 git rev-parse >actual \
519 :0:y/b :0:w/c :0:z/d &&
520 git rev-parse >expect \
522 test_cmp expect actual
526 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
529 # Commit B: z/{b,c}, x/d
530 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
532 test_create_repo 2b &&
564 test_expect_success '2b: Directory split into two on one side, with equal numbers of paths' '
571 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
573 git ls-files -s >out &&
574 test_line_count = 3 out &&
575 git ls-files -u >out &&
576 test_line_count = 0 out &&
577 git ls-files -o >out &&
578 test_line_count = 1 out &&
580 git rev-parse >actual \
581 :0:y/b :0:w/c :0:x/d &&
582 git rev-parse >expect \
584 test_cmp expect actual &&
585 test_i18ngrep ! "CONFLICT.*directory rename split" out
589 ###########################################################################
590 # Rules suggested by section 2:
592 # None; the rule was already covered in section 1. These testcases are
593 # here just to make sure the conflict resolution and necessary warning
594 # messages are handled correctly.
595 ###########################################################################
598 ###########################################################################
599 # SECTION 3: Path in question is the source path for some rename already
601 # Combining cases from Section 1 and trying to handle them could lead to
602 # directory renaming detection being over-applied. So, this section
603 # provides some good testcases to check that the implementation doesn't go
605 ###########################################################################
607 # Testcase 3a, Avoid implicit rename if involved as source on other side
608 # (Related to testcases 1c, 1f, and 9h)
609 # Commit O: z/{b,c,d}
610 # Commit A: z/{b,c,d} (no change)
611 # Commit B: y/{b,c}, x/d
612 # Expected: y/{b,c}, x/d
614 test_create_repo 3a &&
632 git commit --allow-empty -m "A" &&
646 test_expect_success '3a: Avoid implicit rename if involved as source on other side' '
653 git -c merge.directoryRenames=true merge -s recursive B^0 &&
655 git ls-files -s >out &&
656 test_line_count = 3 out &&
658 git rev-parse >actual \
659 HEAD:y/b HEAD:y/c HEAD:x/d &&
660 git rev-parse >expect \
662 test_cmp expect actual
666 # Testcase 3b, Avoid implicit rename if involved as source on other side
667 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
668 # Commit O: z/{b,c,d}
669 # Commit A: y/{b,c}, x/d
670 # Commit B: z/{b,c}, w/d
671 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
672 # NOTE: We're particularly checking that since z/d is already involved as
673 # a source in a file rename on the same side of history, that we don't
674 # get it involved in directory rename detection. If it were, we might
675 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
676 # rename/rename/rename(1to3) conflict, which is just weird.
678 test_create_repo 3b &&
712 test_expect_success '3b: Avoid implicit rename if involved as source on current side' '
719 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
720 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
721 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
723 git ls-files -s >out &&
724 test_line_count = 5 out &&
725 git ls-files -u >out &&
726 test_line_count = 3 out &&
727 git ls-files -o >out &&
728 test_line_count = 1 out &&
730 git rev-parse >actual \
731 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
732 git rev-parse >expect \
733 O:z/b O:z/c O:z/d O:z/d O:z/d &&
734 test_cmp expect actual &&
736 test_path_is_missing z/d &&
737 git hash-object >actual \
739 git rev-parse >expect \
741 test_cmp expect actual
745 ###########################################################################
746 # Rules suggested by section 3:
748 # Avoid directory-rename-detection for a path, if that path is the source
749 # of a rename on either side of a merge.
750 ###########################################################################
753 ###########################################################################
754 # SECTION 4: Partially renamed directory; still exists on both sides of merge
756 # What if we were to attempt to do directory rename detection when someone
757 # "mostly" moved a directory but still left some files around, or,
758 # equivalently, fully renamed a directory in one commit and then recreated
759 # that directory in a later commit adding some new files and then tried to
762 # It's hard to divine user intent in these cases, because you can make an
763 # argument that, depending on the intermediate history of the side being
764 # merged, that some users will want files in that directory to
765 # automatically be detected and renamed, while users with a different
766 # intermediate history wouldn't want that rename to happen.
768 # I think that it is best to simply not have directory rename detection
769 # apply to such cases. My reasoning for this is four-fold: (1) it's
770 # easiest for users in general to figure out what happened if we don't
771 # apply directory rename detection in any such case, (2) it's an easy rule
772 # to explain ["We don't do directory rename detection if the directory
773 # still exists on both sides of the merge"], (3) we can get some hairy
774 # edge/corner cases that would be really confusing and possibly not even
775 # representable in the index if we were to even try, and [related to 3] (4)
776 # attempting to resolve this issue of divining user intent by examining
777 # intermediate history goes against the spirit of three-way merges and is a
778 # path towards crazy corner cases that are far more complex than what we're
779 # already dealing with.
781 # Note that the wording of the rule ("We don't do directory rename
782 # detection if the directory still exists on both sides of the merge.")
783 # also excludes "renaming" of a directory into a subdirectory of itself
784 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
785 # out an exception for "renaming"-beneath-itself cases without opening
786 # weird edge/corner cases for other partial directory renames, but for now
787 # we are keeping the rule simple.
789 # This section contains a test for a partially-renamed-directory case.
790 ###########################################################################
792 # Testcase 4a, Directory split, with original directory still present
793 # (Related to testcase 1f)
794 # Commit O: z/{b,c,d,e}
795 # Commit A: y/{b,c,d}, z/e
796 # Commit B: z/{b,c,d,e,f}
797 # Expected: y/{b,c,d}, z/{e,f}
798 # NOTE: Even though most files from z moved to y, we don't want f to follow.
801 test_create_repo 4a &&
834 test_expect_success '4a: Directory split, with original directory still present' '
841 git -c merge.directoryRenames=true merge -s recursive B^0 &&
843 git ls-files -s >out &&
844 test_line_count = 5 out &&
845 git ls-files -u >out &&
846 test_line_count = 0 out &&
847 git ls-files -o >out &&
848 test_line_count = 1 out &&
850 git rev-parse >actual \
851 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
852 git rev-parse >expect \
853 O:z/b O:z/c O:z/d O:z/e B:z/f &&
854 test_cmp expect actual
858 ###########################################################################
859 # Rules suggested by section 4:
861 # Directory-rename-detection should be turned off for any directories (as
862 # a source for renames) that exist on both sides of the merge. (The "as
863 # a source for renames" clarification is due to cases like 1c where
864 # the target directory exists on both sides and we do want the rename
865 # detection.) But, sadly, see testcase 8b.
866 ###########################################################################
869 ###########################################################################
870 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
872 # Implicitly renaming files due to a detected directory rename could run
873 # into problems if there are files or directories in the way of the paths
874 # we want to rename. Explore such cases in this section.
875 ###########################################################################
877 # Testcase 5a, Merge directories, other side adds files to original and target
878 # Commit O: z/{b,c}, y/d
879 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
880 # Commit B: y/{b,c,d}
881 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
882 # NOTE: While directory rename detection is active here causing z/f to
883 # become y/f, we did not apply this for z/e_1 because that would
884 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
885 # this add/add, is that both versions of y/e are from the same side
886 # of history, giving us no way to represent this conflict in the
890 test_create_repo 5a &&
911 git add z/e z/f y/e &&
924 test_expect_success '5a: Merge directories, other side adds files to original and target' '
931 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
932 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
934 git ls-files -s >out &&
935 test_line_count = 6 out &&
936 git ls-files -u >out &&
937 test_line_count = 0 out &&
938 git ls-files -o >out &&
939 test_line_count = 1 out &&
941 git rev-parse >actual \
942 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
943 git rev-parse >expect \
944 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
945 test_cmp expect actual
949 # Testcase 5b, Rename/delete in order to get add/add/add conflict
950 # (Related to testcase 8d; these may appear slightly inconsistent to users;
951 # Also related to testcases 7d and 7e)
952 # Commit O: z/{b,c,d_1}
953 # Commit A: y/{b,c,d_2}
954 # Commit B: z/{b,c,d_1,e}, y/d_3
955 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
956 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
957 # we normally would since z/ is being renamed to y/, then this would be
958 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
959 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
960 # representable in the index, so the existence of y/d_3 needs to
961 # cause us to bail on directory rename detection for that path, falling
962 # back to git behavior without the directory rename detection.
965 test_create_repo 5b &&
999 test_expect_success '5b: Rename/delete in order to get add/add/add conflict' '
1006 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1007 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1009 git ls-files -s >out &&
1010 test_line_count = 5 out &&
1011 git ls-files -u >out &&
1012 test_line_count = 2 out &&
1013 git ls-files -o >out &&
1014 test_line_count = 1 out &&
1016 git rev-parse >actual \
1017 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1018 git rev-parse >expect \
1019 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1020 test_cmp expect actual &&
1022 test_must_fail git rev-parse :1:y/d &&
1023 test_path_is_file y/d
1027 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1028 # (Directory rename detection would result in transitive rename vs.
1029 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1030 # rename paths conflict with separate adds on the other side)
1031 # (Related to testcases 3b and 7c)
1032 # Commit O: z/{b,c}, x/d_1
1033 # Commit A: y/{b,c,d_2}, w/d_1
1034 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1035 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1036 # presence of y/d_4 in B to avoid doing transitive rename of
1037 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1038 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1039 # though, because it doesn't have anything in the way.
1042 test_create_repo 5c &&
1053 git commit -m "O" &&
1065 git commit -m "A" &&
1074 git add w/ y/ z/e &&
1080 test_expect_success '5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1087 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1088 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1089 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1091 git ls-files -s >out &&
1092 test_line_count = 9 out &&
1093 git ls-files -u >out &&
1094 test_line_count = 6 out &&
1095 git ls-files -o >out &&
1096 test_line_count = 1 out &&
1098 git rev-parse >actual \
1099 :0:y/b :0:y/c :0:y/e &&
1100 git rev-parse >expect \
1101 O:z/b O:z/c B:z/e &&
1102 test_cmp expect actual &&
1104 test_must_fail git rev-parse :1:y/d &&
1105 git rev-parse >actual \
1106 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1107 git rev-parse >expect \
1108 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1109 test_cmp expect actual &&
1111 git hash-object >actual \
1113 git rev-parse >expect \
1115 test_cmp expect actual &&
1116 test_path_is_missing x/d &&
1117 test_path_is_file y/d &&
1118 grep -q "<<<<" y/d # conflict markers should be present
1122 # Testcase 5d, Directory/file/file conflict due to directory rename
1124 # Commit A: y/{b,c,d_1}
1125 # Commit B: z/{b,c,d_2,f}, y/d/e
1126 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1127 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1128 # detection for z/d_2, but that doesn't prevent us from applying the
1129 # directory rename detection for z/f -> y/f.
1132 test_create_repo 5d &&
1141 git commit -m "O" &&
1152 git commit -m "A" &&
1159 git add y/d/e z/d z/f &&
1165 test_expect_success '5d: Directory/file/file conflict due to directory rename' '
1172 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1173 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1175 git ls-files -s >out &&
1176 test_line_count = 6 out &&
1177 git ls-files -u >out &&
1178 test_line_count = 1 out &&
1179 git ls-files -o >out &&
1180 test_line_count = 2 out &&
1182 git rev-parse >actual \
1183 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1184 git rev-parse >expect \
1185 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1186 test_cmp expect actual &&
1188 git hash-object y/d~HEAD >actual &&
1189 git rev-parse A:y/d >expect &&
1190 test_cmp expect actual
1194 ###########################################################################
1195 # Rules suggested by section 5:
1197 # If a subset of to-be-renamed files have a file or directory in the way,
1198 # "turn off" the directory rename for those specific sub-paths, falling
1199 # back to old handling. But, sadly, see testcases 8a and 8b.
1200 ###########################################################################
1203 ###########################################################################
1204 # SECTION 6: Same side of the merge was the one that did the rename
1206 # It may sound obvious that you only want to apply implicit directory
1207 # renames to directories if the _other_ side of history did the renaming.
1208 # If you did make an implementation that didn't explicitly enforce this
1209 # rule, the majority of cases that would fall under this section would
1210 # also be solved by following the rules from the above sections. But
1211 # there are still a few that stick out, so this section covers them just
1212 # to make sure we also get them right.
1213 ###########################################################################
1215 # Testcase 6a, Tricky rename/delete
1216 # Commit O: z/{b,c,d}
1218 # Commit B: y/{b,c}, z/d
1219 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1220 # Note: We're just checking here that the rename of z/b and z/c to put
1221 # them under y/ doesn't accidentally catch z/d and make it look like
1222 # it is also involved in a rename/delete conflict.
1225 test_create_repo 6a &&
1235 git commit -m "O" &&
1245 git commit -m "A" &&
1256 test_expect_success '6a: Tricky rename/delete' '
1263 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1264 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1266 git ls-files -s >out &&
1267 test_line_count = 2 out &&
1268 git ls-files -u >out &&
1269 test_line_count = 1 out &&
1270 git ls-files -o >out &&
1271 test_line_count = 1 out &&
1273 git rev-parse >actual \
1275 git rev-parse >expect \
1277 test_cmp expect actual
1281 # Testcase 6b1, Same rename done on both sides
1282 # (Related to testcase 6b2 and 8e)
1283 # Commit O: z/{b,c,d,e}
1284 # Commit A: y/{b,c,d}, x/e
1285 # Commit B: y/{b,c,d}, z/{e,f}
1286 # Expected: y/{b,c,d,f}, x/e
1287 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1288 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1289 # should be moved to 'y/f'.
1291 # This is a bit of an edge case where any behavior might surprise users,
1292 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1293 # z/ -> x/, or treating A as not doing any directory rename. However, I
1294 # think this answer is the least confusing and most consistent with the
1297 # A note about z/ -> x/, since it may not be clear how that could come
1298 # about: If we were to ignore files renamed by both sides
1299 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1300 # at least git-2.28, then we would note there are no renames from z/ to
1301 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1302 # A renamed z/ -> x/. This seems more confusing for end users than a
1303 # rename of z/ to y/, it makes directory rename detection behavior
1304 # harder for them to predict. As such, we modified the rule, changed
1305 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1308 test_create_repo 6b1 &&
1319 git commit -m "O" &&
1330 git commit -m "A" &&
1343 test_expect_merge_algorithm failure success '6b1: Same renames done on both sides, plus another rename' '
1350 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1352 git ls-files -s >out &&
1353 test_line_count = 5 out &&
1354 git ls-files -u >out &&
1355 test_line_count = 0 out &&
1356 git ls-files -o >out &&
1357 test_line_count = 1 out &&
1359 git rev-parse >actual \
1360 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1361 git rev-parse >expect \
1362 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1363 test_cmp expect actual
1367 # Testcase 6b2, Same rename done on both sides
1368 # (Related to testcases 6c and 8e)
1371 # Commit B: y/{b,c}, z/d
1372 # Expected: y/{b,c,d}
1373 # Alternate: y/{b,c}, z/d
1374 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1375 # file 'z/d' in B should be moved to 'y/d'.
1377 # We could potentially ignore the renames of z/{b,c} on side A since
1378 # those were renamed on both sides. However, it's a bit of a corner
1379 # case because what if there was also a z/e that side A moved to x/e
1380 # and side B left alone? If we used the "ignore renames done on both
1381 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1382 # z/d to x/d. That seems more surprising and uglier than allowing
1383 # the z/ -> y/ rename.
1386 test_create_repo 6b2 &&
1395 git commit -m "O" &&
1404 git commit -m "A" &&
1416 test_expect_merge_algorithm failure success '6b2: Same rename done on both sides' '
1423 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1425 git ls-files -s >out &&
1426 test_line_count = 3 out &&
1427 git ls-files -u >out &&
1428 test_line_count = 0 out &&
1429 git ls-files -o >out &&
1430 test_line_count = 1 out &&
1432 git rev-parse >actual \
1433 HEAD:y/b HEAD:y/c HEAD:y/d &&
1434 git rev-parse >expect \
1435 O:z/b O:z/c B:z/d &&
1436 test_cmp expect actual
1440 # Testcase 6c, Rename only done on same side
1441 # (Related to testcases 6b1, 6b2, and 8e)
1443 # Commit A: z/{b,c} (no change)
1444 # Commit B: y/{b,c}, z/d
1445 # Expected: y/{b,c}, z/d
1446 # NOTE: Seems obvious, but just checking that the implementation doesn't
1447 # "accidentally detect a rename" and give us y/{b,c,d}.
1450 test_create_repo 6c &&
1459 git commit -m "O" &&
1467 git commit --allow-empty -m "A" &&
1479 test_expect_success '6c: Rename only done on same side' '
1486 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1488 git ls-files -s >out &&
1489 test_line_count = 3 out &&
1490 git ls-files -u >out &&
1491 test_line_count = 0 out &&
1492 git ls-files -o >out &&
1493 test_line_count = 1 out &&
1495 git rev-parse >actual \
1496 HEAD:y/b HEAD:y/c HEAD:z/d &&
1497 git rev-parse >expect \
1498 O:z/b O:z/c B:z/d &&
1499 test_cmp expect actual
1503 # Testcase 6d, We don't always want transitive renaming
1504 # (Related to testcase 1c)
1505 # Commit O: z/{b,c}, x/d
1506 # Commit A: z/{b,c}, x/d (no change)
1507 # Commit B: y/{b,c}, z/d
1508 # Expected: y/{b,c}, z/d
1509 # NOTE: Again, this seems obvious but just checking that the implementation
1510 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1513 test_create_repo 6d &&
1524 git commit -m "O" &&
1532 git commit --allow-empty -m "A" &&
1542 test_expect_success '6d: We do not always want transitive renaming' '
1549 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1551 git ls-files -s >out &&
1552 test_line_count = 3 out &&
1553 git ls-files -u >out &&
1554 test_line_count = 0 out &&
1555 git ls-files -o >out &&
1556 test_line_count = 1 out &&
1558 git rev-parse >actual \
1559 HEAD:y/b HEAD:y/c HEAD:z/d &&
1560 git rev-parse >expect \
1561 O:z/b O:z/c O:x/d &&
1562 test_cmp expect actual
1566 # Testcase 6e, Add/add from one-side
1568 # Commit A: z/{b,c} (no change)
1569 # Commit B: y/{b,c,d_1}, z/d_2
1570 # Expected: y/{b,c,d_1}, z/d_2
1571 # NOTE: Again, this seems obvious but just checking that the implementation
1572 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1573 # add/add conflict on y/d_1 vs y/d_2.
1576 test_create_repo 6e &&
1585 git commit -m "O" &&
1593 git commit --allow-empty -m "A" &&
1606 test_expect_success '6e: Add/add from one side' '
1613 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1615 git ls-files -s >out &&
1616 test_line_count = 4 out &&
1617 git ls-files -u >out &&
1618 test_line_count = 0 out &&
1619 git ls-files -o >out &&
1620 test_line_count = 1 out &&
1622 git rev-parse >actual \
1623 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1624 git rev-parse >expect \
1625 O:z/b O:z/c B:y/d B:z/d &&
1626 test_cmp expect actual
1630 ###########################################################################
1631 # Rules suggested by section 6:
1633 # Only apply implicit directory renames to directories if the other
1634 # side of history is the one doing the renaming.
1635 ###########################################################################
1638 ###########################################################################
1639 # SECTION 7: More involved Edge/Corner cases
1641 # The ruleset we have generated in the above sections seems to provide
1642 # well-defined merges. But can we find edge/corner cases that either (a)
1643 # are harder for users to understand, or (b) have a resolution that is
1644 # non-intuitive or suboptimal?
1646 # The testcases in this section dive into cases that I've tried to craft in
1647 # a way to find some that might be surprising to users or difficult for
1648 # them to understand (the next section will look at non-intuitive or
1649 # suboptimal merge results). Some of the testcases are similar to ones
1650 # from past sections, but have been simplified to try to highlight error
1651 # messages using a "modified" path (due to the directory rename). Are
1652 # users okay with these?
1654 # In my opinion, testcases that are difficult to understand from this
1655 # section is due to difficulty in the testcase rather than the directory
1656 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1657 # to the problem setup itself being complex). And I don't think the
1658 # error messages are a problem.
1660 # On the other hand, the testcases in section 8 worry me slightly more...
1661 ###########################################################################
1663 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1666 # Commit B: w/b, x/c, z/d
1667 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1668 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1671 test_create_repo 7a &&
1680 git commit -m "O" &&
1689 git commit -m "A" &&
1703 test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1710 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1711 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1712 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1714 git ls-files -s >out &&
1715 test_line_count = 7 out &&
1716 git ls-files -u >out &&
1717 test_line_count = 6 out &&
1718 git ls-files -o >out &&
1719 test_line_count = 1 out &&
1721 git rev-parse >actual \
1722 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1723 git rev-parse >expect \
1724 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1725 test_cmp expect actual &&
1727 git hash-object >actual \
1729 git rev-parse >expect \
1730 O:z/b O:z/b O:z/c O:z/c &&
1731 test_cmp expect actual
1735 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1736 # (Related to testcase 1d)
1737 # Commit O: z/{b,c}, x/d_1, w/d_2
1738 # Commit A: y/{b,c,d_2}, x/d_1
1739 # Commit B: z/{b,c,d_1}, w/d_2
1740 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1743 test_create_repo 7b &&
1756 git commit -m "O" &&
1766 git commit -m "A" &&
1776 test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' '
1783 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1784 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
1786 git ls-files -s >out &&
1787 test_line_count = 4 out &&
1788 git ls-files -u >out &&
1789 test_line_count = 2 out &&
1790 git ls-files -o >out &&
1791 test_line_count = 1 out &&
1793 git rev-parse >actual \
1794 :0:y/b :0:y/c :2:y/d :3:y/d &&
1795 git rev-parse >expect \
1796 O:z/b O:z/c O:w/d O:x/d &&
1797 test_cmp expect actual &&
1799 # Test that the two-way merge in y/d is as expected
1800 git cat-file -p :2:y/d >expect &&
1801 git cat-file -p :3:y/d >other &&
1803 test_must_fail git merge-file \
1807 expect empty other &&
1812 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1813 # (Related to testcases 3b and 5c)
1814 # Commit O: z/{b,c}, x/d
1815 # Commit A: y/{b,c}, w/d
1816 # Commit B: z/{b,c,d}
1817 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1818 # NOTE: z/ was renamed to y/ so we do want to report
1819 # neither CONFLICT(x/d -> w/d vs. z/d)
1820 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1823 test_create_repo 7c &&
1834 git commit -m "O" &&
1844 git commit -m "A" &&
1854 test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1861 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1862 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1864 git ls-files -s >out &&
1865 test_line_count = 5 out &&
1866 git ls-files -u >out &&
1867 test_line_count = 3 out &&
1868 git ls-files -o >out &&
1869 test_line_count = 1 out &&
1871 git rev-parse >actual \
1872 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1873 git rev-parse >expect \
1874 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1875 test_cmp expect actual
1879 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1880 # (Related somewhat to testcases 5b and 8d)
1881 # Commit O: z/{b,c}, x/d
1883 # Commit B: z/{b,c,d}
1884 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1885 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1888 test_create_repo 7d &&
1899 git commit -m "O" &&
1909 git commit -m "A" &&
1919 test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' '
1926 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1927 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1929 git ls-files -s >out &&
1930 test_line_count = 3 out &&
1931 git ls-files -u >out &&
1932 test_line_count = 1 out &&
1933 git ls-files -o >out &&
1934 test_line_count = 1 out &&
1936 git rev-parse >actual \
1937 :0:y/b :0:y/c :3:y/d &&
1938 git rev-parse >expect \
1939 O:z/b O:z/c O:x/d &&
1940 test_cmp expect actual
1944 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1945 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1946 # (Also related to testcases 9c and 9d)
1947 # Commit O: z/{b,c}, x/d_1
1948 # Commit A: y/{b,c,d/g}, x/d/f
1949 # Commit B: z/{b,c,d_1}
1950 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1951 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1953 # NOTE: The main path of interest here is d_1 and where it ends up, but
1954 # this is actually a case that has two potential directory renames
1955 # involved and D/F conflict(s), so it makes sense to walk through
1958 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1959 # should be instead moved to y/. This gives us the D/F conflict on
1960 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1962 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1963 # should instead be moved to z/...BUT we removed z/ and renamed it
1964 # to y/, so maybe everything should move not from x/ to z/, but
1965 # from x/ to z/ to y/. Doing so might make sense from the logic so
1966 # far, but note that commit A had both an x/ and a y/; it did the
1967 # renaming of z/ to y/ and created x/d/f and it clearly made these
1968 # things separate, so it doesn't make much sense to push these
1969 # together. Doing so is what I'd call a doubly transitive rename;
1970 # see testcases 9c and 9d for further discussion of this issue and
1971 # how it's resolved.
1974 test_create_repo 7e &&
1985 git commit -m "O" &&
1998 git add x/d/f y/d/g &&
2000 git commit -m "A" &&
2010 test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' '
2017 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2018 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2020 git ls-files -s >out &&
2021 test_line_count = 5 out &&
2022 git ls-files -u >out &&
2023 test_line_count = 1 out &&
2024 git ls-files -o >out &&
2025 test_line_count = 2 out &&
2027 git rev-parse >actual \
2028 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2029 git rev-parse >expect \
2030 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
2031 test_cmp expect actual &&
2033 git hash-object y/d~B^0 >actual &&
2034 git rev-parse O:x/d >expect &&
2035 test_cmp expect actual
2039 ###########################################################################
2040 # SECTION 8: Suboptimal merges
2042 # As alluded to in the last section, the ruleset we have built up for
2043 # detecting directory renames unfortunately has some special cases where it
2044 # results in slightly suboptimal or non-intuitive behavior. This section
2045 # explores these cases.
2047 # To be fair, we already had non-intuitive or suboptimal behavior for most
2048 # of these cases in git before introducing implicit directory rename
2049 # detection, but it'd be nice if there was a modified ruleset out there
2050 # that handled these cases a bit better.
2051 ###########################################################################
2053 # Testcase 8a, Dual-directory rename, one into the others' way
2054 # Commit O. x/{a,b}, y/{c,d}
2055 # Commit A. x/{a,b,e}, y/{c,d,f}
2056 # Commit B. y/{a,b}, z/{c,d}
2058 # Possible Resolutions:
2059 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2060 # Currently expected: y/{a,b,e,f}, z/{c,d}
2061 # Optimal: y/{a,b,e}, z/{c,d,f}
2063 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2064 # better with directory rename detection than git did without, but the
2065 # simple rule from section 5 prevents me from handling this as optimally as
2066 # we potentially could.
2069 test_create_repo 8a &&
2081 git commit -m "O" &&
2092 git commit -m "A" &&
2102 test_expect_success '8a: Dual-directory rename, one into the others way' '
2109 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2111 git ls-files -s >out &&
2112 test_line_count = 6 out &&
2113 git ls-files -u >out &&
2114 test_line_count = 0 out &&
2115 git ls-files -o >out &&
2116 test_line_count = 1 out &&
2118 git rev-parse >actual \
2119 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2120 git rev-parse >expect \
2121 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2122 test_cmp expect actual
2126 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2127 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2128 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2129 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2131 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2132 # Currently expected: <same>
2133 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2134 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2136 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2137 # y, both are named 'e'. Without directory rename detection, neither file
2138 # moves directories. Implement directory rename detection suboptimally, and
2139 # you get an add/add conflict, but both files were added in commit A, so this
2140 # is an add/add conflict where one side of history added both files --
2141 # something we can't represent in the index. Obviously, we'd prefer the last
2142 # resolution, but our previous rules are too coarse to allow it. Using both
2143 # the rules from section 4 and section 5 save us from the Scary resolution,
2144 # making us fall back to pre-directory-rename-detection behavior for both
2148 test_create_repo 8b &&
2160 git commit -m "O" &&
2171 git commit -m "A" &&
2181 test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2188 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2190 git ls-files -s >out &&
2191 test_line_count = 6 out &&
2192 git ls-files -u >out &&
2193 test_line_count = 0 out &&
2194 git ls-files -o >out &&
2195 test_line_count = 1 out &&
2197 git rev-parse >actual \
2198 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2199 git rev-parse >expect \
2200 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2201 test_cmp expect actual
2205 # Testcase 8c, modify/delete or rename+modify/delete?
2206 # (Related to testcases 5b, 8d, and 9h)
2207 # Commit O: z/{b,c,d}
2209 # Commit B: z/{b,c,d_modified,e}
2210 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2212 # Note: It could easily be argued that the correct resolution here is
2213 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2214 # and that the modified version of d should be present in y/ after
2215 # the merge, just marked as conflicted. Indeed, I previously did
2216 # argue that. But applying directory renames to the side of
2217 # history where a file is merely modified results in spurious
2218 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2222 test_create_repo 8c &&
2229 test_seq 1 10 >z/d &&
2232 git commit -m "O" &&
2242 git commit -m "A" &&
2246 test_chmod +x z/d &&
2254 test_expect_success '8c: modify/delete or rename+modify/delete' '
2261 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2262 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2264 git ls-files -s >out &&
2265 test_line_count = 5 out &&
2266 git ls-files -u >out &&
2267 test_line_count = 2 out &&
2268 git ls-files -o >out &&
2269 test_line_count = 1 out &&
2271 git rev-parse >actual \
2272 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2273 git rev-parse >expect \
2274 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2275 test_cmp expect actual &&
2277 test_must_fail git rev-parse :2:z/d &&
2278 git ls-files -s z/d | grep ^100755 &&
2279 test_path_is_file z/d &&
2280 test_path_is_missing y/d
2284 # Testcase 8d, rename/delete...or not?
2285 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2286 # Also related to testcases 7d and 7e)
2287 # Commit O: z/{b,c,d}
2289 # Commit B: z/{b,c,d,e}
2290 # Expected: y/{b,c,e}
2292 # Note: It would also be somewhat reasonable to resolve this as
2293 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2295 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2296 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2297 # delete) are both coming from commit A, which is illogical. Conflicts
2298 # during merging are supposed to be about opposite sides doing things
2302 test_create_repo 8d &&
2309 test_seq 1 10 >z/d &&
2312 git commit -m "O" &&
2322 git commit -m "A" &&
2332 test_expect_success '8d: rename/delete...or not?' '
2339 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2341 git ls-files -s >out &&
2342 test_line_count = 3 out &&
2344 git rev-parse >actual \
2345 HEAD:y/b HEAD:y/c HEAD:y/e &&
2346 git rev-parse >expect \
2347 O:z/b O:z/c B:z/e &&
2348 test_cmp expect actual
2352 # Testcase 8e, Both sides rename, one side adds to original directory
2355 # Commit B: w/{b,c}, z/d
2357 # Possible Resolutions:
2358 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2359 # CONFLICT(z/c -> y/c vs. w/c)
2360 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2361 # CONFLICT(z/c -> y/c vs. w/c)
2364 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2365 # did NOT get renamed; the directory is still present; instead it is
2366 # considered to have just renamed a subset of paths in directory z
2367 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2368 # the original paths out of z/ but opted to keep d within z/).
2370 # It was not clear in the past what should be done with this testcase;
2371 # in fact, I noted that I "just picked one" previously. However,
2372 # following the new logic for testcase 6b2, we should take the rename
2373 # and move z/d to y/d.
2375 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2376 # whether they are optimal for end users, but (a) the default for
2377 # directory rename detection is to mark these all as conflicts
2378 # anyway, (b) it feels like this is less prone to higher order corner
2379 # case confusion, and (c) the current algorithm requires less global
2380 # knowledge (i.e. less coupling in the algorithm between renames done
2381 # on both sides) which thus means users are better able to predict
2382 # the behavior, and predict it without computing as many details.
2385 test_create_repo 8e &&
2394 git commit -m "O" &&
2403 git commit -m "A" &&
2415 test_expect_success '8e: Both sides rename, one side adds to original directory' '
2422 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2423 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2424 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2426 git ls-files -s >out &&
2427 test_line_count = 7 out &&
2428 git ls-files -u >out &&
2429 test_line_count = 6 out &&
2430 git ls-files -o >out &&
2431 test_line_count = 2 out &&
2433 git rev-parse >actual \
2434 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2435 git rev-parse >expect \
2436 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2437 test_cmp expect actual &&
2439 git hash-object >actual \
2441 git rev-parse >expect \
2442 O:z/b O:z/b O:z/c O:z/c &&
2443 test_cmp expect actual &&
2445 test_path_is_missing z/b &&
2446 test_path_is_missing z/c
2450 ###########################################################################
2451 # SECTION 9: Other testcases
2453 # This section consists of miscellaneous testcases I thought of during
2454 # the implementation which round out the testing.
2455 ###########################################################################
2457 # Testcase 9a, Inner renamed directory within outer renamed directory
2458 # (Related to testcase 1f)
2459 # Commit O: z/{b,c,d/{e,f,g}}
2460 # Commit A: y/{b,c}, x/w/{e,f,g}
2461 # Commit B: z/{b,c,d/{e,f,g,h},i}
2462 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2463 # NOTE: The only reason this one is interesting is because when a directory
2464 # is split into multiple other directories, we determine by the weight
2465 # of which one had the most paths going to it. A naive implementation
2466 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2469 test_create_repo 9a &&
2481 git commit -m "O" &&
2492 git commit -m "A" &&
2503 test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2510 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2512 git ls-files -s >out &&
2513 test_line_count = 7 out &&
2514 git ls-files -u >out &&
2515 test_line_count = 0 out &&
2516 git ls-files -o >out &&
2517 test_line_count = 1 out &&
2519 git rev-parse >actual \
2520 HEAD:y/b HEAD:y/c HEAD:y/i &&
2521 git rev-parse >expect \
2522 O:z/b O:z/c B:z/i &&
2523 test_cmp expect actual &&
2525 git rev-parse >actual \
2526 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2527 git rev-parse >expect \
2528 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2529 test_cmp expect actual
2533 # Testcase 9b, Transitive rename with content merge
2534 # (Related to testcase 1c)
2535 # Commit O: z/{b,c}, x/d_1
2536 # Commit A: y/{b,c}, x/d_2
2537 # Commit B: z/{b,c,d_3}
2538 # Expected: y/{b,c,d_merged}
2541 test_create_repo 9b &&
2549 test_seq 1 10 >x/d &&
2552 git commit -m "O" &&
2560 test_seq 1 11 >x/d &&
2563 git commit -m "A" &&
2566 test_seq 0 10 >x/d &&
2574 test_expect_success '9b: Transitive rename with content merge' '
2581 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2583 git ls-files -s >out &&
2584 test_line_count = 3 out &&
2586 test_seq 0 11 >expected &&
2587 test_cmp expected y/d &&
2589 git rev-parse >actual \
2590 HEAD:y/b HEAD:y/c HEAD:y/d &&
2591 git rev-parse >expect \
2592 O:z/b O:z/c :0:expected &&
2593 test_cmp expect actual &&
2594 test_must_fail git rev-parse HEAD:x/d &&
2595 test_must_fail git rev-parse HEAD:z/d &&
2596 test_path_is_missing z/d &&
2598 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2599 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2600 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2604 # Testcase 9c, Doubly transitive rename?
2605 # (Related to testcase 1c, 7e, and 9d)
2606 # Commit O: z/{b,c}, x/{d,e}, w/f
2607 # Commit A: y/{b,c}, x/{d,e,f,g}
2608 # Commit B: z/{b,c,d,e}, w/f
2609 # Expected: y/{b,c,d,e}, x/{f,g}
2611 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2612 # x/f is clear. Let's look beyond that. Here's the logic:
2613 # Commit B renamed x/ -> z/
2614 # Commit A renamed z/ -> y/
2615 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2616 # transient rename. However, where does it end? We can chain these
2617 # indefinitely (see testcase 9d). What if there is a D/F conflict
2618 # at z/f/ or y/f/? Or just another file conflict at one of those
2619 # paths? In the case of an N-long chain of transient renamings,
2620 # where do we "abort" the rename at? Can the user make sense of
2621 # the resulting conflict and resolve it?
2623 # To avoid this confusion I use the simple rule that if the other side
2624 # of history did a directory rename to a path that your side renamed
2625 # away, then ignore that particular rename from the other side of
2626 # history for any implicit directory renames.
2629 test_create_repo 9c &&
2643 git commit -m "O" &&
2655 git commit -m "A" &&
2665 test_expect_success '9c: Doubly transitive rename?' '
2672 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2673 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2675 git ls-files -s >out &&
2676 test_line_count = 6 out &&
2677 git ls-files -o >out &&
2678 test_line_count = 1 out &&
2680 git rev-parse >actual \
2681 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2682 git rev-parse >expect \
2683 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2684 test_cmp expect actual
2688 # Testcase 9d, N-fold transitive rename?
2689 # (Related to testcase 9c...and 1c and 7e)
2690 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2691 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2692 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2693 # Expected: <see NOTE first>
2695 # NOTE: z/ -> y/ (in commit A)
2696 # y/ -> x/ (in commit B)
2697 # x/ -> w/ (in commit A)
2698 # w/ -> v/ (in commit B)
2699 # v/ -> u/ (in commit A)
2700 # So, if we add a file to z, say z/t, where should it end up? In u?
2701 # What if there's another file or directory named 't' in one of the
2702 # intervening directories and/or in u itself? Also, shouldn't the
2703 # same logic that places 't' in u/ also move ALL other files to u/?
2704 # What if there are file or directory conflicts in any of them? If
2705 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2706 # like this, would the user have any hope of understanding any
2707 # conflicts or how their working tree ended up? I think not, so I'm
2708 # ruling out N-ary transitive renames for N>1.
2710 # Therefore our expected result is:
2711 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2712 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2713 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2714 # simple rules that are consistent with what we need for all the other
2715 # testcases and simplifies things for the user.
2718 test_create_repo 9d &&
2722 mkdir z y x w v u &&
2729 git add z y x w v u &&
2731 git commit -m "O" &&
2742 git commit -m "A" &&
2754 test_expect_success '9d: N-way transitive rename?' '
2761 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2762 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2763 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2764 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2765 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2767 git ls-files -s >out &&
2768 test_line_count = 7 out &&
2769 git ls-files -o >out &&
2770 test_line_count = 1 out &&
2772 git rev-parse >actual \
2774 HEAD:y/a HEAD:x/b HEAD:w/c \
2775 HEAD:u/d HEAD:u/e HEAD:u/f &&
2776 git rev-parse >expect \
2779 O:w/d O:v/e A:u/f &&
2780 test_cmp expect actual
2784 # Testcase 9e, N-to-1 whammo
2785 # (Related to testcase 9c...and 1c and 7e)
2786 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2787 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2788 # Commit B: combined/{a,b,d,e,g,h,j,k}
2789 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2790 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2793 test_create_repo 9e &&
2797 mkdir dir1 dir2 dir3 dirN &&
2808 git commit -m "O" &&
2825 git commit -m "A" &&
2828 git mv dir1 combined &&
2829 git mv dir2/* combined/ &&
2830 git mv dir3/* combined/ &&
2831 git mv dirN/* combined/ &&
2837 test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' '
2844 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2845 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2846 grep -q dir1/yo error_line &&
2847 grep -q dir2/yo error_line &&
2848 grep -q dir3/yo error_line &&
2849 grep -q dirN/yo error_line &&
2851 git ls-files -s >out &&
2852 test_line_count = 16 out &&
2853 git ls-files -u >out &&
2854 test_line_count = 0 out &&
2855 git ls-files -o >out &&
2856 test_line_count = 2 out &&
2858 git rev-parse >actual \
2859 :0:combined/a :0:combined/b :0:combined/c \
2860 :0:combined/d :0:combined/e :0:combined/f \
2861 :0:combined/g :0:combined/h :0:combined/i \
2862 :0:combined/j :0:combined/k :0:combined/l &&
2863 git rev-parse >expect \
2864 O:dir1/a O:dir1/b A:dir1/c \
2865 O:dir2/d O:dir2/e A:dir2/f \
2866 O:dir3/g O:dir3/h A:dir3/i \
2867 O:dirN/j O:dirN/k A:dirN/l &&
2868 test_cmp expect actual &&
2870 git rev-parse >actual \
2871 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2872 git rev-parse >expect \
2873 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2874 test_cmp expect actual
2878 # Testcase 9f, Renamed directory that only contained immediate subdirs
2879 # (Related to testcases 1e & 9g)
2880 # Commit O: goal/{a,b}/$more_files
2881 # Commit A: priority/{a,b}/$more_files
2882 # Commit B: goal/{a,b}/$more_files, goal/c
2883 # Expected: priority/{a,b}/$more_files, priority/c
2886 test_create_repo 9f &&
2892 echo foo >goal/a/foo &&
2893 echo bar >goal/b/bar &&
2894 echo baz >goal/b/baz &&
2897 git commit -m "O" &&
2904 git mv goal/ priority &&
2906 git commit -m "A" &&
2916 test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2923 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2925 git ls-files -s >out &&
2926 test_line_count = 4 out &&
2928 git rev-parse >actual \
2929 HEAD:priority/a/foo \
2930 HEAD:priority/b/bar \
2931 HEAD:priority/b/baz \
2933 git rev-parse >expect \
2938 test_cmp expect actual &&
2939 test_must_fail git rev-parse HEAD:goal/c
2943 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2944 # (Related to testcases 1e & 9f)
2945 # Commit O: goal/{a,b}/$more_files
2946 # Commit A: priority/{alpha,bravo}/$more_files
2947 # Commit B: goal/{a,b}/$more_files, goal/c
2948 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2949 # We currently fail this test because the directory renames we detect are
2950 # goal/a/ -> priority/alpha/
2951 # goal/b/ -> priority/bravo/
2953 # goal/ -> priority/
2954 # because of no files found within goal/, and the fact that "a" != "alpha"
2955 # and "b" != "bravo". But I'm not sure it's really a failure given that
2959 test_create_repo 9g &&
2965 echo foo >goal/a/foo &&
2966 echo bar >goal/b/bar &&
2967 echo baz >goal/b/baz &&
2970 git commit -m "O" &&
2978 git mv goal/a/ priority/alpha &&
2979 git mv goal/b/ priority/beta &&
2982 git commit -m "A" &&
2992 test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2999 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3001 git ls-files -s >out &&
3002 test_line_count = 4 out &&
3004 git rev-parse >actual \
3005 HEAD:priority/alpha/foo \
3006 HEAD:priority/beta/bar \
3007 HEAD:priority/beta/baz \
3009 git rev-parse >expect \
3014 test_cmp expect actual &&
3015 test_must_fail git rev-parse HEAD:goal/c
3019 # Testcase 9h, Avoid implicit rename if involved as source on other side
3020 # (Extremely closely related to testcase 3a)
3021 # Commit O: z/{b,c,d_1}
3022 # Commit A: z/{b,c,d_2}
3023 # Commit B: y/{b,c}, x/d_1
3024 # Expected: y/{b,c}, x/d_2
3025 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3026 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3028 test_create_repo 9h &&
3035 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
3038 git commit -m "O" &&
3048 git commit -m "A" &&
3062 test_expect_success '9h: Avoid dir rename on merely modified path' '
3069 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3071 git ls-files -s >out &&
3072 test_line_count = 3 out &&
3074 git rev-parse >actual \
3075 HEAD:y/b HEAD:y/c HEAD:x/d &&
3076 git rev-parse >expect \
3077 O:z/b O:z/c A:z/d &&
3078 test_cmp expect actual
3082 ###########################################################################
3083 # Rules suggested by section 9:
3085 # If the other side of history did a directory rename to a path that your
3086 # side renamed away, then ignore that particular rename from the other
3087 # side of history for any implicit directory renames.
3088 ###########################################################################
3090 ###########################################################################
3091 # SECTION 10: Handling untracked files
3093 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3094 # the operation if untracked or dirty files would be deleted or overwritten
3095 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3096 # and if it doesn't abort, then it muddies up the working directory before
3097 # we even get to the point of detecting renames, so we need some special
3098 # handling, at least in the case of directory renames.
3099 ###########################################################################
3101 # Testcase 10a, Overwrite untracked: normal rename/delete
3102 # Commit O: z/{b,c_1}
3103 # Commit A: z/b + untracked z/c + untracked z/d
3104 # Commit B: z/{b,d_1}
3105 # Expected: Aborted Merge +
3106 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3109 test_create_repo 10a &&
3118 git commit -m "O" &&
3127 git commit -m "A" &&
3136 test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3143 echo important >z/d &&
3145 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3146 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3148 git ls-files -s >out &&
3149 test_line_count = 1 out &&
3150 git ls-files -o >out &&
3151 test_line_count = 4 out &&
3153 echo very >expect &&
3154 test_cmp expect z/c &&
3156 echo important >expect &&
3157 test_cmp expect z/d &&
3159 git rev-parse HEAD:z/b >actual &&
3160 git rev-parse O:z/b >expect &&
3161 test_cmp expect actual
3165 # Testcase 10b, Overwrite untracked: dir rename + delete
3166 # Commit O: z/{b,c_1}
3167 # Commit A: y/b + untracked y/{c,d,e}
3168 # Commit B: z/{b,d_1,e}
3169 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3170 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3171 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3174 test_create_repo 10b &&
3183 git commit -m "O" &&
3193 git commit -m "A" &&
3204 test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3211 echo important >y/d &&
3212 echo contents >y/e &&
3214 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3215 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3216 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3218 git ls-files -s >out &&
3219 test_line_count = 3 out &&
3220 git ls-files -u >out &&
3221 test_line_count = 2 out &&
3222 git ls-files -o >out &&
3223 test_line_count = 5 out &&
3225 git rev-parse >actual \
3226 :0:y/b :3:y/d :3:y/e &&
3227 git rev-parse >expect \
3228 O:z/b O:z/c B:z/e &&
3229 test_cmp expect actual &&
3231 echo very >expect &&
3232 test_cmp expect y/c &&
3234 echo important >expect &&
3235 test_cmp expect y/d &&
3237 echo contents >expect &&
3242 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3243 # Commit O: z/{a,b}, x/{c,d}
3244 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3245 # Commit B: z/{a,b,c}, x/d
3246 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3247 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3249 # ERROR_MSG(Refusing to lose untracked file at y/c)
3252 test_create_repo 10c_$1 &&
3263 git commit -m "O" &&
3274 git commit -m "A" &&
3283 test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3289 echo important >y/c &&
3291 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3292 test_i18ngrep "CONFLICT (rename/rename)" out &&
3293 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3295 git ls-files -s >out &&
3296 test_line_count = 6 out &&
3297 git ls-files -u >out &&
3298 test_line_count = 3 out &&
3299 git ls-files -o >out &&
3300 test_line_count = 3 out &&
3302 git rev-parse >actual \
3303 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3304 git rev-parse >expect \
3305 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3306 test_cmp expect actual &&
3308 git hash-object y/c~B^0 >actual &&
3309 git rev-parse O:x/c >expect &&
3310 test_cmp expect actual &&
3312 echo important >expect &&
3317 test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3327 echo important >y/c &&
3329 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3330 test_i18ngrep "CONFLICT (rename/rename)" out &&
3331 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3333 git ls-files -s >out &&
3334 test_line_count = 6 out &&
3335 git ls-files -u >out &&
3336 test_line_count = 3 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:x/d :1:x/c :3:w/c :2:y/c &&
3342 git rev-parse >expect \
3343 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3344 test_cmp expect actual &&
3346 git hash-object y/c~HEAD >actual &&
3347 git rev-parse O:x/c >expect &&
3348 test_cmp expect actual &&
3350 echo important >expect &&
3355 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3356 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3357 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3358 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3359 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3360 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3361 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3364 test_create_repo 10d &&
3377 git commit -m "O" &&
3384 git mv z/c x/wham &&
3387 git commit -m "A" &&
3390 git mv x/f z/wham &&
3397 test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3403 echo important >y/wham &&
3405 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3406 test_i18ngrep "CONFLICT (rename/rename)" out &&
3407 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3409 git ls-files -s >out &&
3410 test_line_count = 6 out &&
3411 git ls-files -u >out &&
3412 test_line_count = 2 out &&
3413 git ls-files -o >out &&
3414 test_line_count = 3 out &&
3416 git rev-parse >actual \
3417 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3418 git rev-parse >expect \
3419 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3420 test_cmp expect actual &&
3422 test_must_fail git rev-parse :1:y/wham &&
3424 echo important >expect &&
3425 test_cmp expect y/wham &&
3427 # Test that the two-way merge in y/wham~merged is as expected
3428 git cat-file -p :2:y/wham >expect &&
3429 git cat-file -p :3:y/wham >other &&
3431 test_must_fail git merge-file \
3435 expect empty other &&
3436 test_cmp expect y/wham~merged
3440 # Testcase 10e, Does git complain about untracked file that's not in the way?
3442 # Commit A: y/{a,b} + untracked z/c
3443 # Commit B: z/{a,b,c}
3444 # Expected: y/{a,b,c} + untracked z/c
3447 test_create_repo 10e &&
3456 git commit -m "O" &&
3465 git commit -m "A" &&
3475 test_expect_merge_algorithm failure success '10e: Does git complain about untracked file that is not really in the way?' '
3484 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3485 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3487 git ls-files -s >out &&
3488 test_line_count = 3 out &&
3489 git ls-files -u >out &&
3490 test_line_count = 0 out &&
3491 git ls-files -o >out &&
3492 test_line_count = 3 out &&
3494 git rev-parse >actual \
3495 :0:y/a :0:y/b :0:y/c &&
3496 git rev-parse >expect \
3497 O:z/a O:z/b B:z/c &&
3498 test_cmp expect actual &&
3500 echo random >expect &&
3505 ###########################################################################
3506 # SECTION 11: Handling dirty (not up-to-date) files
3508 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3509 # the operation if untracked or dirty files would be deleted or overwritten
3510 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3511 # and if it doesn't abort, then it muddies up the working directory before
3512 # we even get to the point of detecting renames, so we need some special
3513 # handling. This was true even of normal renames, but there are additional
3514 # codepaths that need special handling with directory renames. Add
3515 # testcases for both renamed-by-directory-rename-detection and standard
3517 ###########################################################################
3519 # Testcase 11a, Avoid losing dirty contents with simple rename
3520 # Commit O: z/{a,b_v1},
3521 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3522 # Commit B: z/{a,b_v2}
3523 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3524 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3525 # z/c~HEAD with contents of B:z/b_v2,
3526 # z/c with uncommitted mods on top of A:z/c_v1
3529 test_create_repo 11a &&
3535 test_seq 1 10 >z/b &&
3538 git commit -m "O" &&
3547 git commit -m "A" &&
3557 test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3565 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3566 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3568 test_seq 1 10 >expected &&
3569 echo stuff >>expected &&
3570 test_cmp expected z/c &&
3572 git ls-files -s >out &&
3573 test_line_count = 2 out &&
3574 git ls-files -u >out &&
3575 test_line_count = 1 out &&
3576 git ls-files -o >out &&
3577 test_line_count = 4 out &&
3579 git rev-parse >actual \
3581 git rev-parse >expect \
3583 test_cmp expect actual &&
3585 git hash-object z/c~HEAD >actual &&
3586 git rev-parse B:z/b >expect &&
3587 test_cmp expect actual
3591 # Testcase 11b, Avoid losing dirty file involved in directory rename
3592 # Commit O: z/a, x/{b,c_v1}
3593 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3594 # Commit B: y/a, x/{b,c_v2}
3595 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3596 # ERROR_MSG(Refusing to lose dirty file at z/c)
3600 test_create_repo 11b &&
3607 test_seq 1 10 >x/c &&
3610 git commit -m "O" &&
3619 git commit -m "A" &&
3630 test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3638 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3639 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3641 grep -q stuff z/c &&
3642 test_seq 1 10 >expected &&
3643 echo stuff >>expected &&
3644 test_cmp expected z/c &&
3646 git ls-files -s >out &&
3647 test_line_count = 3 out &&
3648 git ls-files -u >out &&
3649 test_line_count = 0 out &&
3650 git ls-files -m >out &&
3651 test_line_count = 0 out &&
3652 git ls-files -o >out &&
3653 test_line_count = 4 out &&
3655 git rev-parse >actual \
3656 :0:x/b :0:y/a :0:y/c &&
3657 git rev-parse >expect \
3658 O:x/b O:z/a B:x/c &&
3659 test_cmp expect actual &&
3661 git hash-object y/c >actual &&
3662 git rev-parse B:x/c >expect &&
3663 test_cmp expect actual
3667 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3668 # Commit O: y/a, x/{b,c_v1}
3669 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3670 # Commit B: y/{a,c/d}, x/{b,c_v2}
3671 # Expected: Abort_msg("following files would be overwritten by merge") +
3672 # y/c left untouched (still has uncommitted mods)
3675 test_create_repo 11c &&
3682 test_seq 1 10 >x/c &&
3685 git commit -m "O" &&
3694 git commit -m "A" &&
3700 git add x/c y/c/d &&
3706 test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3714 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3715 test_i18ngrep "following files would be overwritten by merge" err &&
3717 grep -q stuff y/c &&
3718 test_seq 1 10 >expected &&
3719 echo stuff >>expected &&
3720 test_cmp expected y/c &&
3722 git ls-files -s >out &&
3723 test_line_count = 3 out &&
3724 git ls-files -u >out &&
3725 test_line_count = 0 out &&
3726 git ls-files -m >out &&
3727 test_line_count = 1 out &&
3728 git ls-files -o >out &&
3729 test_line_count = 3 out
3733 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3734 # Commit O: z/a, x/{b,c_v1}
3735 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3736 # Commit B: y/{a,c/d}, x/{b,c_v2}
3737 # Expected: D/F: y/c_v2 vs y/c/d) +
3738 # Warning_Msg("Refusing to lose dirty file at z/c) +
3739 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3742 test_create_repo 11d &&
3749 test_seq 1 10 >x/c &&
3752 git commit -m "O" &&
3761 git commit -m "A" &&
3768 git add x/c y/c/d &&
3774 test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3782 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3783 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3785 grep -q stuff z/c &&
3786 test_seq 1 10 >expected &&
3787 echo stuff >>expected &&
3788 test_cmp expected z/c &&
3790 git ls-files -s >out &&
3791 test_line_count = 4 out &&
3792 git ls-files -u >out &&
3793 test_line_count = 1 out &&
3794 git ls-files -o >out &&
3795 test_line_count = 5 out &&
3797 git rev-parse >actual \
3798 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3799 git rev-parse >expect \
3800 O:x/b O:z/a B:y/c/d B:x/c &&
3801 test_cmp expect actual &&
3803 git hash-object y/c~HEAD >actual &&
3804 git rev-parse B:x/c >expect &&
3805 test_cmp expect actual
3809 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3810 # Commit O: z/{a,b}, x/{c_1,d}
3811 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3812 # Commit B: z/{a,b,c_1}, x/d
3813 # Expected: Failed Merge; y/{a,b} + x/d +
3814 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3815 # ERROR_MSG(Refusing to lose dirty file at y/c)
3816 # y/c~B^0 has O:x/c_1 contents
3817 # y/c~HEAD has A:y/c_2 contents
3818 # y/c has dirty file from before merge
3821 test_create_repo 11e &&
3832 git commit -m "O" &&
3840 echo different >y/c &&
3845 git commit -m "A" &&
3854 test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3862 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3863 test_i18ngrep "CONFLICT (rename/rename)" out &&
3864 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3866 git ls-files -s >out &&
3867 test_line_count = 7 out &&
3868 git ls-files -u >out &&
3869 test_line_count = 4 out &&
3870 git ls-files -o >out &&
3871 test_line_count = 3 out &&
3873 echo different >expected &&
3874 echo mods >>expected &&
3875 test_cmp expected y/c &&
3877 git rev-parse >actual \
3878 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3879 git rev-parse >expect \
3880 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3881 test_cmp expect actual &&
3883 # See if y/c~merged has expected contents; requires manually
3884 # doing the expected file merge
3885 git cat-file -p A:y/c >c1 &&
3886 git cat-file -p B:z/c >c2 &&
3888 test_must_fail git merge-file \
3893 test_cmp c1 y/c~merged
3897 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3898 # Commit O: z/{a,b}, x/{c_1,d_2}
3899 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3900 # Commit B: z/{a,b,wham_2}, x/c_1
3901 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3902 # y/wham with dirty changes from before merge +
3903 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3904 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3907 test_create_repo 11f &&
3914 test_seq 1 10 >x/c &&
3918 git commit -m "O" &&
3926 git mv x/c y/wham &&
3928 git commit -m "A" &&
3931 git mv x/d z/wham &&
3937 test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3943 echo important >>y/wham &&
3945 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3946 test_i18ngrep "CONFLICT (rename/rename)" out &&
3947 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3949 git ls-files -s >out &&
3950 test_line_count = 4 out &&
3951 git ls-files -u >out &&
3952 test_line_count = 2 out &&
3953 git ls-files -o >out &&
3954 test_line_count = 3 out &&
3956 test_seq 1 10 >expected &&
3957 echo important >>expected &&
3958 test_cmp expected y/wham &&
3960 test_must_fail git rev-parse :1:y/wham &&
3962 git rev-parse >actual \
3963 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3964 git rev-parse >expect \
3965 O:z/a O:z/b O:x/c O:x/d &&
3966 test_cmp expect actual &&
3968 # Test that the two-way merge in y/wham~merged is as expected
3969 git cat-file -p :2:y/wham >expect &&
3970 git cat-file -p :3:y/wham >other &&
3972 test_must_fail git merge-file \
3976 expect empty other &&
3977 test_cmp expect y/wham~merged
3981 ###########################################################################
3982 # SECTION 12: Everything else
3984 # Tests suggested by others. Tests added after implementation completed
3985 # and submitted. Grab bag.
3986 ###########################################################################
3988 # Testcase 12a, Moving one directory hierarchy into another
3989 # (Related to testcase 9a)
3990 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3991 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3992 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3993 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3996 test_create_repo 12a &&
4000 mkdir -p node1 node2 &&
4001 echo leaf1 >node1/leaf1 &&
4002 echo leaf2 >node1/leaf2 &&
4003 echo leaf3 >node2/leaf3 &&
4004 echo leaf4 >node2/leaf4 &&
4005 git add node1 node2 &&
4007 git commit -m "O" &&
4014 git mv node2/ node1/ &&
4016 git commit -m "A" &&
4019 echo leaf5 >node1/leaf5 &&
4020 echo leaf6 >node2/leaf6 &&
4021 git add node1 node2 &&
4027 test_expect_success '12a: Moving one directory hierarchy into another' '
4034 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4036 git ls-files -s >out &&
4037 test_line_count = 6 out &&
4039 git rev-parse >actual \
4040 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4041 HEAD:node1/node2/leaf3 \
4042 HEAD:node1/node2/leaf4 \
4043 HEAD:node1/node2/leaf6 &&
4044 git rev-parse >expect \
4045 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4049 test_cmp expect actual
4053 # Testcase 12b1, Moving two directory hierarchies into each other
4054 # (Related to testcases 1c and 12c)
4055 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4056 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4057 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4058 # Expected: node1/node2/{leaf3, leaf4}
4059 # node2/node1/{leaf1, leaf2}
4060 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4061 # then we would need to detect renames for those directories and would
4063 # commit A renames node2/ -> node1/node2/
4064 # commit B renames node1/ -> node2/node1/
4065 # Applying those directory renames to the initial result (making all
4066 # four paths experience a transitive renaming), yields
4067 # node1/node2/node1/{leaf1, leaf2}
4068 # node2/node1/node2/{leaf3, leaf4}
4069 # as the result. It may be really weird to have two directories
4070 # rename each other, but simple rules give weird results when given
4071 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4072 # false; there were no new files added and thus there is no directory
4073 # rename detection to perform. As such, we just have simple renames
4074 # and the expected answer is:
4075 # node1/node2/{leaf3, leaf4}
4076 # node2/node1/{leaf1, leaf2}
4078 test_setup_12b1 () {
4079 test_create_repo 12b1 &&
4083 mkdir -p node1 node2 &&
4084 echo leaf1 >node1/leaf1 &&
4085 echo leaf2 >node1/leaf2 &&
4086 echo leaf3 >node2/leaf3 &&
4087 echo leaf4 >node2/leaf4 &&
4088 git add node1 node2 &&
4090 git commit -m "O" &&
4097 git mv node2/ node1/ &&
4099 git commit -m "A" &&
4102 git mv node1/ node2/ &&
4108 test_expect_merge_algorithm failure success '12b1: Moving two directory hierarchies into each other' '
4115 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4117 git ls-files -s >out &&
4118 test_line_count = 4 out &&
4120 git rev-parse >actual \
4121 HEAD:node2/node1/leaf1 \
4122 HEAD:node2/node1/leaf2 \
4123 HEAD:node1/node2/leaf3 \
4124 HEAD:node1/node2/leaf4 &&
4125 git rev-parse >expect \
4130 test_cmp expect actual
4134 # Testcase 12b2, Moving two directory hierarchies into each other
4135 # (Related to testcases 1c and 12c)
4136 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4137 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4138 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4139 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4140 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4141 # NOTE: Without directory renames, we would expect
4142 # A: node2/leaf3 -> node1/node2/leaf3
4143 # A: node2/leaf1 -> node1/node2/leaf4
4144 # A: Adds node1/leaf5
4145 # B: node1/leaf1 -> node2/node1/leaf1
4146 # B: node1/leaf2 -> node2/node1/leaf2
4147 # B: Adds node2/leaf6
4148 # with directory rename detection, we note that
4149 # commit A renames node2/ -> node1/node2/
4150 # commit B renames node1/ -> node2/node1/
4151 # therefore, applying A's directory rename to the paths added in B gives:
4152 # B: node1/leaf1 -> node1/node2/node1/leaf1
4153 # B: node1/leaf2 -> node1/node2/node1/leaf2
4154 # B: Adds node1/node2/leaf6
4155 # and applying B's directory rename to the paths added in A gives:
4156 # A: node2/leaf3 -> node2/node1/node2/leaf3
4157 # A: node2/leaf1 -> node2/node1/node2/leaf4
4158 # A: Adds node2/node1/leaf5
4159 # resulting in the expected
4160 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4161 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4163 # You may ask, is it weird to have two directories rename each other?
4164 # To which, I can do no more than shrug my shoulders and say that
4165 # even simple rules give weird results when given weird inputs.
4167 test_setup_12b2 () {
4168 test_create_repo 12b2 &&
4172 mkdir -p node1 node2 &&
4173 echo leaf1 >node1/leaf1 &&
4174 echo leaf2 >node1/leaf2 &&
4175 echo leaf3 >node2/leaf3 &&
4176 echo leaf4 >node2/leaf4 &&
4177 git add node1 node2 &&
4179 git commit -m "O" &&
4186 git mv node2/ node1/ &&
4187 echo leaf5 >node1/leaf5 &&
4188 git add node1/leaf5 &&
4190 git commit -m "A" &&
4193 git mv node1/ node2/ &&
4194 echo leaf6 >node2/leaf6 &&
4195 git add node2/leaf6 &&
4201 test_expect_success '12b2: Moving two directory hierarchies into each other' '
4208 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4210 git ls-files -s >out &&
4211 test_line_count = 6 out &&
4213 git rev-parse >actual \
4214 HEAD:node1/node2/node1/leaf1 \
4215 HEAD:node1/node2/node1/leaf2 \
4216 HEAD:node2/node1/node2/leaf3 \
4217 HEAD:node2/node1/node2/leaf4 \
4218 HEAD:node2/node1/leaf5 \
4219 HEAD:node1/node2/leaf6 &&
4220 git rev-parse >expect \
4227 test_cmp expect actual
4231 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4232 # (Related to testcase 12b)
4233 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4234 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4235 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4236 # Expected: Content merge conflicts for each of:
4237 # node1/node2/node1/{leaf1, leaf2},
4238 # node2/node1/node2/{leaf3, leaf4}
4239 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4240 # each side of the merge.
4242 test_setup_12c1 () {
4243 test_create_repo 12c1 &&
4247 mkdir -p node1 node2 &&
4248 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4249 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4250 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4251 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4252 git add node1 node2 &&
4254 git commit -m "O" &&
4261 git mv node2/ node1/ &&
4262 for i in `git ls-files`; do echo side A >>$i; done &&
4265 git commit -m "A" &&
4268 git mv node1/ node2/ &&
4269 for i in `git ls-files`; do echo side B >>$i; done &&
4276 test_expect_merge_algorithm failure success '12c1: Moving one directory hierarchy into another w/ content merge' '
4283 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4285 git ls-files -u >out &&
4286 test_line_count = 12 out &&
4288 git rev-parse >actual \
4289 :1:node2/node1/leaf1 \
4290 :1:node2/node1/leaf2 \
4291 :1:node1/node2/leaf3 \
4292 :1:node1/node2/leaf4 \
4293 :2:node2/node1/leaf1 \
4294 :2:node2/node1/leaf2 \
4295 :2:node1/node2/leaf3 \
4296 :2:node1/node2/leaf4 \
4297 :3:node2/node1/leaf1 \
4298 :3:node2/node1/leaf2 \
4299 :3:node1/node2/leaf3 \
4300 :3:node1/node2/leaf4 &&
4301 git rev-parse >expect \
4308 A:node1/node2/leaf3 \
4309 A:node1/node2/leaf4 \
4310 B:node2/node1/leaf1 \
4311 B:node2/node1/leaf2 \
4314 test_cmp expect actual
4318 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4319 # (Related to testcase 12b)
4320 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4321 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4322 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4323 # Expected: Content merge conflicts for each of:
4324 # node1/node2/node1/{leaf1, leaf2}
4325 # node2/node1/node2/{leaf3, leaf4}
4329 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4330 # on each side of the merge.
4332 test_setup_12c2 () {
4333 test_create_repo 12c2 &&
4337 mkdir -p node1 node2 &&
4338 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4339 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4340 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4341 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4342 git add node1 node2 &&
4344 git commit -m "O" &&
4351 git mv node2/ node1/ &&
4352 for i in `git ls-files`; do echo side A >>$i; done &&
4354 echo leaf5 >node1/leaf5 &&
4355 git add node1/leaf5 &&
4357 git commit -m "A" &&
4360 git mv node1/ node2/ &&
4361 for i in `git ls-files`; do echo side B >>$i; done &&
4363 echo leaf6 >node2/leaf6 &&
4364 git add node2/leaf6 &&
4370 test_expect_success '12c2: Moving one directory hierarchy into another w/ content merge' '
4377 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4379 git ls-files -s >out &&
4380 test_line_count = 14 out &&
4381 git ls-files -u >out &&
4382 test_line_count = 12 out &&
4384 git rev-parse >actual \
4385 :1:node1/node2/node1/leaf1 \
4386 :1:node1/node2/node1/leaf2 \
4387 :1:node2/node1/node2/leaf3 \
4388 :1:node2/node1/node2/leaf4 \
4389 :2:node1/node2/node1/leaf1 \
4390 :2:node1/node2/node1/leaf2 \
4391 :2:node2/node1/node2/leaf3 \
4392 :2:node2/node1/node2/leaf4 \
4393 :3:node1/node2/node1/leaf1 \
4394 :3:node1/node2/node1/leaf2 \
4395 :3:node2/node1/node2/leaf3 \
4396 :3:node2/node1/node2/leaf4 \
4397 :0:node2/node1/leaf5 \
4398 :0:node1/node2/leaf6 &&
4399 git rev-parse >expect \
4406 A:node1/node2/leaf3 \
4407 A:node1/node2/leaf4 \
4408 B:node2/node1/leaf1 \
4409 B:node2/node1/leaf2 \
4414 test_cmp expect actual
4418 # Testcase 12d, Rename/merge of subdirectory into the root
4419 # Commit O: a/b/subdir/foo
4420 # Commit A: subdir/foo
4421 # Commit B: a/b/subdir/foo, a/b/bar
4422 # Expected: subdir/foo, bar
4425 test_create_repo 12d &&
4429 mkdir -p a/b/subdir &&
4430 test_commit a/b/subdir/foo &&
4438 git mv a/b/subdir/foo.t subdir/foo.t &&
4440 git commit -m "A" &&
4447 test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4454 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4456 git ls-files -s >out &&
4457 test_line_count = 2 out &&
4459 git rev-parse >actual \
4460 HEAD:subdir/foo.t HEAD:bar.t &&
4461 git rev-parse >expect \
4462 O:a/b/subdir/foo.t B:a/b/bar.t &&
4463 test_cmp expect actual &&
4465 git hash-object bar.t >actual &&
4466 git rev-parse B:a/b/bar.t >expect &&
4467 test_cmp expect actual &&
4469 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4470 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4471 test_path_is_missing a/ &&
4472 test_path_is_file bar.t
4476 # Testcase 12e, Rename/merge of subdirectory into the root
4479 # Commit B: a/b/foo, a/b/bar
4480 # Expected: foo, bar
4483 test_create_repo 12e &&
4488 test_commit a/b/foo &&
4496 git mv a/b/foo.t foo.t &&
4498 git commit -m "A" &&
4505 test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4512 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4514 git ls-files -s >out &&
4515 test_line_count = 2 out &&
4517 git rev-parse >actual \
4518 HEAD:foo.t HEAD:bar.t &&
4519 git rev-parse >expect \
4520 O:a/b/foo.t B:a/b/bar.t &&
4521 test_cmp expect actual &&
4523 git hash-object bar.t >actual &&
4524 git rev-parse B:a/b/bar.t >expect &&
4525 test_cmp expect actual &&
4527 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4528 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4529 test_path_is_missing a/ &&
4530 test_path_is_file bar.t
4534 # Testcase 12f, Rebase of patches with big directory rename
4536 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4537 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4538 # dir/unchanged/<LOTS OF FILES>
4540 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4541 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4542 # folder/subdir/newsubdir/e_A
4543 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4544 # folder/unchanged/<LOTS OF FILES>
4546 # (add newfile.{c,py}, modify underscored files)
4547 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4548 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4549 # dir/unchanged/<LOTS OF FILES>
4551 # (Modify e further, add newfile.rs)
4552 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4553 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4554 # dir/unchanged/<LOTS OF FILES>
4557 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4558 # folder/subdir/newsubdir/e_Merge1
4559 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4560 # folder/unchanged/<LOTS OF FILES>
4562 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4563 # folder/subdir/newsubdir/e_Merge2
4564 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4565 # folder/unchanged/<LOTS OF FILES>
4567 # Notes: This testcase happens to exercise lots of the
4568 # optimization-specific codepaths in merge-ort, and also
4569 # demonstrated a failing of the directory rename detection algorithm
4570 # in merge-recursive; newfile.c should not get pushed into
4571 # folder/subdir/newsubdir/, yet merge-recursive put it there because
4572 # the rename of dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d}
4575 # whereas the rename of dir/subdir/e -> folder/subdir/newsubdir/e
4577 # dir/subdir/ -> folder/subdir/newsubdir/
4578 # and if we note that newfile.c is found in dir/subdir/, we might
4579 # overlook the dir/ -> folder/ rule that has more weight.
4582 test_create_repo 12f &&
4586 mkdir -p dir/unchanged &&
4587 mkdir -p dir/subdir/tweaked &&
4588 echo a >dir/subdir/a &&
4589 echo b >dir/subdir/b &&
4590 echo c >dir/subdir/c &&
4591 echo d >dir/subdir/d &&
4592 test_seq 1 10 >dir/subdir/e &&
4593 test_seq 10 20 >dir/subdir/Makefile &&
4594 echo f >dir/subdir/tweaked/f &&
4595 echo g >dir/subdir/tweaked/g &&
4596 echo h >dir/subdir/tweaked/h &&
4597 test_seq 20 30 >dir/subdir/tweaked/Makefile &&
4598 for i in `test_seq 1 88`; do
4599 echo content $i >dir/unchanged/file_$i
4602 git commit -m "O" &&
4609 git rm dir/subdir/tweaked/f dir/subdir/tweaked/g &&
4610 test_seq 2 10 >dir/subdir/e &&
4611 test_seq 11 20 >dir/subdir/Makefile &&
4612 test_seq 21 30 >dir/subdir/tweaked/Makefile &&
4613 mkdir dir/subdir/newsubdir &&
4614 git mv dir/subdir/e dir/subdir/newsubdir/ &&
4615 git mv dir folder &&
4617 git commit -m "A" &&
4620 mkdir dir/subdir/newsubdir/ &&
4621 echo c code >dir/subdir/newfile.c &&
4622 echo python code >dir/subdir/newsubdir/newfile.py &&
4623 test_seq 1 11 >dir/subdir/e &&
4624 test_seq 10 21 >dir/subdir/Makefile &&
4625 test_seq 20 31 >dir/subdir/tweaked/Makefile &&
4627 git commit -m "B1" &&
4629 echo rust code >dir/subdir/newfile.rs &&
4630 test_seq 1 12 >dir/subdir/e &&
4636 test_expect_merge_algorithm failure success '12f: Trivial directory resolve, caching, all kinds of fun' '
4642 git branch Bmod B &&
4644 git -c merge.directoryRenames=true rebase A Bmod &&
4646 echo Checking the pick of B1... &&
4648 test_must_fail git rev-parse Bmod~1:dir &&
4650 git ls-tree -r Bmod~1 >out &&
4651 test_line_count = 98 out &&
4653 git diff --name-status A Bmod~1 >actual &&
4654 q_to_tab >expect <<-\EOF &&
4655 MQfolder/subdir/Makefile
4656 AQfolder/subdir/newfile.c
4657 MQfolder/subdir/newsubdir/e
4658 AQfolder/subdir/newsubdir/newfile.py
4659 MQfolder/subdir/tweaked/Makefile
4661 test_cmp expect actual &&
4663 # Three-way merged files
4664 test_seq 2 11 >e_Merge1 &&
4665 test_seq 11 21 >Makefile_TOP &&
4666 test_seq 21 31 >Makefile_SUB &&
4667 git hash-object >expect \
4671 git rev-parse >actual \
4672 Bmod~1:folder/subdir/newsubdir/e \
4673 Bmod~1:folder/subdir/Makefile \
4674 Bmod~1:folder/subdir/tweaked/Makefile &&
4675 test_cmp expect actual &&
4677 # New files showed up at the right location with right contents
4678 git rev-parse >expect \
4679 B~1:dir/subdir/newfile.c \
4680 B~1:dir/subdir/newsubdir/newfile.py &&
4681 git rev-parse >actual \
4682 Bmod~1:folder/subdir/newfile.c \
4683 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4684 test_cmp expect actual &&
4687 test_path_is_missing folder/subdir/tweaked/f &&
4688 test_path_is_missing folder/subdir/tweaked/g &&
4690 # Unchanged files or directories
4691 git rev-parse >actual \
4692 Bmod~1:folder/subdir/a \
4693 Bmod~1:folder/subdir/b \
4694 Bmod~1:folder/subdir/c \
4695 Bmod~1:folder/subdir/d \
4696 Bmod~1:folder/unchanged \
4697 Bmod~1:folder/subdir/tweaked/h &&
4698 git rev-parse >expect \
4704 O:dir/subdir/tweaked/h &&
4705 test_cmp expect actual &&
4707 echo Checking the pick of B2... &&
4709 test_must_fail git rev-parse Bmod:dir &&
4711 git ls-tree -r Bmod >out &&
4712 test_line_count = 99 out &&
4714 git diff --name-status Bmod~1 Bmod >actual &&
4715 q_to_tab >expect <<-\EOF &&
4716 AQfolder/subdir/newfile.rs
4717 MQfolder/subdir/newsubdir/e
4719 test_cmp expect actual &&
4721 # Three-way merged file
4722 test_seq 2 12 >e_Merge2 &&
4723 git hash-object e_Merge2 >expect &&
4724 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4725 test_cmp expect actual
4729 ###########################################################################
4730 # SECTION 13: Checking informational and conflict messages
4732 # A year after directory rename detection became the default, it was
4733 # instead decided to report conflicts on the pathname on the basis that
4734 # some users may expect the new files added or moved into a directory to
4735 # be unrelated to all the other files in that directory, and thus that
4736 # directory rename detection is unexpected. Test that the messages printed
4737 # match our expectation.
4738 ###########################################################################
4740 # Testcase 13a, Basic directory rename with newly added files
4743 # Commit B: z/{b,c,d,e/f}
4744 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4747 test_create_repo 13a_$1 &&
4756 git commit -m "O" &&
4765 git commit -m "A" &&
4771 git add z/d z/e/f &&
4777 test_expect_success '13a(conflict): messages for newly added files' '
4778 test_setup_13a conflict &&
4784 test_must_fail git merge -s recursive B^0 >out 2>err &&
4786 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4787 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4789 git ls-files >paths &&
4791 grep "y/[de]" paths &&
4793 test_path_is_missing z/d &&
4794 test_path_is_file y/d &&
4795 test_path_is_missing z/e/f &&
4796 test_path_is_file y/e/f
4800 test_expect_success '13a(info): messages for newly added files' '
4801 test_setup_13a info &&
4808 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4810 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4811 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4813 git ls-files >paths &&
4815 grep "y/[de]" paths &&
4817 test_path_is_missing z/d &&
4818 test_path_is_file y/d &&
4819 test_path_is_missing z/e/f &&
4820 test_path_is_file y/e/f
4824 # Testcase 13b, Transitive rename with conflicted content merge and default
4825 # "conflict" setting
4826 # (Related to testcase 1c, 9b)
4827 # Commit O: z/{b,c}, x/d_1
4828 # Commit A: y/{b,c}, x/d_2
4829 # Commit B: z/{b,c,d_3}
4830 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4831 # one about content, and one about file location
4834 test_create_repo 13b_$1 &&
4840 test_seq 1 10 >x/d &&
4845 git commit -m "O" &&
4856 git commit -m "A" &&
4859 echo eleven >>x/d &&
4867 test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
4868 test_setup_13b conflict &&
4874 test_must_fail git merge -s recursive B^0 >out 2>err &&
4876 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4877 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4879 git ls-files >paths &&
4883 test_path_is_missing z/d &&
4884 test_path_is_file y/d
4888 test_expect_success '13b(info): messages for transitive rename with conflicted content' '
4889 test_setup_13b info &&
4896 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4898 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4899 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4901 git ls-files >paths &&
4905 test_path_is_missing z/d &&
4906 test_path_is_file y/d
4910 # Testcase 13c, Rename/rename(1to1) due to directory rename
4911 # Commit O: z/{b,c}, x/{d,e}
4912 # Commit A: y/{b,c,d}, x/e
4913 # Commit B: z/{b,c,d}, x/e
4914 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
4915 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4916 # One could argue A had partial knowledge of what was done with
4917 # d and B had full knowledge, but that's a slippery slope as
4918 # shown in testcase 13d.
4921 test_create_repo 13c_$1 &&
4927 test_seq 1 10 >x/d &&
4933 git commit -m "O" &&
4943 git commit -m "A" &&
4953 test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
4954 test_setup_13c conflict &&
4960 test_must_fail git merge -s recursive B^0 >out 2>err &&
4962 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4964 git ls-files >paths &&
4968 test_path_is_missing z/d &&
4969 test_path_is_file y/d
4973 test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
4974 test_setup_13c info &&
4981 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4983 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4985 git ls-files >paths &&
4989 test_path_is_missing z/d &&
4990 test_path_is_file y/d
4994 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4995 # Commit O: a/{z,y}, b/x, c/w
4996 # Commit A: a/z, b/{y,x}, d/w
4997 # Commit B: a/z, d/x, c/{y,w}
4998 # Expected: a/z, d/{y,x,w} with no file location conflict for x
5000 # * z is always in a; so it stays in a.
5001 # * x starts in b, only modified on one side to move into d/
5002 # * w starts in c, only modified on one side to move into d/
5004 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5005 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5006 # No conflict in where a/y ends up, so put it in d/y.
5009 test_create_repo 13d_$1 &&
5022 git commit -m "O" &&
5032 git commit -m "A" &&
5042 test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5043 test_setup_13d conflict &&
5049 test_must_fail git merge -s recursive B^0 >out 2>err &&
5051 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5052 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5054 git ls-files >paths &&
5059 test_path_is_missing b/y &&
5060 test_path_is_missing c/y &&
5061 test_path_is_file d/y
5065 test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5066 test_setup_13d info &&
5073 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5075 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5076 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5078 git ls-files >paths &&
5083 test_path_is_missing b/y &&
5084 test_path_is_missing c/y &&
5085 test_path_is_file d/y
5089 # Testcase 13e, directory rename in virtual merge base
5091 # This testcase has a slightly different setup than all the above cases, in
5092 # order to include a recursive case:
5104 # Commit B: a/{z,y,x}
5105 # Commit C: b/{z,y,x}
5106 # Commit D: b/{z,y}, a/x
5107 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5109 # NOTES: 'X' represents a virtual merge base. With the default of
5110 # directory rename detection yielding conflicts, merging A and B
5111 # results in a conflict complaining about whether 'x' should be
5112 # under 'a/' or 'b/'. However, when creating the virtual merge
5113 # base 'X', since virtual merge bases need to be written out as a
5114 # tree, we cannot have a conflict, so some resolution has to be
5117 # In choosing the right resolution, it's worth noting here that
5118 # commits C & D are merges of A & B that choose different
5119 # locations for 'x' (i.e. they resolve the conflict differently),
5120 # and so it would be nice when merging C & D if git could detect
5121 # this difference of opinion and report a conflict. But the only
5122 # way to do so that I can think of would be to have the virtual
5123 # merge base place 'x' in some directory other than either 'a/' or
5124 # 'b/', which seems a little weird -- especially since it'd result
5125 # in a rename/rename(1to2) conflict with a source path that never
5126 # existed in any version.
5128 # So, for now, when directory rename detection is set to
5129 # 'conflict' just avoid doing directory rename detection at all in
5130 # the recursive case. This will not allow us to detect a conflict
5131 # in the outer merge for this special kind of setup, but it at
5132 # least avoids hitting a BUG().
5135 test_create_repo 13e &&
5144 git commit -m "O" &&
5153 git commit -m "A" &&
5159 git commit -m "B" &&
5165 test_must_fail git -c merge.directoryRenames=conflict merge B &&
5168 git commit -m "C" &&
5172 test_must_fail git -c merge.directoryRenames=conflict merge A &&
5181 test_expect_success '13e: directory rename detection in recursive case' '
5186 git checkout --quiet D^0 &&
5188 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5190 test_i18ngrep ! CONFLICT out &&
5191 test_i18ngrep ! BUG: err &&
5192 test_i18ngrep ! core.dumped err &&
5193 test_must_be_empty err &&
5195 git ls-files >paths &&