3 test_description="recursive merge with directory renames"
4 # includes checking of many corner cases, with a similar methodology to:
5 # t6042: corner cases with renames but not criss-cross merges
6 # t6036: corner cases with both renames and criss-cross merges
8 # The setup for all of them, pictorially, is:
18 # To help make it easier to follow the flow of tests, they have been
19 # divided into sections and each test will start with a quick explanation
20 # of what commits O, A, and B contain.
23 # z/{b,c} means files z/b and z/c both exist
24 # x/d_1 means file x/d exists with content d1. (Purpose of the
25 # underscore notation is to differentiate different
26 # files that might be renamed into each other's paths.)
31 ###########################################################################
32 # SECTION 1: Basic cases we should be able to handle
33 ###########################################################################
35 # Testcase 1a, Basic directory rename.
38 # Commit B: z/{b,c,d,e/f}
39 # Expected: y/{b,c,d,e/f}
42 test_create_repo 1a &&
72 test_expect_success '1a: Simple directory rename detection' '
79 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
81 git ls-files -s >out &&
82 test_line_count = 4 out &&
84 git rev-parse >actual \
85 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
86 git rev-parse >expect \
87 O:z/b O:z/c B:z/d B:z/e/f &&
88 test_cmp expect actual &&
90 git hash-object y/d >actual &&
91 git rev-parse B:z/d >expect &&
92 test_cmp expect actual &&
94 test_must_fail git rev-parse HEAD:z/d &&
95 test_must_fail git rev-parse HEAD:z/e/f &&
96 test_path_is_missing z/d &&
97 test_path_is_missing z/e/f
101 # Testcase 1b, Merge a directory with another
102 # Commit O: z/{b,c}, y/d
103 # Commit A: z/{b,c,e}, y/d
104 # Commit B: y/{b,c,d}
105 # Expected: y/{b,c,d,e}
108 test_create_repo 1b &&
140 test_expect_success '1b: Merge a directory with another' '
147 git -c merge.directoryRenames=true merge -s recursive B^0 &&
149 git ls-files -s >out &&
150 test_line_count = 4 out &&
152 git rev-parse >actual \
153 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
154 git rev-parse >expect \
155 O:z/b O:z/c O:y/d A:z/e &&
156 test_cmp expect actual &&
157 test_must_fail git rev-parse HEAD:z/e
161 # Testcase 1c, Transitive renaming
162 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
163 # (Related to testcases 9c and 9d -- can transitivity repeat?)
164 # (Related to testcase 12b -- joint-transitivity?)
165 # Commit O: z/{b,c}, x/d
166 # Commit A: y/{b,c}, x/d
167 # Commit B: z/{b,c,d}
168 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
171 test_create_repo 1c &&
200 test_expect_success '1c: Transitive renaming' '
207 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
209 git ls-files -s >out &&
210 test_line_count = 3 out &&
212 git rev-parse >actual \
213 HEAD:y/b HEAD:y/c HEAD:y/d &&
214 git rev-parse >expect \
216 test_cmp expect actual &&
217 test_must_fail git rev-parse HEAD:x/d &&
218 test_must_fail git rev-parse HEAD:z/d &&
219 test_path_is_missing z/d
223 # Testcase 1d, Directory renames (merging two directories into one new one)
224 # cause a rename/rename(2to1) conflict
225 # (Related to testcases 1c and 7b)
226 # Commit O. z/{b,c}, y/{d,e}
227 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
228 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
229 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
230 # Note: y/m & z/n should definitely move into x. By the same token, both
231 # y/wham_1 & z/wham_2 should too...giving us a conflict.
234 test_create_repo 1d &&
255 echo wham1 >y/wham &&
263 echo wham2 >z/wham &&
270 test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict' '
277 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
278 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
280 git ls-files -s >out &&
281 test_line_count = 8 out &&
282 git ls-files -u >out &&
283 test_line_count = 2 out &&
284 git ls-files -o >out &&
285 test_line_count = 1 out &&
287 git rev-parse >actual \
288 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
289 git rev-parse >expect \
290 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
291 test_cmp expect actual &&
293 test_must_fail git rev-parse :0:x/wham &&
294 git rev-parse >actual \
295 :2:x/wham :3:x/wham &&
296 git rev-parse >expect \
298 test_cmp expect actual &&
300 # Test that the two-way merge in x/wham is as expected
301 git cat-file -p :2:x/wham >expect &&
302 git cat-file -p :3:x/wham >other &&
304 test_must_fail git merge-file \
308 expect empty other &&
309 test_cmp expect x/wham
313 # Testcase 1e, Renamed directory, with all filenames being renamed too
314 # (Related to testcases 9f & 9g)
315 # Commit O: z/{oldb,oldc}
316 # Commit A: y/{newb,newc}
317 # Commit B: z/{oldb,oldc,d}
318 # Expected: y/{newb,newc,d}
321 test_create_repo 1e &&
338 git mv z/oldb y/newb &&
339 git mv z/oldc y/newc &&
351 test_expect_success '1e: Renamed directory, with all files being renamed too' '
358 git -c merge.directoryRenames=true merge -s recursive B^0 &&
360 git ls-files -s >out &&
361 test_line_count = 3 out &&
363 git rev-parse >actual \
364 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
365 git rev-parse >expect \
366 O:z/oldb O:z/oldc B:z/d &&
367 test_cmp expect actual &&
368 test_must_fail git rev-parse HEAD:z/d
372 # Testcase 1f, Split a directory into two other directories
373 # (Related to testcases 3a, all of section 2, and all of section 4)
374 # Commit O: z/{b,c,d,e,f}
375 # Commit A: z/{b,c,d,e,f,g}
376 # Commit B: y/{b,c}, x/{d,e,f}
377 # Expected: y/{b,c}, x/{d,e,f,g}
380 test_create_repo 1f &&
418 test_expect_success '1f: Split a directory into two other directories' '
425 git -c merge.directoryRenames=true merge -s recursive B^0 &&
427 git ls-files -s >out &&
428 test_line_count = 6 out &&
430 git rev-parse >actual \
431 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
432 git rev-parse >expect \
433 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
434 test_cmp expect actual &&
435 test_path_is_missing z/g &&
436 test_must_fail git rev-parse HEAD:z/g
440 ###########################################################################
441 # Rules suggested by testcases in section 1:
443 # We should still detect the directory rename even if it wasn't just
444 # the directory renamed, but the files within it. (see 1b)
446 # If renames split a directory into two or more others, the directory
447 # with the most renames, "wins" (see 1c). However, see the testcases
448 # in section 2, plus testcases 3a and 4a.
449 ###########################################################################
452 ###########################################################################
453 # SECTION 2: Split into multiple directories, with equal number of paths
455 # Explore the splitting-a-directory rules a bit; what happens in the
458 # Note that there is a closely related case of a directory not being
459 # split on either side of history, but being renamed differently on
460 # each side. See testcase 8e for that.
461 ###########################################################################
463 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
466 # Commit B: z/{b,c,d}
467 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
469 test_create_repo 2a &&
500 test_expect_success '2a: Directory split into two on one side, with equal numbers of paths' '
507 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
508 test_i18ngrep "CONFLICT.*directory rename split" out &&
510 git ls-files -s >out &&
511 test_line_count = 3 out &&
512 git ls-files -u >out &&
513 test_line_count = 0 out &&
514 git ls-files -o >out &&
515 test_line_count = 1 out &&
517 git rev-parse >actual \
518 :0:y/b :0:w/c :0:z/d &&
519 git rev-parse >expect \
521 test_cmp expect actual
525 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
528 # Commit B: z/{b,c}, x/d
529 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
531 test_create_repo 2b &&
563 test_expect_success '2b: Directory split into two on one side, with equal numbers of paths' '
570 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
572 git ls-files -s >out &&
573 test_line_count = 3 out &&
574 git ls-files -u >out &&
575 test_line_count = 0 out &&
576 git ls-files -o >out &&
577 test_line_count = 1 out &&
579 git rev-parse >actual \
580 :0:y/b :0:w/c :0:x/d &&
581 git rev-parse >expect \
583 test_cmp expect actual &&
584 test_i18ngrep ! "CONFLICT.*directory rename split" out
588 ###########################################################################
589 # Rules suggested by section 2:
591 # None; the rule was already covered in section 1. These testcases are
592 # here just to make sure the conflict resolution and necessary warning
593 # messages are handled correctly.
594 ###########################################################################
597 ###########################################################################
598 # SECTION 3: Path in question is the source path for some rename already
600 # Combining cases from Section 1 and trying to handle them could lead to
601 # directory renaming detection being over-applied. So, this section
602 # provides some good testcases to check that the implementation doesn't go
604 ###########################################################################
606 # Testcase 3a, Avoid implicit rename if involved as source on other side
607 # (Related to testcases 1c, 1f, and 9h)
608 # Commit O: z/{b,c,d}
609 # Commit A: z/{b,c,d} (no change)
610 # Commit B: y/{b,c}, x/d
611 # Expected: y/{b,c}, x/d
613 test_create_repo 3a &&
631 git commit --allow-empty -m "A" &&
645 test_expect_success '3a: Avoid implicit rename if involved as source on other side' '
652 git -c merge.directoryRenames=true merge -s recursive B^0 &&
654 git ls-files -s >out &&
655 test_line_count = 3 out &&
657 git rev-parse >actual \
658 HEAD:y/b HEAD:y/c HEAD:x/d &&
659 git rev-parse >expect \
661 test_cmp expect actual
665 # Testcase 3b, Avoid implicit rename if involved as source on other side
666 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
667 # Commit O: z/{b,c,d}
668 # Commit A: y/{b,c}, x/d
669 # Commit B: z/{b,c}, w/d
670 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
671 # NOTE: We're particularly checking that since z/d is already involved as
672 # a source in a file rename on the same side of history, that we don't
673 # get it involved in directory rename detection. If it were, we might
674 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
675 # rename/rename/rename(1to3) conflict, which is just weird.
677 test_create_repo 3b &&
711 test_expect_success '3b: Avoid implicit rename if involved as source on current side' '
718 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
719 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
720 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
722 git ls-files -s >out &&
723 test_line_count = 5 out &&
724 git ls-files -u >out &&
725 test_line_count = 3 out &&
726 git ls-files -o >out &&
727 test_line_count = 1 out &&
729 git rev-parse >actual \
730 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
731 git rev-parse >expect \
732 O:z/b O:z/c O:z/d O:z/d O:z/d &&
733 test_cmp expect actual &&
735 test_path_is_missing z/d &&
736 git hash-object >actual \
738 git rev-parse >expect \
740 test_cmp expect actual
744 ###########################################################################
745 # Rules suggested by section 3:
747 # Avoid directory-rename-detection for a path, if that path is the source
748 # of a rename on either side of a merge.
749 ###########################################################################
752 ###########################################################################
753 # SECTION 4: Partially renamed directory; still exists on both sides of merge
755 # What if we were to attempt to do directory rename detection when someone
756 # "mostly" moved a directory but still left some files around, or,
757 # equivalently, fully renamed a directory in one commit and then recreated
758 # that directory in a later commit adding some new files and then tried to
761 # It's hard to divine user intent in these cases, because you can make an
762 # argument that, depending on the intermediate history of the side being
763 # merged, that some users will want files in that directory to
764 # automatically be detected and renamed, while users with a different
765 # intermediate history wouldn't want that rename to happen.
767 # I think that it is best to simply not have directory rename detection
768 # apply to such cases. My reasoning for this is four-fold: (1) it's
769 # easiest for users in general to figure out what happened if we don't
770 # apply directory rename detection in any such case, (2) it's an easy rule
771 # to explain ["We don't do directory rename detection if the directory
772 # still exists on both sides of the merge"], (3) we can get some hairy
773 # edge/corner cases that would be really confusing and possibly not even
774 # representable in the index if we were to even try, and [related to 3] (4)
775 # attempting to resolve this issue of divining user intent by examining
776 # intermediate history goes against the spirit of three-way merges and is a
777 # path towards crazy corner cases that are far more complex than what we're
778 # already dealing with.
780 # Note that the wording of the rule ("We don't do directory rename
781 # detection if the directory still exists on both sides of the merge.")
782 # also excludes "renaming" of a directory into a subdirectory of itself
783 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
784 # out an exception for "renaming"-beneath-itself cases without opening
785 # weird edge/corner cases for other partial directory renames, but for now
786 # we are keeping the rule simple.
788 # This section contains a test for a partially-renamed-directory case.
789 ###########################################################################
791 # Testcase 4a, Directory split, with original directory still present
792 # (Related to testcase 1f)
793 # Commit O: z/{b,c,d,e}
794 # Commit A: y/{b,c,d}, z/e
795 # Commit B: z/{b,c,d,e,f}
796 # Expected: y/{b,c,d}, z/{e,f}
797 # NOTE: Even though most files from z moved to y, we don't want f to follow.
800 test_create_repo 4a &&
833 test_expect_success '4a: Directory split, with original directory still present' '
840 git -c merge.directoryRenames=true merge -s recursive B^0 &&
842 git ls-files -s >out &&
843 test_line_count = 5 out &&
844 git ls-files -u >out &&
845 test_line_count = 0 out &&
846 git ls-files -o >out &&
847 test_line_count = 1 out &&
849 git rev-parse >actual \
850 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
851 git rev-parse >expect \
852 O:z/b O:z/c O:z/d O:z/e B:z/f &&
853 test_cmp expect actual
857 ###########################################################################
858 # Rules suggested by section 4:
860 # Directory-rename-detection should be turned off for any directories (as
861 # a source for renames) that exist on both sides of the merge. (The "as
862 # a source for renames" clarification is due to cases like 1c where
863 # the target directory exists on both sides and we do want the rename
864 # detection.) But, sadly, see testcase 8b.
865 ###########################################################################
868 ###########################################################################
869 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
871 # Implicitly renaming files due to a detected directory rename could run
872 # into problems if there are files or directories in the way of the paths
873 # we want to rename. Explore such cases in this section.
874 ###########################################################################
876 # Testcase 5a, Merge directories, other side adds files to original and target
877 # Commit O: z/{b,c}, y/d
878 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
879 # Commit B: y/{b,c,d}
880 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
881 # NOTE: While directory rename detection is active here causing z/f to
882 # become y/f, we did not apply this for z/e_1 because that would
883 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
884 # this add/add, is that both versions of y/e are from the same side
885 # of history, giving us no way to represent this conflict in the
889 test_create_repo 5a &&
910 git add z/e z/f y/e &&
923 test_expect_success '5a: Merge directories, other side adds files to original and target' '
930 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
931 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
933 git ls-files -s >out &&
934 test_line_count = 6 out &&
935 git ls-files -u >out &&
936 test_line_count = 0 out &&
937 git ls-files -o >out &&
938 test_line_count = 1 out &&
940 git rev-parse >actual \
941 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
942 git rev-parse >expect \
943 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
944 test_cmp expect actual
948 # Testcase 5b, Rename/delete in order to get add/add/add conflict
949 # (Related to testcase 8d; these may appear slightly inconsistent to users;
950 # Also related to testcases 7d and 7e)
951 # Commit O: z/{b,c,d_1}
952 # Commit A: y/{b,c,d_2}
953 # Commit B: z/{b,c,d_1,e}, y/d_3
954 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
955 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
956 # we normally would since z/ is being renamed to y/, then this would be
957 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
958 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
959 # representable in the index, so the existence of y/d_3 needs to
960 # cause us to bail on directory rename detection for that path, falling
961 # back to git behavior without the directory rename detection.
964 test_create_repo 5b &&
998 test_expect_success '5b: Rename/delete in order to get add/add/add conflict' '
1005 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1006 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1008 git ls-files -s >out &&
1009 test_line_count = 5 out &&
1010 git ls-files -u >out &&
1011 test_line_count = 2 out &&
1012 git ls-files -o >out &&
1013 test_line_count = 1 out &&
1015 git rev-parse >actual \
1016 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1017 git rev-parse >expect \
1018 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1019 test_cmp expect actual &&
1021 test_must_fail git rev-parse :1:y/d &&
1022 test_path_is_file y/d
1026 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1027 # (Directory rename detection would result in transitive rename vs.
1028 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1029 # rename paths conflict with separate adds on the other side)
1030 # (Related to testcases 3b and 7c)
1031 # Commit O: z/{b,c}, x/d_1
1032 # Commit A: y/{b,c,d_2}, w/d_1
1033 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1034 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1035 # presence of y/d_4 in B to avoid doing transitive rename of
1036 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1037 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1038 # though, because it doesn't have anything in the way.
1041 test_create_repo 5c &&
1052 git commit -m "O" &&
1064 git commit -m "A" &&
1073 git add w/ y/ z/e &&
1079 test_expect_success '5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1086 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1087 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1088 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1090 git ls-files -s >out &&
1091 test_line_count = 9 out &&
1092 git ls-files -u >out &&
1093 test_line_count = 6 out &&
1094 git ls-files -o >out &&
1095 test_line_count = 1 out &&
1097 git rev-parse >actual \
1098 :0:y/b :0:y/c :0:y/e &&
1099 git rev-parse >expect \
1100 O:z/b O:z/c B:z/e &&
1101 test_cmp expect actual &&
1103 test_must_fail git rev-parse :1:y/d &&
1104 git rev-parse >actual \
1105 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1106 git rev-parse >expect \
1107 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1108 test_cmp expect actual &&
1110 git hash-object >actual \
1112 git rev-parse >expect \
1114 test_cmp expect actual &&
1115 test_path_is_missing x/d &&
1116 test_path_is_file y/d &&
1117 grep -q "<<<<" y/d # conflict markers should be present
1121 # Testcase 5d, Directory/file/file conflict due to directory rename
1123 # Commit A: y/{b,c,d_1}
1124 # Commit B: z/{b,c,d_2,f}, y/d/e
1125 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1126 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1127 # detection for z/d_2, but that doesn't prevent us from applying the
1128 # directory rename detection for z/f -> y/f.
1131 test_create_repo 5d &&
1140 git commit -m "O" &&
1151 git commit -m "A" &&
1158 git add y/d/e z/d z/f &&
1164 test_expect_success '5d: Directory/file/file conflict due to directory rename' '
1171 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1172 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1174 git ls-files -s >out &&
1175 test_line_count = 6 out &&
1176 git ls-files -u >out &&
1177 test_line_count = 1 out &&
1178 git ls-files -o >out &&
1179 test_line_count = 2 out &&
1181 git rev-parse >actual \
1182 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1183 git rev-parse >expect \
1184 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1185 test_cmp expect actual &&
1187 git hash-object y/d~HEAD >actual &&
1188 git rev-parse A:y/d >expect &&
1189 test_cmp expect actual
1193 ###########################################################################
1194 # Rules suggested by section 5:
1196 # If a subset of to-be-renamed files have a file or directory in the way,
1197 # "turn off" the directory rename for those specific sub-paths, falling
1198 # back to old handling. But, sadly, see testcases 8a and 8b.
1199 ###########################################################################
1202 ###########################################################################
1203 # SECTION 6: Same side of the merge was the one that did the rename
1205 # It may sound obvious that you only want to apply implicit directory
1206 # renames to directories if the _other_ side of history did the renaming.
1207 # If you did make an implementation that didn't explicitly enforce this
1208 # rule, the majority of cases that would fall under this section would
1209 # also be solved by following the rules from the above sections. But
1210 # there are still a few that stick out, so this section covers them just
1211 # to make sure we also get them right.
1212 ###########################################################################
1214 # Testcase 6a, Tricky rename/delete
1215 # Commit O: z/{b,c,d}
1217 # Commit B: y/{b,c}, z/d
1218 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1219 # Note: We're just checking here that the rename of z/b and z/c to put
1220 # them under y/ doesn't accidentally catch z/d and make it look like
1221 # it is also involved in a rename/delete conflict.
1224 test_create_repo 6a &&
1234 git commit -m "O" &&
1244 git commit -m "A" &&
1255 test_expect_success '6a: Tricky rename/delete' '
1262 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1263 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1265 git ls-files -s >out &&
1266 test_line_count = 2 out &&
1267 git ls-files -u >out &&
1268 test_line_count = 1 out &&
1269 git ls-files -o >out &&
1270 test_line_count = 1 out &&
1272 git rev-parse >actual \
1274 git rev-parse >expect \
1276 test_cmp expect actual
1280 # Testcase 6b, Same rename done on both sides
1281 # (Related to testcases 6c and 8e)
1284 # Commit B: y/{b,c}, z/d
1285 # Expected: y/{b,c}, z/d
1286 # Note: If we did directory rename detection here, we'd move z/d into y/,
1287 # but B did that rename and still decided to put the file into z/,
1288 # so we probably shouldn't apply directory rename detection for it.
1291 test_create_repo 6b &&
1300 git commit -m "O" &&
1309 git commit -m "A" &&
1321 test_expect_success '6b: Same rename done on both sides' '
1328 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1330 git ls-files -s >out &&
1331 test_line_count = 3 out &&
1332 git ls-files -u >out &&
1333 test_line_count = 0 out &&
1334 git ls-files -o >out &&
1335 test_line_count = 1 out &&
1337 git rev-parse >actual \
1338 HEAD:y/b HEAD:y/c HEAD:z/d &&
1339 git rev-parse >expect \
1340 O:z/b O:z/c B:z/d &&
1341 test_cmp expect actual
1345 # Testcase 6c, Rename only done on same side
1346 # (Related to testcases 6b and 8e)
1348 # Commit A: z/{b,c} (no change)
1349 # Commit B: y/{b,c}, z/d
1350 # Expected: y/{b,c}, z/d
1351 # NOTE: Seems obvious, but just checking that the implementation doesn't
1352 # "accidentally detect a rename" and give us y/{b,c,d}.
1355 test_create_repo 6c &&
1364 git commit -m "O" &&
1372 git commit --allow-empty -m "A" &&
1384 test_expect_success '6c: Rename only done on same side' '
1391 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1393 git ls-files -s >out &&
1394 test_line_count = 3 out &&
1395 git ls-files -u >out &&
1396 test_line_count = 0 out &&
1397 git ls-files -o >out &&
1398 test_line_count = 1 out &&
1400 git rev-parse >actual \
1401 HEAD:y/b HEAD:y/c HEAD:z/d &&
1402 git rev-parse >expect \
1403 O:z/b O:z/c B:z/d &&
1404 test_cmp expect actual
1408 # Testcase 6d, We don't always want transitive renaming
1409 # (Related to testcase 1c)
1410 # Commit O: z/{b,c}, x/d
1411 # Commit A: z/{b,c}, x/d (no change)
1412 # Commit B: y/{b,c}, z/d
1413 # Expected: y/{b,c}, z/d
1414 # NOTE: Again, this seems obvious but just checking that the implementation
1415 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1418 test_create_repo 6d &&
1429 git commit -m "O" &&
1437 git commit --allow-empty -m "A" &&
1447 test_expect_success '6d: We do not always want transitive renaming' '
1454 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1456 git ls-files -s >out &&
1457 test_line_count = 3 out &&
1458 git ls-files -u >out &&
1459 test_line_count = 0 out &&
1460 git ls-files -o >out &&
1461 test_line_count = 1 out &&
1463 git rev-parse >actual \
1464 HEAD:y/b HEAD:y/c HEAD:z/d &&
1465 git rev-parse >expect \
1466 O:z/b O:z/c O:x/d &&
1467 test_cmp expect actual
1471 # Testcase 6e, Add/add from one-side
1473 # Commit A: z/{b,c} (no change)
1474 # Commit B: y/{b,c,d_1}, z/d_2
1475 # Expected: y/{b,c,d_1}, z/d_2
1476 # NOTE: Again, this seems obvious but just checking that the implementation
1477 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1478 # add/add conflict on y/d_1 vs y/d_2.
1481 test_create_repo 6e &&
1490 git commit -m "O" &&
1498 git commit --allow-empty -m "A" &&
1511 test_expect_success '6e: Add/add from one side' '
1518 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1520 git ls-files -s >out &&
1521 test_line_count = 4 out &&
1522 git ls-files -u >out &&
1523 test_line_count = 0 out &&
1524 git ls-files -o >out &&
1525 test_line_count = 1 out &&
1527 git rev-parse >actual \
1528 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1529 git rev-parse >expect \
1530 O:z/b O:z/c B:y/d B:z/d &&
1531 test_cmp expect actual
1535 ###########################################################################
1536 # Rules suggested by section 6:
1538 # Only apply implicit directory renames to directories if the other
1539 # side of history is the one doing the renaming.
1540 ###########################################################################
1543 ###########################################################################
1544 # SECTION 7: More involved Edge/Corner cases
1546 # The ruleset we have generated in the above sections seems to provide
1547 # well-defined merges. But can we find edge/corner cases that either (a)
1548 # are harder for users to understand, or (b) have a resolution that is
1549 # non-intuitive or suboptimal?
1551 # The testcases in this section dive into cases that I've tried to craft in
1552 # a way to find some that might be surprising to users or difficult for
1553 # them to understand (the next section will look at non-intuitive or
1554 # suboptimal merge results). Some of the testcases are similar to ones
1555 # from past sections, but have been simplified to try to highlight error
1556 # messages using a "modified" path (due to the directory rename). Are
1557 # users okay with these?
1559 # In my opinion, testcases that are difficult to understand from this
1560 # section is due to difficulty in the testcase rather than the directory
1561 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1562 # to the problem setup itself being complex). And I don't think the
1563 # error messages are a problem.
1565 # On the other hand, the testcases in section 8 worry me slightly more...
1566 ###########################################################################
1568 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1571 # Commit B: w/b, x/c, z/d
1572 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1573 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1576 test_create_repo 7a &&
1585 git commit -m "O" &&
1594 git commit -m "A" &&
1608 test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1615 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1616 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1617 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1619 git ls-files -s >out &&
1620 test_line_count = 7 out &&
1621 git ls-files -u >out &&
1622 test_line_count = 6 out &&
1623 git ls-files -o >out &&
1624 test_line_count = 1 out &&
1626 git rev-parse >actual \
1627 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1628 git rev-parse >expect \
1629 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1630 test_cmp expect actual &&
1632 git hash-object >actual \
1634 git rev-parse >expect \
1635 O:z/b O:z/b O:z/c O:z/c &&
1636 test_cmp expect actual
1640 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1641 # (Related to testcase 1d)
1642 # Commit O: z/{b,c}, x/d_1, w/d_2
1643 # Commit A: y/{b,c,d_2}, x/d_1
1644 # Commit B: z/{b,c,d_1}, w/d_2
1645 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1648 test_create_repo 7b &&
1661 git commit -m "O" &&
1671 git commit -m "A" &&
1681 test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' '
1688 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1689 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
1691 git ls-files -s >out &&
1692 test_line_count = 4 out &&
1693 git ls-files -u >out &&
1694 test_line_count = 2 out &&
1695 git ls-files -o >out &&
1696 test_line_count = 1 out &&
1698 git rev-parse >actual \
1699 :0:y/b :0:y/c :2:y/d :3:y/d &&
1700 git rev-parse >expect \
1701 O:z/b O:z/c O:w/d O:x/d &&
1702 test_cmp expect actual &&
1704 # Test that the two-way merge in y/d is as expected
1705 git cat-file -p :2:y/d >expect &&
1706 git cat-file -p :3:y/d >other &&
1708 test_must_fail git merge-file \
1712 expect empty other &&
1717 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1718 # (Related to testcases 3b and 5c)
1719 # Commit O: z/{b,c}, x/d
1720 # Commit A: y/{b,c}, w/d
1721 # Commit B: z/{b,c,d}
1722 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1723 # NOTE: z/ was renamed to y/ so we do want to report
1724 # neither CONFLICT(x/d -> w/d vs. z/d)
1725 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1728 test_create_repo 7c &&
1739 git commit -m "O" &&
1749 git commit -m "A" &&
1759 test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1766 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1767 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1769 git ls-files -s >out &&
1770 test_line_count = 5 out &&
1771 git ls-files -u >out &&
1772 test_line_count = 3 out &&
1773 git ls-files -o >out &&
1774 test_line_count = 1 out &&
1776 git rev-parse >actual \
1777 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1778 git rev-parse >expect \
1779 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1780 test_cmp expect actual
1784 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1785 # (Related somewhat to testcases 5b and 8d)
1786 # Commit O: z/{b,c}, x/d
1788 # Commit B: z/{b,c,d}
1789 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1790 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1793 test_create_repo 7d &&
1804 git commit -m "O" &&
1814 git commit -m "A" &&
1824 test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' '
1831 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1832 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1834 git ls-files -s >out &&
1835 test_line_count = 3 out &&
1836 git ls-files -u >out &&
1837 test_line_count = 1 out &&
1838 git ls-files -o >out &&
1839 test_line_count = 1 out &&
1841 git rev-parse >actual \
1842 :0:y/b :0:y/c :3:y/d &&
1843 git rev-parse >expect \
1844 O:z/b O:z/c O:x/d &&
1845 test_cmp expect actual
1849 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1850 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1851 # (Also related to testcases 9c and 9d)
1852 # Commit O: z/{b,c}, x/d_1
1853 # Commit A: y/{b,c,d/g}, x/d/f
1854 # Commit B: z/{b,c,d_1}
1855 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1856 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1858 # NOTE: The main path of interest here is d_1 and where it ends up, but
1859 # this is actually a case that has two potential directory renames
1860 # involved and D/F conflict(s), so it makes sense to walk through
1863 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1864 # should be instead moved to y/. This gives us the D/F conflict on
1865 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1867 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1868 # should instead be moved to z/...BUT we removed z/ and renamed it
1869 # to y/, so maybe everything should move not from x/ to z/, but
1870 # from x/ to z/ to y/. Doing so might make sense from the logic so
1871 # far, but note that commit A had both an x/ and a y/; it did the
1872 # renaming of z/ to y/ and created x/d/f and it clearly made these
1873 # things separate, so it doesn't make much sense to push these
1874 # together. Doing so is what I'd call a doubly transitive rename;
1875 # see testcases 9c and 9d for further discussion of this issue and
1876 # how it's resolved.
1879 test_create_repo 7e &&
1890 git commit -m "O" &&
1903 git add x/d/f y/d/g &&
1905 git commit -m "A" &&
1915 test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' '
1922 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1923 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1925 git ls-files -s >out &&
1926 test_line_count = 5 out &&
1927 git ls-files -u >out &&
1928 test_line_count = 1 out &&
1929 git ls-files -o >out &&
1930 test_line_count = 2 out &&
1932 git rev-parse >actual \
1933 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
1934 git rev-parse >expect \
1935 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
1936 test_cmp expect actual &&
1938 git hash-object y/d~B^0 >actual &&
1939 git rev-parse O:x/d >expect &&
1940 test_cmp expect actual
1944 ###########################################################################
1945 # SECTION 8: Suboptimal merges
1947 # As alluded to in the last section, the ruleset we have built up for
1948 # detecting directory renames unfortunately has some special cases where it
1949 # results in slightly suboptimal or non-intuitive behavior. This section
1950 # explores these cases.
1952 # To be fair, we already had non-intuitive or suboptimal behavior for most
1953 # of these cases in git before introducing implicit directory rename
1954 # detection, but it'd be nice if there was a modified ruleset out there
1955 # that handled these cases a bit better.
1956 ###########################################################################
1958 # Testcase 8a, Dual-directory rename, one into the others' way
1959 # Commit O. x/{a,b}, y/{c,d}
1960 # Commit A. x/{a,b,e}, y/{c,d,f}
1961 # Commit B. y/{a,b}, z/{c,d}
1963 # Possible Resolutions:
1964 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
1965 # Currently expected: y/{a,b,e,f}, z/{c,d}
1966 # Optimal: y/{a,b,e}, z/{c,d,f}
1968 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
1969 # better with directory rename detection than git did without, but the
1970 # simple rule from section 5 prevents me from handling this as optimally as
1971 # we potentially could.
1974 test_create_repo 8a &&
1986 git commit -m "O" &&
1997 git commit -m "A" &&
2007 test_expect_success '8a: Dual-directory rename, one into the others way' '
2014 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2016 git ls-files -s >out &&
2017 test_line_count = 6 out &&
2018 git ls-files -u >out &&
2019 test_line_count = 0 out &&
2020 git ls-files -o >out &&
2021 test_line_count = 1 out &&
2023 git rev-parse >actual \
2024 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2025 git rev-parse >expect \
2026 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2027 test_cmp expect actual
2031 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2032 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2033 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2034 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2036 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2037 # Currently expected: <same>
2038 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2039 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2041 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2042 # y, both are named 'e'. Without directory rename detection, neither file
2043 # moves directories. Implement directory rename detection suboptimally, and
2044 # you get an add/add conflict, but both files were added in commit A, so this
2045 # is an add/add conflict where one side of history added both files --
2046 # something we can't represent in the index. Obviously, we'd prefer the last
2047 # resolution, but our previous rules are too coarse to allow it. Using both
2048 # the rules from section 4 and section 5 save us from the Scary resolution,
2049 # making us fall back to pre-directory-rename-detection behavior for both
2053 test_create_repo 8b &&
2065 git commit -m "O" &&
2076 git commit -m "A" &&
2086 test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2093 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2095 git ls-files -s >out &&
2096 test_line_count = 6 out &&
2097 git ls-files -u >out &&
2098 test_line_count = 0 out &&
2099 git ls-files -o >out &&
2100 test_line_count = 1 out &&
2102 git rev-parse >actual \
2103 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2104 git rev-parse >expect \
2105 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2106 test_cmp expect actual
2110 # Testcase 8c, modify/delete or rename+modify/delete?
2111 # (Related to testcases 5b, 8d, and 9h)
2112 # Commit O: z/{b,c,d}
2114 # Commit B: z/{b,c,d_modified,e}
2115 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2117 # Note: It could easily be argued that the correct resolution here is
2118 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2119 # and that the modified version of d should be present in y/ after
2120 # the merge, just marked as conflicted. Indeed, I previously did
2121 # argue that. But applying directory renames to the side of
2122 # history where a file is merely modified results in spurious
2123 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2127 test_create_repo 8c &&
2134 test_seq 1 10 >z/d &&
2137 git commit -m "O" &&
2147 git commit -m "A" &&
2151 test_chmod +x z/d &&
2159 test_expect_success '8c: modify/delete or rename+modify/delete' '
2166 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2167 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2169 git ls-files -s >out &&
2170 test_line_count = 5 out &&
2171 git ls-files -u >out &&
2172 test_line_count = 2 out &&
2173 git ls-files -o >out &&
2174 test_line_count = 1 out &&
2176 git rev-parse >actual \
2177 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2178 git rev-parse >expect \
2179 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2180 test_cmp expect actual &&
2182 test_must_fail git rev-parse :2:z/d &&
2183 git ls-files -s z/d | grep ^100755 &&
2184 test_path_is_file z/d &&
2185 test_path_is_missing y/d
2189 # Testcase 8d, rename/delete...or not?
2190 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2191 # Also related to testcases 7d and 7e)
2192 # Commit O: z/{b,c,d}
2194 # Commit B: z/{b,c,d,e}
2195 # Expected: y/{b,c,e}
2197 # Note: It would also be somewhat reasonable to resolve this as
2198 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2200 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2201 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2202 # delete) are both coming from commit A, which is illogical. Conflicts
2203 # during merging are supposed to be about opposite sides doing things
2207 test_create_repo 8d &&
2214 test_seq 1 10 >z/d &&
2217 git commit -m "O" &&
2227 git commit -m "A" &&
2237 test_expect_success '8d: rename/delete...or not?' '
2244 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2246 git ls-files -s >out &&
2247 test_line_count = 3 out &&
2249 git rev-parse >actual \
2250 HEAD:y/b HEAD:y/c HEAD:y/e &&
2251 git rev-parse >expect \
2252 O:z/b O:z/c B:z/e &&
2253 test_cmp expect actual
2257 # Testcase 8e, Both sides rename, one side adds to original directory
2260 # Commit B: w/{b,c}, z/d
2262 # Possible Resolutions:
2263 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2264 # CONFLICT(z/c -> y/c vs. w/c)
2265 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2266 # CONFLICT(z/c -> y/c vs. w/c)
2269 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2270 # did NOT get renamed; the directory is still present; instead it is
2271 # considered to have just renamed a subset of paths in directory z
2272 # elsewhere. However, this is much like testcase 6b (where commit B
2273 # moves all the original paths out of z/ but opted to keep d
2274 # within z/). This makes it hard to judge where d should end up.
2276 # It's possible that users would get confused about this, but what
2277 # should we do instead? It's not at all clear to me whether z/d or
2278 # y/d or something else is a better resolution here, and other cases
2279 # start getting really tricky, so I just picked one.
2282 test_create_repo 8e &&
2291 git commit -m "O" &&
2300 git commit -m "A" &&
2312 test_expect_success '8e: Both sides rename, one side adds to original directory' '
2319 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2320 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2321 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2323 git ls-files -s >out &&
2324 test_line_count = 7 out &&
2325 git ls-files -u >out &&
2326 test_line_count = 6 out &&
2327 git ls-files -o >out &&
2328 test_line_count = 2 out &&
2330 git rev-parse >actual \
2331 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2332 git rev-parse >expect \
2333 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2334 test_cmp expect actual &&
2336 git hash-object >actual \
2338 git rev-parse >expect \
2339 O:z/b O:z/b O:z/c O:z/c &&
2340 test_cmp expect actual &&
2342 test_path_is_missing z/b &&
2343 test_path_is_missing z/c
2347 ###########################################################################
2348 # SECTION 9: Other testcases
2350 # This section consists of miscellaneous testcases I thought of during
2351 # the implementation which round out the testing.
2352 ###########################################################################
2354 # Testcase 9a, Inner renamed directory within outer renamed directory
2355 # (Related to testcase 1f)
2356 # Commit O: z/{b,c,d/{e,f,g}}
2357 # Commit A: y/{b,c}, x/w/{e,f,g}
2358 # Commit B: z/{b,c,d/{e,f,g,h},i}
2359 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2360 # NOTE: The only reason this one is interesting is because when a directory
2361 # is split into multiple other directories, we determine by the weight
2362 # of which one had the most paths going to it. A naive implementation
2363 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2366 test_create_repo 9a &&
2378 git commit -m "O" &&
2389 git commit -m "A" &&
2400 test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2407 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2409 git ls-files -s >out &&
2410 test_line_count = 7 out &&
2411 git ls-files -u >out &&
2412 test_line_count = 0 out &&
2413 git ls-files -o >out &&
2414 test_line_count = 1 out &&
2416 git rev-parse >actual \
2417 HEAD:y/b HEAD:y/c HEAD:y/i &&
2418 git rev-parse >expect \
2419 O:z/b O:z/c B:z/i &&
2420 test_cmp expect actual &&
2422 git rev-parse >actual \
2423 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2424 git rev-parse >expect \
2425 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2426 test_cmp expect actual
2430 # Testcase 9b, Transitive rename with content merge
2431 # (Related to testcase 1c)
2432 # Commit O: z/{b,c}, x/d_1
2433 # Commit A: y/{b,c}, x/d_2
2434 # Commit B: z/{b,c,d_3}
2435 # Expected: y/{b,c,d_merged}
2438 test_create_repo 9b &&
2446 test_seq 1 10 >x/d &&
2449 git commit -m "O" &&
2457 test_seq 1 11 >x/d &&
2460 git commit -m "A" &&
2463 test_seq 0 10 >x/d &&
2471 test_expect_success '9b: Transitive rename with content merge' '
2478 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2480 git ls-files -s >out &&
2481 test_line_count = 3 out &&
2483 test_seq 0 11 >expected &&
2484 test_cmp expected y/d &&
2486 git rev-parse >actual \
2487 HEAD:y/b HEAD:y/c HEAD:y/d &&
2488 git rev-parse >expect \
2489 O:z/b O:z/c :0:expected &&
2490 test_cmp expect actual &&
2491 test_must_fail git rev-parse HEAD:x/d &&
2492 test_must_fail git rev-parse HEAD:z/d &&
2493 test_path_is_missing z/d &&
2495 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2496 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2497 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2501 # Testcase 9c, Doubly transitive rename?
2502 # (Related to testcase 1c, 7e, and 9d)
2503 # Commit O: z/{b,c}, x/{d,e}, w/f
2504 # Commit A: y/{b,c}, x/{d,e,f,g}
2505 # Commit B: z/{b,c,d,e}, w/f
2506 # Expected: y/{b,c,d,e}, x/{f,g}
2508 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2509 # x/f is clear. Let's look beyond that. Here's the logic:
2510 # Commit B renamed x/ -> z/
2511 # Commit A renamed z/ -> y/
2512 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2513 # transient rename. However, where does it end? We can chain these
2514 # indefinitely (see testcase 9d). What if there is a D/F conflict
2515 # at z/f/ or y/f/? Or just another file conflict at one of those
2516 # paths? In the case of an N-long chain of transient renamings,
2517 # where do we "abort" the rename at? Can the user make sense of
2518 # the resulting conflict and resolve it?
2520 # To avoid this confusion I use the simple rule that if the other side
2521 # of history did a directory rename to a path that your side renamed
2522 # away, then ignore that particular rename from the other side of
2523 # history for any implicit directory renames.
2526 test_create_repo 9c &&
2540 git commit -m "O" &&
2552 git commit -m "A" &&
2562 test_expect_success '9c: Doubly transitive rename?' '
2569 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2570 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2572 git ls-files -s >out &&
2573 test_line_count = 6 out &&
2574 git ls-files -o >out &&
2575 test_line_count = 1 out &&
2577 git rev-parse >actual \
2578 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2579 git rev-parse >expect \
2580 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2581 test_cmp expect actual
2585 # Testcase 9d, N-fold transitive rename?
2586 # (Related to testcase 9c...and 1c and 7e)
2587 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2588 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2589 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2590 # Expected: <see NOTE first>
2592 # NOTE: z/ -> y/ (in commit A)
2593 # y/ -> x/ (in commit B)
2594 # x/ -> w/ (in commit A)
2595 # w/ -> v/ (in commit B)
2596 # v/ -> u/ (in commit A)
2597 # So, if we add a file to z, say z/t, where should it end up? In u?
2598 # What if there's another file or directory named 't' in one of the
2599 # intervening directories and/or in u itself? Also, shouldn't the
2600 # same logic that places 't' in u/ also move ALL other files to u/?
2601 # What if there are file or directory conflicts in any of them? If
2602 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2603 # like this, would the user have any hope of understanding any
2604 # conflicts or how their working tree ended up? I think not, so I'm
2605 # ruling out N-ary transitive renames for N>1.
2607 # Therefore our expected result is:
2608 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2609 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2610 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2611 # simple rules that are consistent with what we need for all the other
2612 # testcases and simplifies things for the user.
2615 test_create_repo 9d &&
2619 mkdir z y x w v u &&
2626 git add z y x w v u &&
2628 git commit -m "O" &&
2639 git commit -m "A" &&
2651 test_expect_success '9d: N-way transitive rename?' '
2658 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2659 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2660 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2661 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2662 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2664 git ls-files -s >out &&
2665 test_line_count = 7 out &&
2666 git ls-files -o >out &&
2667 test_line_count = 1 out &&
2669 git rev-parse >actual \
2671 HEAD:y/a HEAD:x/b HEAD:w/c \
2672 HEAD:u/d HEAD:u/e HEAD:u/f &&
2673 git rev-parse >expect \
2676 O:w/d O:v/e A:u/f &&
2677 test_cmp expect actual
2681 # Testcase 9e, N-to-1 whammo
2682 # (Related to testcase 9c...and 1c and 7e)
2683 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2684 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2685 # Commit B: combined/{a,b,d,e,g,h,j,k}
2686 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2687 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2690 test_create_repo 9e &&
2694 mkdir dir1 dir2 dir3 dirN &&
2705 git commit -m "O" &&
2722 git commit -m "A" &&
2725 git mv dir1 combined &&
2726 git mv dir2/* combined/ &&
2727 git mv dir3/* combined/ &&
2728 git mv dirN/* combined/ &&
2734 test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' '
2741 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2742 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2743 grep -q dir1/yo error_line &&
2744 grep -q dir2/yo error_line &&
2745 grep -q dir3/yo error_line &&
2746 grep -q dirN/yo error_line &&
2748 git ls-files -s >out &&
2749 test_line_count = 16 out &&
2750 git ls-files -u >out &&
2751 test_line_count = 0 out &&
2752 git ls-files -o >out &&
2753 test_line_count = 2 out &&
2755 git rev-parse >actual \
2756 :0:combined/a :0:combined/b :0:combined/c \
2757 :0:combined/d :0:combined/e :0:combined/f \
2758 :0:combined/g :0:combined/h :0:combined/i \
2759 :0:combined/j :0:combined/k :0:combined/l &&
2760 git rev-parse >expect \
2761 O:dir1/a O:dir1/b A:dir1/c \
2762 O:dir2/d O:dir2/e A:dir2/f \
2763 O:dir3/g O:dir3/h A:dir3/i \
2764 O:dirN/j O:dirN/k A:dirN/l &&
2765 test_cmp expect actual &&
2767 git rev-parse >actual \
2768 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2769 git rev-parse >expect \
2770 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2771 test_cmp expect actual
2775 # Testcase 9f, Renamed directory that only contained immediate subdirs
2776 # (Related to testcases 1e & 9g)
2777 # Commit O: goal/{a,b}/$more_files
2778 # Commit A: priority/{a,b}/$more_files
2779 # Commit B: goal/{a,b}/$more_files, goal/c
2780 # Expected: priority/{a,b}/$more_files, priority/c
2783 test_create_repo 9f &&
2789 echo foo >goal/a/foo &&
2790 echo bar >goal/b/bar &&
2791 echo baz >goal/b/baz &&
2794 git commit -m "O" &&
2801 git mv goal/ priority &&
2803 git commit -m "A" &&
2813 test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2820 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2822 git ls-files -s >out &&
2823 test_line_count = 4 out &&
2825 git rev-parse >actual \
2826 HEAD:priority/a/foo \
2827 HEAD:priority/b/bar \
2828 HEAD:priority/b/baz \
2830 git rev-parse >expect \
2835 test_cmp expect actual &&
2836 test_must_fail git rev-parse HEAD:goal/c
2840 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2841 # (Related to testcases 1e & 9f)
2842 # Commit O: goal/{a,b}/$more_files
2843 # Commit A: priority/{alpha,bravo}/$more_files
2844 # Commit B: goal/{a,b}/$more_files, goal/c
2845 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2846 # We currently fail this test because the directory renames we detect are
2847 # goal/a/ -> priority/alpha/
2848 # goal/b/ -> priority/bravo/
2850 # goal/ -> priority/
2851 # because of no files found within goal/, and the fact that "a" != "alpha"
2852 # and "b" != "bravo". But I'm not sure it's really a failure given that
2856 test_create_repo 9g &&
2862 echo foo >goal/a/foo &&
2863 echo bar >goal/b/bar &&
2864 echo baz >goal/b/baz &&
2867 git commit -m "O" &&
2875 git mv goal/a/ priority/alpha &&
2876 git mv goal/b/ priority/beta &&
2879 git commit -m "A" &&
2889 test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2896 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2898 git ls-files -s >out &&
2899 test_line_count = 4 out &&
2901 git rev-parse >actual \
2902 HEAD:priority/alpha/foo \
2903 HEAD:priority/beta/bar \
2904 HEAD:priority/beta/baz \
2906 git rev-parse >expect \
2911 test_cmp expect actual &&
2912 test_must_fail git rev-parse HEAD:goal/c
2916 # Testcase 9h, Avoid implicit rename if involved as source on other side
2917 # (Extremely closely related to testcase 3a)
2918 # Commit O: z/{b,c,d_1}
2919 # Commit A: z/{b,c,d_2}
2920 # Commit B: y/{b,c}, x/d_1
2921 # Expected: y/{b,c}, x/d_2
2922 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2923 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
2925 test_create_repo 9h &&
2932 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2935 git commit -m "O" &&
2945 git commit -m "A" &&
2959 test_expect_success '9h: Avoid dir rename on merely modified path' '
2966 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2968 git ls-files -s >out &&
2969 test_line_count = 3 out &&
2971 git rev-parse >actual \
2972 HEAD:y/b HEAD:y/c HEAD:x/d &&
2973 git rev-parse >expect \
2974 O:z/b O:z/c A:z/d &&
2975 test_cmp expect actual
2979 ###########################################################################
2980 # Rules suggested by section 9:
2982 # If the other side of history did a directory rename to a path that your
2983 # side renamed away, then ignore that particular rename from the other
2984 # side of history for any implicit directory renames.
2985 ###########################################################################
2987 ###########################################################################
2988 # SECTION 10: Handling untracked files
2990 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
2991 # the operation if untracked or dirty files would be deleted or overwritten
2992 # by the merge. Unfortunately, unpack_trees() does not understand renames,
2993 # and if it doesn't abort, then it muddies up the working directory before
2994 # we even get to the point of detecting renames, so we need some special
2995 # handling, at least in the case of directory renames.
2996 ###########################################################################
2998 # Testcase 10a, Overwrite untracked: normal rename/delete
2999 # Commit O: z/{b,c_1}
3000 # Commit A: z/b + untracked z/c + untracked z/d
3001 # Commit B: z/{b,d_1}
3002 # Expected: Aborted Merge +
3003 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3006 test_create_repo 10a &&
3015 git commit -m "O" &&
3024 git commit -m "A" &&
3033 test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3040 echo important >z/d &&
3042 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3043 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3045 git ls-files -s >out &&
3046 test_line_count = 1 out &&
3047 git ls-files -o >out &&
3048 test_line_count = 4 out &&
3050 echo very >expect &&
3051 test_cmp expect z/c &&
3053 echo important >expect &&
3054 test_cmp expect z/d &&
3056 git rev-parse HEAD:z/b >actual &&
3057 git rev-parse O:z/b >expect &&
3058 test_cmp expect actual
3062 # Testcase 10b, Overwrite untracked: dir rename + delete
3063 # Commit O: z/{b,c_1}
3064 # Commit A: y/b + untracked y/{c,d,e}
3065 # Commit B: z/{b,d_1,e}
3066 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3067 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3068 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3071 test_create_repo 10b &&
3080 git commit -m "O" &&
3090 git commit -m "A" &&
3101 test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3108 echo important >y/d &&
3109 echo contents >y/e &&
3111 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3112 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3113 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3115 git ls-files -s >out &&
3116 test_line_count = 3 out &&
3117 git ls-files -u >out &&
3118 test_line_count = 2 out &&
3119 git ls-files -o >out &&
3120 test_line_count = 5 out &&
3122 git rev-parse >actual \
3123 :0:y/b :3:y/d :3:y/e &&
3124 git rev-parse >expect \
3125 O:z/b O:z/c B:z/e &&
3126 test_cmp expect actual &&
3128 echo very >expect &&
3129 test_cmp expect y/c &&
3131 echo important >expect &&
3132 test_cmp expect y/d &&
3134 echo contents >expect &&
3139 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3140 # Commit O: z/{a,b}, x/{c,d}
3141 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3142 # Commit B: z/{a,b,c}, x/d
3143 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3144 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3146 # ERROR_MSG(Refusing to lose untracked file at y/c)
3149 test_create_repo 10c_$1 &&
3160 git commit -m "O" &&
3171 git commit -m "A" &&
3180 test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3186 echo important >y/c &&
3188 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3189 test_i18ngrep "CONFLICT (rename/rename)" out &&
3190 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3192 git ls-files -s >out &&
3193 test_line_count = 6 out &&
3194 git ls-files -u >out &&
3195 test_line_count = 3 out &&
3196 git ls-files -o >out &&
3197 test_line_count = 3 out &&
3199 git rev-parse >actual \
3200 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3201 git rev-parse >expect \
3202 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3203 test_cmp expect actual &&
3205 git hash-object y/c~B^0 >actual &&
3206 git rev-parse O:x/c >expect &&
3207 test_cmp expect actual &&
3209 echo important >expect &&
3214 test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3224 echo important >y/c &&
3226 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3227 test_i18ngrep "CONFLICT (rename/rename)" out &&
3228 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3230 git ls-files -s >out &&
3231 test_line_count = 6 out &&
3232 git ls-files -u >out &&
3233 test_line_count = 3 out &&
3234 git ls-files -o >out &&
3235 test_line_count = 3 out &&
3237 git rev-parse >actual \
3238 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3239 git rev-parse >expect \
3240 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3241 test_cmp expect actual &&
3243 git hash-object y/c~HEAD >actual &&
3244 git rev-parse O:x/c >expect &&
3245 test_cmp expect actual &&
3247 echo important >expect &&
3252 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3253 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3254 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3255 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3256 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3257 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3258 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3261 test_create_repo 10d &&
3274 git commit -m "O" &&
3281 git mv z/c x/wham &&
3284 git commit -m "A" &&
3287 git mv x/f z/wham &&
3294 test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3300 echo important >y/wham &&
3302 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3303 test_i18ngrep "CONFLICT (rename/rename)" out &&
3304 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3306 git ls-files -s >out &&
3307 test_line_count = 6 out &&
3308 git ls-files -u >out &&
3309 test_line_count = 2 out &&
3310 git ls-files -o >out &&
3311 test_line_count = 3 out &&
3313 git rev-parse >actual \
3314 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3315 git rev-parse >expect \
3316 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3317 test_cmp expect actual &&
3319 test_must_fail git rev-parse :1:y/wham &&
3321 echo important >expect &&
3322 test_cmp expect y/wham &&
3324 # Test that the two-way merge in y/wham~merged is as expected
3325 git cat-file -p :2:y/wham >expect &&
3326 git cat-file -p :3:y/wham >other &&
3328 test_must_fail git merge-file \
3332 expect empty other &&
3333 test_cmp expect y/wham~merged
3337 # Testcase 10e, Does git complain about untracked file that's not in the way?
3339 # Commit A: y/{a,b} + untracked z/c
3340 # Commit B: z/{a,b,c}
3341 # Expected: y/{a,b,c} + untracked z/c
3344 test_create_repo 10e &&
3353 git commit -m "O" &&
3362 git commit -m "A" &&
3372 test_expect_failure '10e: Does git complain about untracked file that is not really in the way?' '
3381 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3382 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3384 git ls-files -s >out &&
3385 test_line_count = 3 out &&
3386 git ls-files -u >out &&
3387 test_line_count = 0 out &&
3388 git ls-files -o >out &&
3389 test_line_count = 3 out &&
3391 git rev-parse >actual \
3392 :0:y/a :0:y/b :0:y/c &&
3393 git rev-parse >expect \
3394 O:z/a O:z/b B:z/c &&
3395 test_cmp expect actual &&
3397 echo random >expect &&
3402 ###########################################################################
3403 # SECTION 11: Handling dirty (not up-to-date) files
3405 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3406 # the operation if untracked or dirty files would be deleted or overwritten
3407 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3408 # and if it doesn't abort, then it muddies up the working directory before
3409 # we even get to the point of detecting renames, so we need some special
3410 # handling. This was true even of normal renames, but there are additional
3411 # codepaths that need special handling with directory renames. Add
3412 # testcases for both renamed-by-directory-rename-detection and standard
3414 ###########################################################################
3416 # Testcase 11a, Avoid losing dirty contents with simple rename
3417 # Commit O: z/{a,b_v1},
3418 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3419 # Commit B: z/{a,b_v2}
3420 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3421 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3422 # z/c~HEAD with contents of B:z/b_v2,
3423 # z/c with uncommitted mods on top of A:z/c_v1
3426 test_create_repo 11a &&
3432 test_seq 1 10 >z/b &&
3435 git commit -m "O" &&
3444 git commit -m "A" &&
3454 test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3462 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3463 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3465 test_seq 1 10 >expected &&
3466 echo stuff >>expected &&
3467 test_cmp expected z/c &&
3469 git ls-files -s >out &&
3470 test_line_count = 2 out &&
3471 git ls-files -u >out &&
3472 test_line_count = 1 out &&
3473 git ls-files -o >out &&
3474 test_line_count = 4 out &&
3476 git rev-parse >actual \
3478 git rev-parse >expect \
3480 test_cmp expect actual &&
3482 git hash-object z/c~HEAD >actual &&
3483 git rev-parse B:z/b >expect &&
3484 test_cmp expect actual
3488 # Testcase 11b, Avoid losing dirty file involved in directory rename
3489 # Commit O: z/a, x/{b,c_v1}
3490 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3491 # Commit B: y/a, x/{b,c_v2}
3492 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3493 # ERROR_MSG(Refusing to lose dirty file at z/c)
3497 test_create_repo 11b &&
3504 test_seq 1 10 >x/c &&
3507 git commit -m "O" &&
3516 git commit -m "A" &&
3527 test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3535 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3536 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3538 grep -q stuff z/c &&
3539 test_seq 1 10 >expected &&
3540 echo stuff >>expected &&
3541 test_cmp expected z/c &&
3543 git ls-files -s >out &&
3544 test_line_count = 3 out &&
3545 git ls-files -u >out &&
3546 test_line_count = 0 out &&
3547 git ls-files -m >out &&
3548 test_line_count = 0 out &&
3549 git ls-files -o >out &&
3550 test_line_count = 4 out &&
3552 git rev-parse >actual \
3553 :0:x/b :0:y/a :0:y/c &&
3554 git rev-parse >expect \
3555 O:x/b O:z/a B:x/c &&
3556 test_cmp expect actual &&
3558 git hash-object y/c >actual &&
3559 git rev-parse B:x/c >expect &&
3560 test_cmp expect actual
3564 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3565 # Commit O: y/a, x/{b,c_v1}
3566 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3567 # Commit B: y/{a,c/d}, x/{b,c_v2}
3568 # Expected: Abort_msg("following files would be overwritten by merge") +
3569 # y/c left untouched (still has uncommitted mods)
3572 test_create_repo 11c &&
3579 test_seq 1 10 >x/c &&
3582 git commit -m "O" &&
3591 git commit -m "A" &&
3597 git add x/c y/c/d &&
3603 test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3611 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3612 test_i18ngrep "following files would be overwritten by merge" err &&
3614 grep -q stuff y/c &&
3615 test_seq 1 10 >expected &&
3616 echo stuff >>expected &&
3617 test_cmp expected y/c &&
3619 git ls-files -s >out &&
3620 test_line_count = 3 out &&
3621 git ls-files -u >out &&
3622 test_line_count = 0 out &&
3623 git ls-files -m >out &&
3624 test_line_count = 1 out &&
3625 git ls-files -o >out &&
3626 test_line_count = 3 out
3630 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3631 # Commit O: z/a, x/{b,c_v1}
3632 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3633 # Commit B: y/{a,c/d}, x/{b,c_v2}
3634 # Expected: D/F: y/c_v2 vs y/c/d) +
3635 # Warning_Msg("Refusing to lose dirty file at z/c) +
3636 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3639 test_create_repo 11d &&
3646 test_seq 1 10 >x/c &&
3649 git commit -m "O" &&
3658 git commit -m "A" &&
3665 git add x/c y/c/d &&
3671 test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3679 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3680 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3682 grep -q stuff z/c &&
3683 test_seq 1 10 >expected &&
3684 echo stuff >>expected &&
3685 test_cmp expected z/c &&
3687 git ls-files -s >out &&
3688 test_line_count = 4 out &&
3689 git ls-files -u >out &&
3690 test_line_count = 1 out &&
3691 git ls-files -o >out &&
3692 test_line_count = 5 out &&
3694 git rev-parse >actual \
3695 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3696 git rev-parse >expect \
3697 O:x/b O:z/a B:y/c/d B:x/c &&
3698 test_cmp expect actual &&
3700 git hash-object y/c~HEAD >actual &&
3701 git rev-parse B:x/c >expect &&
3702 test_cmp expect actual
3706 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3707 # Commit O: z/{a,b}, x/{c_1,d}
3708 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3709 # Commit B: z/{a,b,c_1}, x/d
3710 # Expected: Failed Merge; y/{a,b} + x/d +
3711 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3712 # ERROR_MSG(Refusing to lose dirty file at y/c)
3713 # y/c~B^0 has O:x/c_1 contents
3714 # y/c~HEAD has A:y/c_2 contents
3715 # y/c has dirty file from before merge
3718 test_create_repo 11e &&
3729 git commit -m "O" &&
3737 echo different >y/c &&
3742 git commit -m "A" &&
3751 test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3759 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3760 test_i18ngrep "CONFLICT (rename/rename)" out &&
3761 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3763 git ls-files -s >out &&
3764 test_line_count = 7 out &&
3765 git ls-files -u >out &&
3766 test_line_count = 4 out &&
3767 git ls-files -o >out &&
3768 test_line_count = 3 out &&
3770 echo different >expected &&
3771 echo mods >>expected &&
3772 test_cmp expected y/c &&
3774 git rev-parse >actual \
3775 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3776 git rev-parse >expect \
3777 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3778 test_cmp expect actual &&
3780 # See if y/c~merged has expected contents; requires manually
3781 # doing the expected file merge
3782 git cat-file -p A:y/c >c1 &&
3783 git cat-file -p B:z/c >c2 &&
3785 test_must_fail git merge-file \
3790 test_cmp c1 y/c~merged
3794 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3795 # Commit O: z/{a,b}, x/{c_1,d_2}
3796 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3797 # Commit B: z/{a,b,wham_2}, x/c_1
3798 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3799 # y/wham with dirty changes from before merge +
3800 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3801 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3804 test_create_repo 11f &&
3811 test_seq 1 10 >x/c &&
3815 git commit -m "O" &&
3823 git mv x/c y/wham &&
3825 git commit -m "A" &&
3828 git mv x/d z/wham &&
3834 test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3840 echo important >>y/wham &&
3842 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3843 test_i18ngrep "CONFLICT (rename/rename)" out &&
3844 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3846 git ls-files -s >out &&
3847 test_line_count = 4 out &&
3848 git ls-files -u >out &&
3849 test_line_count = 2 out &&
3850 git ls-files -o >out &&
3851 test_line_count = 3 out &&
3853 test_seq 1 10 >expected &&
3854 echo important >>expected &&
3855 test_cmp expected y/wham &&
3857 test_must_fail git rev-parse :1:y/wham &&
3859 git rev-parse >actual \
3860 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3861 git rev-parse >expect \
3862 O:z/a O:z/b O:x/c O:x/d &&
3863 test_cmp expect actual &&
3865 # Test that the two-way merge in y/wham~merged is as expected
3866 git cat-file -p :2:y/wham >expect &&
3867 git cat-file -p :3:y/wham >other &&
3869 test_must_fail git merge-file \
3873 expect empty other &&
3874 test_cmp expect y/wham~merged
3878 ###########################################################################
3879 # SECTION 12: Everything else
3881 # Tests suggested by others. Tests added after implementation completed
3882 # and submitted. Grab bag.
3883 ###########################################################################
3885 # Testcase 12a, Moving one directory hierarchy into another
3886 # (Related to testcase 9a)
3887 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3888 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3889 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3890 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3893 test_create_repo 12a &&
3897 mkdir -p node1 node2 &&
3898 echo leaf1 >node1/leaf1 &&
3899 echo leaf2 >node1/leaf2 &&
3900 echo leaf3 >node2/leaf3 &&
3901 echo leaf4 >node2/leaf4 &&
3902 git add node1 node2 &&
3904 git commit -m "O" &&
3911 git mv node2/ node1/ &&
3913 git commit -m "A" &&
3916 echo leaf5 >node1/leaf5 &&
3917 echo leaf6 >node2/leaf6 &&
3918 git add node1 node2 &&
3924 test_expect_success '12a: Moving one directory hierarchy into another' '
3931 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3933 git ls-files -s >out &&
3934 test_line_count = 6 out &&
3936 git rev-parse >actual \
3937 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3938 HEAD:node1/node2/leaf3 \
3939 HEAD:node1/node2/leaf4 \
3940 HEAD:node1/node2/leaf6 &&
3941 git rev-parse >expect \
3942 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3946 test_cmp expect actual
3950 # Testcase 12b, Moving two directory hierarchies into each other
3951 # (Related to testcases 1c and 12c)
3952 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3953 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3954 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3955 # Expected: node1/node2/node1/{leaf1, leaf2},
3956 # node2/node1/node2/{leaf3, leaf4}
3957 # NOTE: Without directory renames, we would expect
3958 # node2/node1/{leaf1, leaf2},
3959 # node1/node2/{leaf3, leaf4}
3960 # with directory rename detection, we note that
3961 # commit A renames node2/ -> node1/node2/
3962 # commit B renames node1/ -> node2/node1/
3963 # therefore, applying those directory renames to the initial result
3964 # (making all four paths experience a transitive renaming), yields
3965 # the expected result.
3967 # You may ask, is it weird to have two directories rename each other?
3968 # To which, I can do no more than shrug my shoulders and say that
3969 # even simple rules give weird results when given weird inputs.
3972 test_create_repo 12b &&
3976 mkdir -p node1 node2 &&
3977 echo leaf1 >node1/leaf1 &&
3978 echo leaf2 >node1/leaf2 &&
3979 echo leaf3 >node2/leaf3 &&
3980 echo leaf4 >node2/leaf4 &&
3981 git add node1 node2 &&
3983 git commit -m "O" &&
3990 git mv node2/ node1/ &&
3992 git commit -m "A" &&
3995 git mv node1/ node2/ &&
4001 test_expect_success '12b: Moving two directory hierarchies into each other' '
4008 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4010 git ls-files -s >out &&
4011 test_line_count = 4 out &&
4013 git rev-parse >actual \
4014 HEAD:node1/node2/node1/leaf1 \
4015 HEAD:node1/node2/node1/leaf2 \
4016 HEAD:node2/node1/node2/leaf3 \
4017 HEAD:node2/node1/node2/leaf4 &&
4018 git rev-parse >expect \
4023 test_cmp expect actual
4027 # Testcase 12c, Moving two directory hierarchies into each other w/ content merge
4028 # (Related to testcase 12b)
4029 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4030 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4031 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4032 # Expected: Content merge conflicts for each of:
4033 # node1/node2/node1/{leaf1, leaf2},
4034 # node2/node1/node2/{leaf3, leaf4}
4035 # NOTE: This is *exactly* like 12c, except that every path is modified on
4036 # each side of the merge.
4039 test_create_repo 12c &&
4043 mkdir -p node1 node2 &&
4044 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4045 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4046 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4047 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4048 git add node1 node2 &&
4050 git commit -m "O" &&
4057 git mv node2/ node1/ &&
4058 for i in `git ls-files`; do echo side A >>$i; done &&
4061 git commit -m "A" &&
4064 git mv node1/ node2/ &&
4065 for i in `git ls-files`; do echo side B >>$i; done &&
4072 test_expect_success '12c: Moving one directory hierarchy into another w/ content merge' '
4079 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4081 git ls-files -u >out &&
4082 test_line_count = 12 out &&
4084 git rev-parse >actual \
4085 :1:node1/node2/node1/leaf1 \
4086 :1:node1/node2/node1/leaf2 \
4087 :1:node2/node1/node2/leaf3 \
4088 :1:node2/node1/node2/leaf4 \
4089 :2:node1/node2/node1/leaf1 \
4090 :2:node1/node2/node1/leaf2 \
4091 :2:node2/node1/node2/leaf3 \
4092 :2:node2/node1/node2/leaf4 \
4093 :3:node1/node2/node1/leaf1 \
4094 :3:node1/node2/node1/leaf2 \
4095 :3:node2/node1/node2/leaf3 \
4096 :3:node2/node1/node2/leaf4 &&
4097 git rev-parse >expect \
4104 A:node1/node2/leaf3 \
4105 A:node1/node2/leaf4 \
4106 B:node2/node1/leaf1 \
4107 B:node2/node1/leaf2 \
4110 test_cmp expect actual
4114 # Testcase 12d, Rename/merge of subdirectory into the root
4115 # Commit O: a/b/subdir/foo
4116 # Commit A: subdir/foo
4117 # Commit B: a/b/subdir/foo, a/b/bar
4118 # Expected: subdir/foo, bar
4121 test_create_repo 12d &&
4125 mkdir -p a/b/subdir &&
4126 test_commit a/b/subdir/foo &&
4134 git mv a/b/subdir/foo.t subdir/foo.t &&
4136 git commit -m "A" &&
4143 test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4150 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4152 git ls-files -s >out &&
4153 test_line_count = 2 out &&
4155 git rev-parse >actual \
4156 HEAD:subdir/foo.t HEAD:bar.t &&
4157 git rev-parse >expect \
4158 O:a/b/subdir/foo.t B:a/b/bar.t &&
4159 test_cmp expect actual &&
4161 git hash-object bar.t >actual &&
4162 git rev-parse B:a/b/bar.t >expect &&
4163 test_cmp expect actual &&
4165 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4166 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4167 test_path_is_missing a/ &&
4168 test_path_is_file bar.t
4172 # Testcase 12e, Rename/merge of subdirectory into the root
4175 # Commit B: a/b/foo, a/b/bar
4176 # Expected: foo, bar
4179 test_create_repo 12e &&
4184 test_commit a/b/foo &&
4192 git mv a/b/foo.t foo.t &&
4194 git commit -m "A" &&
4201 test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4208 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4210 git ls-files -s >out &&
4211 test_line_count = 2 out &&
4213 git rev-parse >actual \
4214 HEAD:foo.t HEAD:bar.t &&
4215 git rev-parse >expect \
4216 O:a/b/foo.t B:a/b/bar.t &&
4217 test_cmp expect actual &&
4219 git hash-object bar.t >actual &&
4220 git rev-parse B:a/b/bar.t >expect &&
4221 test_cmp expect actual &&
4223 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4224 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4225 test_path_is_missing a/ &&
4226 test_path_is_file bar.t
4230 ###########################################################################
4231 # SECTION 13: Checking informational and conflict messages
4233 # A year after directory rename detection became the default, it was
4234 # instead decided to report conflicts on the pathname on the basis that
4235 # some users may expect the new files added or moved into a directory to
4236 # be unrelated to all the other files in that directory, and thus that
4237 # directory rename detection is unexpected. Test that the messages printed
4238 # match our expectation.
4239 ###########################################################################
4241 # Testcase 13a, Basic directory rename with newly added files
4244 # Commit B: z/{b,c,d,e/f}
4245 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4248 test_create_repo 13a_$1 &&
4257 git commit -m "O" &&
4266 git commit -m "A" &&
4272 git add z/d z/e/f &&
4278 test_expect_success '13a(conflict): messages for newly added files' '
4279 test_setup_13a conflict &&
4285 test_must_fail git merge -s recursive B^0 >out 2>err &&
4287 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4288 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4290 git ls-files >paths &&
4292 grep "y/[de]" paths &&
4294 test_path_is_missing z/d &&
4295 test_path_is_file y/d &&
4296 test_path_is_missing z/e/f &&
4297 test_path_is_file y/e/f
4301 test_expect_success '13a(info): messages for newly added files' '
4302 test_setup_13a info &&
4309 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4311 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4312 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4314 git ls-files >paths &&
4316 grep "y/[de]" paths &&
4318 test_path_is_missing z/d &&
4319 test_path_is_file y/d &&
4320 test_path_is_missing z/e/f &&
4321 test_path_is_file y/e/f
4325 # Testcase 13b, Transitive rename with conflicted content merge and default
4326 # "conflict" setting
4327 # (Related to testcase 1c, 9b)
4328 # Commit O: z/{b,c}, x/d_1
4329 # Commit A: y/{b,c}, x/d_2
4330 # Commit B: z/{b,c,d_3}
4331 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4332 # one about content, and one about file location
4335 test_create_repo 13b_$1 &&
4341 test_seq 1 10 >x/d &&
4346 git commit -m "O" &&
4357 git commit -m "A" &&
4360 echo eleven >>x/d &&
4368 test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
4369 test_setup_13b conflict &&
4375 test_must_fail git merge -s recursive B^0 >out 2>err &&
4377 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4378 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4380 git ls-files >paths &&
4384 test_path_is_missing z/d &&
4385 test_path_is_file y/d
4389 test_expect_success '13b(info): messages for transitive rename with conflicted content' '
4390 test_setup_13b info &&
4397 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4399 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4400 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4402 git ls-files >paths &&
4406 test_path_is_missing z/d &&
4407 test_path_is_file y/d
4411 # Testcase 13c, Rename/rename(1to1) due to directory rename
4412 # Commit O: z/{b,c}, x/{d,e}
4413 # Commit A: y/{b,c,d}, x/e
4414 # Commit B: z/{b,c,d}, x/e
4415 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
4416 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4417 # One could argue A had partial knowledge of what was done with
4418 # d and B had full knowledge, but that's a slippery slope as
4419 # shown in testcase 13d.
4422 test_create_repo 13c_$1 &&
4428 test_seq 1 10 >x/d &&
4434 git commit -m "O" &&
4444 git commit -m "A" &&
4454 test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
4455 test_setup_13c conflict &&
4461 test_must_fail git merge -s recursive B^0 >out 2>err &&
4463 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4465 git ls-files >paths &&
4469 test_path_is_missing z/d &&
4470 test_path_is_file y/d
4474 test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
4475 test_setup_13c info &&
4482 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4484 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4486 git ls-files >paths &&
4490 test_path_is_missing z/d &&
4491 test_path_is_file y/d
4495 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4496 # Commit O: a/{z,y}, b/x, c/w
4497 # Commit A: a/z, b/{y,x}, d/w
4498 # Commit B: a/z, d/x, c/{y,w}
4499 # Expected: a/z, d/{y,x,w} with no file location conflict for x
4501 # * z is always in a; so it stays in a.
4502 # * x starts in b, only modified on one side to move into d/
4503 # * w starts in c, only modified on one side to move into d/
4505 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
4506 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
4507 # No conflict in where a/y ends up, so put it in d/y.
4510 test_create_repo 13d_$1 &&
4523 git commit -m "O" &&
4533 git commit -m "A" &&
4543 test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
4544 test_setup_13d conflict &&
4550 test_must_fail git merge -s recursive B^0 >out 2>err &&
4552 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
4553 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
4555 git ls-files >paths &&
4560 test_path_is_missing b/y &&
4561 test_path_is_missing c/y &&
4562 test_path_is_file d/y
4566 test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
4567 test_setup_13d info &&
4574 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4576 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
4577 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
4579 git ls-files >paths &&
4584 test_path_is_missing b/y &&
4585 test_path_is_missing c/y &&
4586 test_path_is_file d/y
4590 # Testcase 13e, directory rename in virtual merge base
4592 # This testcase has a slightly different setup than all the above cases, in
4593 # order to include a recursive case:
4605 # Commit B: a/{z,y,x}
4606 # Commit C: b/{z,y,x}
4607 # Commit D: b/{z,y}, a/x
4608 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
4610 # NOTES: 'X' represents a virtual merge base. With the default of
4611 # directory rename detection yielding conflicts, merging A and B
4612 # results in a conflict complaining about whether 'x' should be
4613 # under 'a/' or 'b/'. However, when creating the virtual merge
4614 # base 'X', since virtual merge bases need to be written out as a
4615 # tree, we cannot have a conflict, so some resolution has to be
4618 # In choosing the right resolution, it's worth noting here that
4619 # commits C & D are merges of A & B that choose different
4620 # locations for 'x' (i.e. they resolve the conflict differently),
4621 # and so it would be nice when merging C & D if git could detect
4622 # this difference of opinion and report a conflict. But the only
4623 # way to do so that I can think of would be to have the virtual
4624 # merge base place 'x' in some directory other than either 'a/' or
4625 # 'b/', which seems a little weird -- especially since it'd result
4626 # in a rename/rename(1to2) conflict with a source path that never
4627 # existed in any version.
4629 # So, for now, when directory rename detection is set to
4630 # 'conflict' just avoid doing directory rename detection at all in
4631 # the recursive case. This will not allow us to detect a conflict
4632 # in the outer merge for this special kind of setup, but it at
4633 # least avoids hitting a BUG().
4636 test_create_repo 13e &&
4645 git commit -m "O" &&
4654 git commit -m "A" &&
4660 git commit -m "B" &&
4666 test_must_fail git -c merge.directoryRenames=conflict merge B &&
4669 git commit -m "C" &&
4673 test_must_fail git -c merge.directoryRenames=conflict merge A &&
4682 test_expect_success '13e: directory rename detection in recursive case' '
4687 git checkout --quiet D^0 &&
4689 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
4691 test_i18ngrep ! CONFLICT out &&
4692 test_i18ngrep ! BUG: err &&
4693 test_i18ngrep ! core.dumped err &&
4694 test_must_be_empty err &&
4696 git ls-files >paths &&