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 (rename/rename)" 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 (rename/rename)" 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 # w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2264 # CONFLICT(z/c -> y/c vs. w/c)
2265 # Currently expected: 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. Therefore, the directory rename done in commit A to z/
2273 # applies to z/d and maps it to y/d.
2275 # It's possible that users would get confused about this, but what
2276 # should we do instead? Silently leaving at z/d seems just as bad or
2277 # maybe even worse. Perhaps we could print a big warning about z/d
2278 # and how we're moving to y/d in this case, but when I started thinking
2279 # about the ramifications of doing that, I didn't know how to rule out
2280 # that opening other weird edge and corner cases so I just punted.
2283 test_create_repo 8e &&
2292 git commit -m "O" &&
2301 git commit -m "A" &&
2313 test_expect_success '8e: Both sides rename, one side adds to original directory' '
2320 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2321 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2322 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2324 git ls-files -s >out &&
2325 test_line_count = 7 out &&
2326 git ls-files -u >out &&
2327 test_line_count = 6 out &&
2328 git ls-files -o >out &&
2329 test_line_count = 2 out &&
2331 git rev-parse >actual \
2332 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2333 git rev-parse >expect \
2334 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2335 test_cmp expect actual &&
2337 git hash-object >actual \
2339 git rev-parse >expect \
2340 O:z/b O:z/b O:z/c O:z/c &&
2341 test_cmp expect actual &&
2343 test_path_is_missing z/b &&
2344 test_path_is_missing z/c
2348 ###########################################################################
2349 # SECTION 9: Other testcases
2351 # This section consists of miscellaneous testcases I thought of during
2352 # the implementation which round out the testing.
2353 ###########################################################################
2355 # Testcase 9a, Inner renamed directory within outer renamed directory
2356 # (Related to testcase 1f)
2357 # Commit O: z/{b,c,d/{e,f,g}}
2358 # Commit A: y/{b,c}, x/w/{e,f,g}
2359 # Commit B: z/{b,c,d/{e,f,g,h},i}
2360 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2361 # NOTE: The only reason this one is interesting is because when a directory
2362 # is split into multiple other directories, we determine by the weight
2363 # of which one had the most paths going to it. A naive implementation
2364 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2367 test_create_repo 9a &&
2379 git commit -m "O" &&
2390 git commit -m "A" &&
2401 test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2408 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2410 git ls-files -s >out &&
2411 test_line_count = 7 out &&
2412 git ls-files -u >out &&
2413 test_line_count = 0 out &&
2414 git ls-files -o >out &&
2415 test_line_count = 1 out &&
2417 git rev-parse >actual \
2418 HEAD:y/b HEAD:y/c HEAD:y/i &&
2419 git rev-parse >expect \
2420 O:z/b O:z/c B:z/i &&
2421 test_cmp expect actual &&
2423 git rev-parse >actual \
2424 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2425 git rev-parse >expect \
2426 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2427 test_cmp expect actual
2431 # Testcase 9b, Transitive rename with content merge
2432 # (Related to testcase 1c)
2433 # Commit O: z/{b,c}, x/d_1
2434 # Commit A: y/{b,c}, x/d_2
2435 # Commit B: z/{b,c,d_3}
2436 # Expected: y/{b,c,d_merged}
2439 test_create_repo 9b &&
2447 test_seq 1 10 >x/d &&
2450 git commit -m "O" &&
2458 test_seq 1 11 >x/d &&
2461 git commit -m "A" &&
2464 test_seq 0 10 >x/d &&
2472 test_expect_success '9b: Transitive rename with content merge' '
2479 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2481 git ls-files -s >out &&
2482 test_line_count = 3 out &&
2484 test_seq 0 11 >expected &&
2485 test_cmp expected y/d &&
2487 git rev-parse >actual \
2488 HEAD:y/b HEAD:y/c HEAD:y/d &&
2489 git rev-parse >expect \
2490 O:z/b O:z/c :0:expected &&
2491 test_cmp expect actual &&
2492 test_must_fail git rev-parse HEAD:x/d &&
2493 test_must_fail git rev-parse HEAD:z/d &&
2494 test_path_is_missing z/d &&
2496 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2497 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2498 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2502 # Testcase 9c, Doubly transitive rename?
2503 # (Related to testcase 1c, 7e, and 9d)
2504 # Commit O: z/{b,c}, x/{d,e}, w/f
2505 # Commit A: y/{b,c}, x/{d,e,f,g}
2506 # Commit B: z/{b,c,d,e}, w/f
2507 # Expected: y/{b,c,d,e}, x/{f,g}
2509 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2510 # x/f is clear. Let's look beyond that. Here's the logic:
2511 # Commit B renamed x/ -> z/
2512 # Commit A renamed z/ -> y/
2513 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2514 # transient rename. However, where does it end? We can chain these
2515 # indefinitely (see testcase 9d). What if there is a D/F conflict
2516 # at z/f/ or y/f/? Or just another file conflict at one of those
2517 # paths? In the case of an N-long chain of transient renamings,
2518 # where do we "abort" the rename at? Can the user make sense of
2519 # the resulting conflict and resolve it?
2521 # To avoid this confusion I use the simple rule that if the other side
2522 # of history did a directory rename to a path that your side renamed
2523 # away, then ignore that particular rename from the other side of
2524 # history for any implicit directory renames.
2527 test_create_repo 9c &&
2541 git commit -m "O" &&
2553 git commit -m "A" &&
2563 test_expect_success '9c: Doubly transitive rename?' '
2570 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2571 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2573 git ls-files -s >out &&
2574 test_line_count = 6 out &&
2575 git ls-files -o >out &&
2576 test_line_count = 1 out &&
2578 git rev-parse >actual \
2579 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2580 git rev-parse >expect \
2581 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2582 test_cmp expect actual
2586 # Testcase 9d, N-fold transitive rename?
2587 # (Related to testcase 9c...and 1c and 7e)
2588 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2589 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2590 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2591 # Expected: <see NOTE first>
2593 # NOTE: z/ -> y/ (in commit A)
2594 # y/ -> x/ (in commit B)
2595 # x/ -> w/ (in commit A)
2596 # w/ -> v/ (in commit B)
2597 # v/ -> u/ (in commit A)
2598 # So, if we add a file to z, say z/t, where should it end up? In u?
2599 # What if there's another file or directory named 't' in one of the
2600 # intervening directories and/or in u itself? Also, shouldn't the
2601 # same logic that places 't' in u/ also move ALL other files to u/?
2602 # What if there are file or directory conflicts in any of them? If
2603 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2604 # like this, would the user have any hope of understanding any
2605 # conflicts or how their working tree ended up? I think not, so I'm
2606 # ruling out N-ary transitive renames for N>1.
2608 # Therefore our expected result is:
2609 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2610 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2611 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2612 # simple rules that are consistent with what we need for all the other
2613 # testcases and simplifies things for the user.
2616 test_create_repo 9d &&
2620 mkdir z y x w v u &&
2627 git add z y x w v u &&
2629 git commit -m "O" &&
2640 git commit -m "A" &&
2652 test_expect_success '9d: N-way transitive rename?' '
2659 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2660 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2661 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2662 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2663 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2665 git ls-files -s >out &&
2666 test_line_count = 7 out &&
2667 git ls-files -o >out &&
2668 test_line_count = 1 out &&
2670 git rev-parse >actual \
2672 HEAD:y/a HEAD:x/b HEAD:w/c \
2673 HEAD:u/d HEAD:u/e HEAD:u/f &&
2674 git rev-parse >expect \
2677 O:w/d O:v/e A:u/f &&
2678 test_cmp expect actual
2682 # Testcase 9e, N-to-1 whammo
2683 # (Related to testcase 9c...and 1c and 7e)
2684 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2685 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2686 # Commit B: combined/{a,b,d,e,g,h,j,k}
2687 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2688 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2691 test_create_repo 9e &&
2695 mkdir dir1 dir2 dir3 dirN &&
2706 git commit -m "O" &&
2723 git commit -m "A" &&
2726 git mv dir1 combined &&
2727 git mv dir2/* combined/ &&
2728 git mv dir3/* combined/ &&
2729 git mv dirN/* combined/ &&
2735 test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' '
2742 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2743 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2744 grep -q dir1/yo error_line &&
2745 grep -q dir2/yo error_line &&
2746 grep -q dir3/yo error_line &&
2747 grep -q dirN/yo error_line &&
2749 git ls-files -s >out &&
2750 test_line_count = 16 out &&
2751 git ls-files -u >out &&
2752 test_line_count = 0 out &&
2753 git ls-files -o >out &&
2754 test_line_count = 2 out &&
2756 git rev-parse >actual \
2757 :0:combined/a :0:combined/b :0:combined/c \
2758 :0:combined/d :0:combined/e :0:combined/f \
2759 :0:combined/g :0:combined/h :0:combined/i \
2760 :0:combined/j :0:combined/k :0:combined/l &&
2761 git rev-parse >expect \
2762 O:dir1/a O:dir1/b A:dir1/c \
2763 O:dir2/d O:dir2/e A:dir2/f \
2764 O:dir3/g O:dir3/h A:dir3/i \
2765 O:dirN/j O:dirN/k A:dirN/l &&
2766 test_cmp expect actual &&
2768 git rev-parse >actual \
2769 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2770 git rev-parse >expect \
2771 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2772 test_cmp expect actual
2776 # Testcase 9f, Renamed directory that only contained immediate subdirs
2777 # (Related to testcases 1e & 9g)
2778 # Commit O: goal/{a,b}/$more_files
2779 # Commit A: priority/{a,b}/$more_files
2780 # Commit B: goal/{a,b}/$more_files, goal/c
2781 # Expected: priority/{a,b}/$more_files, priority/c
2784 test_create_repo 9f &&
2790 echo foo >goal/a/foo &&
2791 echo bar >goal/b/bar &&
2792 echo baz >goal/b/baz &&
2795 git commit -m "O" &&
2802 git mv goal/ priority &&
2804 git commit -m "A" &&
2814 test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2821 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2823 git ls-files -s >out &&
2824 test_line_count = 4 out &&
2826 git rev-parse >actual \
2827 HEAD:priority/a/foo \
2828 HEAD:priority/b/bar \
2829 HEAD:priority/b/baz \
2831 git rev-parse >expect \
2836 test_cmp expect actual &&
2837 test_must_fail git rev-parse HEAD:goal/c
2841 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2842 # (Related to testcases 1e & 9f)
2843 # Commit O: goal/{a,b}/$more_files
2844 # Commit A: priority/{alpha,bravo}/$more_files
2845 # Commit B: goal/{a,b}/$more_files, goal/c
2846 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2849 test_create_repo 9g &&
2855 echo foo >goal/a/foo &&
2856 echo bar >goal/b/bar &&
2857 echo baz >goal/b/baz &&
2860 git commit -m "O" &&
2868 git mv goal/a/ priority/alpha &&
2869 git mv goal/b/ priority/beta &&
2872 git commit -m "A" &&
2882 test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2888 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2890 git ls-files -s >out &&
2891 test_line_count = 4 out &&
2893 git rev-parse >actual \
2894 HEAD:priority/alpha/foo \
2895 HEAD:priority/beta/bar \
2896 HEAD:priority/beta/baz \
2898 git rev-parse >expect \
2903 test_cmp expect actual &&
2904 test_must_fail git rev-parse HEAD:goal/c
2908 # Testcase 9h, Avoid implicit rename if involved as source on other side
2909 # (Extremely closely related to testcase 3a)
2910 # Commit O: z/{b,c,d_1}
2911 # Commit A: z/{b,c,d_2}
2912 # Commit B: y/{b,c}, x/d_1
2913 # Expected: y/{b,c}, x/d_2
2914 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2915 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
2917 test_create_repo 9h &&
2924 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2927 git commit -m "O" &&
2937 git commit -m "A" &&
2951 test_expect_success '9h: Avoid dir rename on merely modified path' '
2958 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2960 git ls-files -s >out &&
2961 test_line_count = 3 out &&
2963 git rev-parse >actual \
2964 HEAD:y/b HEAD:y/c HEAD:x/d &&
2965 git rev-parse >expect \
2966 O:z/b O:z/c A:z/d &&
2967 test_cmp expect actual
2971 ###########################################################################
2972 # Rules suggested by section 9:
2974 # If the other side of history did a directory rename to a path that your
2975 # side renamed away, then ignore that particular rename from the other
2976 # side of history for any implicit directory renames.
2977 ###########################################################################
2979 ###########################################################################
2980 # SECTION 10: Handling untracked files
2982 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
2983 # the operation if untracked or dirty files would be deleted or overwritten
2984 # by the merge. Unfortunately, unpack_trees() does not understand renames,
2985 # and if it doesn't abort, then it muddies up the working directory before
2986 # we even get to the point of detecting renames, so we need some special
2987 # handling, at least in the case of directory renames.
2988 ###########################################################################
2990 # Testcase 10a, Overwrite untracked: normal rename/delete
2991 # Commit O: z/{b,c_1}
2992 # Commit A: z/b + untracked z/c + untracked z/d
2993 # Commit B: z/{b,d_1}
2994 # Expected: Aborted Merge +
2995 # ERROR_MSG(untracked working tree files would be overwritten by merge)
2998 test_create_repo 10a &&
3007 git commit -m "O" &&
3016 git commit -m "A" &&
3025 test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3032 echo important >z/d &&
3034 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3035 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3037 git ls-files -s >out &&
3038 test_line_count = 1 out &&
3039 git ls-files -o >out &&
3040 test_line_count = 4 out &&
3042 echo very >expect &&
3043 test_cmp expect z/c &&
3045 echo important >expect &&
3046 test_cmp expect z/d &&
3048 git rev-parse HEAD:z/b >actual &&
3049 git rev-parse O:z/b >expect &&
3050 test_cmp expect actual
3054 # Testcase 10b, Overwrite untracked: dir rename + delete
3055 # Commit O: z/{b,c_1}
3056 # Commit A: y/b + untracked y/{c,d,e}
3057 # Commit B: z/{b,d_1,e}
3058 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3059 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3060 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3063 test_create_repo 10b &&
3072 git commit -m "O" &&
3082 git commit -m "A" &&
3093 test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3100 echo important >y/d &&
3101 echo contents >y/e &&
3103 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3104 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3105 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3107 git ls-files -s >out &&
3108 test_line_count = 3 out &&
3109 git ls-files -u >out &&
3110 test_line_count = 2 out &&
3111 git ls-files -o >out &&
3112 test_line_count = 5 out &&
3114 git rev-parse >actual \
3115 :0:y/b :3:y/d :3:y/e &&
3116 git rev-parse >expect \
3117 O:z/b O:z/c B:z/e &&
3118 test_cmp expect actual &&
3120 echo very >expect &&
3121 test_cmp expect y/c &&
3123 echo important >expect &&
3124 test_cmp expect y/d &&
3126 echo contents >expect &&
3131 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3132 # Commit O: z/{a,b}, x/{c,d}
3133 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3134 # Commit B: z/{a,b,c}, x/d
3135 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3136 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3138 # ERROR_MSG(Refusing to lose untracked file at y/c)
3141 test_create_repo 10c_$1 &&
3152 git commit -m "O" &&
3163 git commit -m "A" &&
3172 test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3178 echo important >y/c &&
3180 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3181 test_i18ngrep "CONFLICT (rename/rename)" out &&
3182 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3184 git ls-files -s >out &&
3185 test_line_count = 6 out &&
3186 git ls-files -u >out &&
3187 test_line_count = 3 out &&
3188 git ls-files -o >out &&
3189 test_line_count = 3 out &&
3191 git rev-parse >actual \
3192 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3193 git rev-parse >expect \
3194 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3195 test_cmp expect actual &&
3197 git hash-object y/c~B^0 >actual &&
3198 git rev-parse O:x/c >expect &&
3199 test_cmp expect actual &&
3201 echo important >expect &&
3206 test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3216 echo important >y/c &&
3218 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3219 test_i18ngrep "CONFLICT (rename/rename)" out &&
3220 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3222 git ls-files -s >out &&
3223 test_line_count = 6 out &&
3224 git ls-files -u >out &&
3225 test_line_count = 3 out &&
3226 git ls-files -o >out &&
3227 test_line_count = 3 out &&
3229 git rev-parse >actual \
3230 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3231 git rev-parse >expect \
3232 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3233 test_cmp expect actual &&
3235 git hash-object y/c~HEAD >actual &&
3236 git rev-parse O:x/c >expect &&
3237 test_cmp expect actual &&
3239 echo important >expect &&
3244 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3245 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3246 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3247 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3248 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3249 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3250 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3253 test_create_repo 10d &&
3266 git commit -m "O" &&
3273 git mv z/c x/wham &&
3276 git commit -m "A" &&
3279 git mv x/f z/wham &&
3286 test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3292 echo important >y/wham &&
3294 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3295 test_i18ngrep "CONFLICT (rename/rename)" out &&
3296 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3298 git ls-files -s >out &&
3299 test_line_count = 6 out &&
3300 git ls-files -u >out &&
3301 test_line_count = 2 out &&
3302 git ls-files -o >out &&
3303 test_line_count = 3 out &&
3305 git rev-parse >actual \
3306 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3307 git rev-parse >expect \
3308 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3309 test_cmp expect actual &&
3311 test_must_fail git rev-parse :1:y/wham &&
3313 echo important >expect &&
3314 test_cmp expect y/wham &&
3316 # Test that the two-way merge in y/wham~merged is as expected
3317 git cat-file -p :2:y/wham >expect &&
3318 git cat-file -p :3:y/wham >other &&
3320 test_must_fail git merge-file \
3324 expect empty other &&
3325 test_cmp expect y/wham~merged
3329 # Testcase 10e, Does git complain about untracked file that's not in the way?
3331 # Commit A: y/{a,b} + untracked z/c
3332 # Commit B: z/{a,b,c}
3333 # Expected: y/{a,b,c} + untracked z/c
3336 test_create_repo 10e &&
3345 git commit -m "O" &&
3354 git commit -m "A" &&
3364 test_expect_failure '10e: Does git complain about untracked file that is not really in the way?' '
3372 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3373 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3375 git ls-files -s >out &&
3376 test_line_count = 3 out &&
3377 git ls-files -u >out &&
3378 test_line_count = 0 out &&
3379 git ls-files -o >out &&
3380 test_line_count = 3 out &&
3382 git rev-parse >actual \
3383 :0:y/a :0:y/b :0:y/c &&
3384 git rev-parse >expect \
3385 O:z/a O:z/b B:z/c &&
3386 test_cmp expect actual &&
3388 echo random >expect &&
3393 ###########################################################################
3394 # SECTION 11: Handling dirty (not up-to-date) files
3396 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3397 # the operation if untracked or dirty files would be deleted or overwritten
3398 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3399 # and if it doesn't abort, then it muddies up the working directory before
3400 # we even get to the point of detecting renames, so we need some special
3401 # handling. This was true even of normal renames, but there are additional
3402 # codepaths that need special handling with directory renames. Add
3403 # testcases for both renamed-by-directory-rename-detection and standard
3405 ###########################################################################
3407 # Testcase 11a, Avoid losing dirty contents with simple rename
3408 # Commit O: z/{a,b_v1},
3409 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3410 # Commit B: z/{a,b_v2}
3411 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3412 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3413 # z/c~HEAD with contents of B:z/b_v2,
3414 # z/c with uncommitted mods on top of A:z/c_v1
3417 test_create_repo 11a &&
3423 test_seq 1 10 >z/b &&
3426 git commit -m "O" &&
3435 git commit -m "A" &&
3445 test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3453 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3454 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3456 test_seq 1 10 >expected &&
3457 echo stuff >>expected &&
3458 test_cmp expected z/c &&
3460 git ls-files -s >out &&
3461 test_line_count = 2 out &&
3462 git ls-files -u >out &&
3463 test_line_count = 1 out &&
3464 git ls-files -o >out &&
3465 test_line_count = 4 out &&
3467 git rev-parse >actual \
3469 git rev-parse >expect \
3471 test_cmp expect actual &&
3473 git hash-object z/c~HEAD >actual &&
3474 git rev-parse B:z/b >expect &&
3475 test_cmp expect actual
3479 # Testcase 11b, Avoid losing dirty file involved in directory rename
3480 # Commit O: z/a, x/{b,c_v1}
3481 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3482 # Commit B: y/a, x/{b,c_v2}
3483 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3484 # ERROR_MSG(Refusing to lose dirty file at z/c)
3488 test_create_repo 11b &&
3495 test_seq 1 10 >x/c &&
3498 git commit -m "O" &&
3507 git commit -m "A" &&
3518 test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3526 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3527 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3529 grep -q stuff z/c &&
3530 test_seq 1 10 >expected &&
3531 echo stuff >>expected &&
3532 test_cmp expected z/c &&
3534 git ls-files -s >out &&
3535 test_line_count = 3 out &&
3536 git ls-files -u >out &&
3537 test_line_count = 0 out &&
3538 git ls-files -m >out &&
3539 test_line_count = 0 out &&
3540 git ls-files -o >out &&
3541 test_line_count = 4 out &&
3543 git rev-parse >actual \
3544 :0:x/b :0:y/a :0:y/c &&
3545 git rev-parse >expect \
3546 O:x/b O:z/a B:x/c &&
3547 test_cmp expect actual &&
3549 git hash-object y/c >actual &&
3550 git rev-parse B:x/c >expect &&
3551 test_cmp expect actual
3555 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3556 # Commit O: y/a, x/{b,c_v1}
3557 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3558 # Commit B: y/{a,c/d}, x/{b,c_v2}
3559 # Expected: Abort_msg("following files would be overwritten by merge") +
3560 # y/c left untouched (still has uncommitted mods)
3563 test_create_repo 11c &&
3570 test_seq 1 10 >x/c &&
3573 git commit -m "O" &&
3582 git commit -m "A" &&
3588 git add x/c y/c/d &&
3594 test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3602 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3603 test_i18ngrep "following files would be overwritten by merge" err &&
3605 grep -q stuff y/c &&
3606 test_seq 1 10 >expected &&
3607 echo stuff >>expected &&
3608 test_cmp expected y/c &&
3610 git ls-files -s >out &&
3611 test_line_count = 3 out &&
3612 git ls-files -u >out &&
3613 test_line_count = 0 out &&
3614 git ls-files -m >out &&
3615 test_line_count = 1 out &&
3616 git ls-files -o >out &&
3617 test_line_count = 3 out
3621 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3622 # Commit O: z/a, x/{b,c_v1}
3623 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3624 # Commit B: y/{a,c/d}, x/{b,c_v2}
3625 # Expected: D/F: y/c_v2 vs y/c/d) +
3626 # Warning_Msg("Refusing to lose dirty file at z/c) +
3627 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3630 test_create_repo 11d &&
3637 test_seq 1 10 >x/c &&
3640 git commit -m "O" &&
3649 git commit -m "A" &&
3656 git add x/c y/c/d &&
3662 test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3670 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3671 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3673 grep -q stuff z/c &&
3674 test_seq 1 10 >expected &&
3675 echo stuff >>expected &&
3676 test_cmp expected z/c &&
3678 git ls-files -s >out &&
3679 test_line_count = 4 out &&
3680 git ls-files -u >out &&
3681 test_line_count = 1 out &&
3682 git ls-files -o >out &&
3683 test_line_count = 5 out &&
3685 git rev-parse >actual \
3686 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3687 git rev-parse >expect \
3688 O:x/b O:z/a B:y/c/d B:x/c &&
3689 test_cmp expect actual &&
3691 git hash-object y/c~HEAD >actual &&
3692 git rev-parse B:x/c >expect &&
3693 test_cmp expect actual
3697 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3698 # Commit O: z/{a,b}, x/{c_1,d}
3699 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3700 # Commit B: z/{a,b,c_1}, x/d
3701 # Expected: Failed Merge; y/{a,b} + x/d +
3702 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3703 # ERROR_MSG(Refusing to lose dirty file at y/c)
3704 # y/c~B^0 has O:x/c_1 contents
3705 # y/c~HEAD has A:y/c_2 contents
3706 # y/c has dirty file from before merge
3709 test_create_repo 11e &&
3720 git commit -m "O" &&
3728 echo different >y/c &&
3733 git commit -m "A" &&
3742 test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3750 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3751 test_i18ngrep "CONFLICT (rename/rename)" out &&
3752 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3754 git ls-files -s >out &&
3755 test_line_count = 7 out &&
3756 git ls-files -u >out &&
3757 test_line_count = 4 out &&
3758 git ls-files -o >out &&
3759 test_line_count = 3 out &&
3761 echo different >expected &&
3762 echo mods >>expected &&
3763 test_cmp expected y/c &&
3765 git rev-parse >actual \
3766 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3767 git rev-parse >expect \
3768 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3769 test_cmp expect actual &&
3771 # See if y/c~merged has expected contents; requires manually
3772 # doing the expected file merge
3773 git cat-file -p A:y/c >c1 &&
3774 git cat-file -p B:z/c >c2 &&
3776 test_must_fail git merge-file \
3781 test_cmp c1 y/c~merged
3785 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3786 # Commit O: z/{a,b}, x/{c_1,d_2}
3787 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3788 # Commit B: z/{a,b,wham_2}, x/c_1
3789 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3790 # y/wham with dirty changes from before merge +
3791 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3792 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3795 test_create_repo 11f &&
3802 test_seq 1 10 >x/c &&
3806 git commit -m "O" &&
3814 git mv x/c y/wham &&
3816 git commit -m "A" &&
3819 git mv x/d z/wham &&
3825 test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3831 echo important >>y/wham &&
3833 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3834 test_i18ngrep "CONFLICT (rename/rename)" out &&
3835 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3837 git ls-files -s >out &&
3838 test_line_count = 4 out &&
3839 git ls-files -u >out &&
3840 test_line_count = 2 out &&
3841 git ls-files -o >out &&
3842 test_line_count = 3 out &&
3844 test_seq 1 10 >expected &&
3845 echo important >>expected &&
3846 test_cmp expected y/wham &&
3848 test_must_fail git rev-parse :1:y/wham &&
3850 git rev-parse >actual \
3851 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3852 git rev-parse >expect \
3853 O:z/a O:z/b O:x/c O:x/d &&
3854 test_cmp expect actual &&
3856 # Test that the two-way merge in y/wham~merged is as expected
3857 git cat-file -p :2:y/wham >expect &&
3858 git cat-file -p :3:y/wham >other &&
3860 test_must_fail git merge-file \
3864 expect empty other &&
3865 test_cmp expect y/wham~merged
3869 ###########################################################################
3870 # SECTION 12: Everything else
3872 # Tests suggested by others. Tests added after implementation completed
3873 # and submitted. Grab bag.
3874 ###########################################################################
3876 # Testcase 12a, Moving one directory hierarchy into another
3877 # (Related to testcase 9a)
3878 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3879 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3880 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3881 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3884 test_create_repo 12a &&
3888 mkdir -p node1 node2 &&
3889 echo leaf1 >node1/leaf1 &&
3890 echo leaf2 >node1/leaf2 &&
3891 echo leaf3 >node2/leaf3 &&
3892 echo leaf4 >node2/leaf4 &&
3893 git add node1 node2 &&
3895 git commit -m "O" &&
3902 git mv node2/ node1/ &&
3904 git commit -m "A" &&
3907 echo leaf5 >node1/leaf5 &&
3908 echo leaf6 >node2/leaf6 &&
3909 git add node1 node2 &&
3915 test_expect_success '12a: Moving one directory hierarchy into another' '
3922 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3924 git ls-files -s >out &&
3925 test_line_count = 6 out &&
3927 git rev-parse >actual \
3928 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3929 HEAD:node1/node2/leaf3 \
3930 HEAD:node1/node2/leaf4 \
3931 HEAD:node1/node2/leaf6 &&
3932 git rev-parse >expect \
3933 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3937 test_cmp expect actual
3941 # Testcase 12b, Moving two directory hierarchies into each other
3942 # (Related to testcases 1c and 12c)
3943 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3944 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3945 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3946 # Expected: node1/node2/node1/{leaf1, leaf2},
3947 # node2/node1/node2/{leaf3, leaf4}
3948 # NOTE: Without directory renames, we would expect
3949 # node2/node1/{leaf1, leaf2},
3950 # node1/node2/{leaf3, leaf4}
3951 # with directory rename detection, we note that
3952 # commit A renames node2/ -> node1/node2/
3953 # commit B renames node1/ -> node2/node1/
3954 # therefore, applying those directory renames to the initial result
3955 # (making all four paths experience a transitive renaming), yields
3956 # the expected result.
3958 # You may ask, is it weird to have two directories rename each other?
3959 # To which, I can do no more than shrug my shoulders and say that
3960 # even simple rules give weird results when given weird inputs.
3963 test_create_repo 12b &&
3967 mkdir -p node1 node2 &&
3968 echo leaf1 >node1/leaf1 &&
3969 echo leaf2 >node1/leaf2 &&
3970 echo leaf3 >node2/leaf3 &&
3971 echo leaf4 >node2/leaf4 &&
3972 git add node1 node2 &&
3974 git commit -m "O" &&
3981 git mv node2/ node1/ &&
3983 git commit -m "A" &&
3986 git mv node1/ node2/ &&
3992 test_expect_success '12b: Moving two directory hierarchies into each other' '
3999 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4001 git ls-files -s >out &&
4002 test_line_count = 4 out &&
4004 git rev-parse >actual \
4005 HEAD:node1/node2/node1/leaf1 \
4006 HEAD:node1/node2/node1/leaf2 \
4007 HEAD:node2/node1/node2/leaf3 \
4008 HEAD:node2/node1/node2/leaf4 &&
4009 git rev-parse >expect \
4014 test_cmp expect actual
4018 # Testcase 12c, Moving two directory hierarchies into each other w/ content merge
4019 # (Related to testcase 12b)
4020 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4021 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4022 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4023 # Expected: Content merge conflicts for each of:
4024 # node1/node2/node1/{leaf1, leaf2},
4025 # node2/node1/node2/{leaf3, leaf4}
4026 # NOTE: This is *exactly* like 12c, except that every path is modified on
4027 # each side of the merge.
4030 test_create_repo 12c &&
4034 mkdir -p node1 node2 &&
4035 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4036 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4037 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4038 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4039 git add node1 node2 &&
4041 git commit -m "O" &&
4048 git mv node2/ node1/ &&
4049 for i in `git ls-files`; do echo side A >>$i; done &&
4052 git commit -m "A" &&
4055 git mv node1/ node2/ &&
4056 for i in `git ls-files`; do echo side B >>$i; done &&
4063 test_expect_success '12c: Moving one directory hierarchy into another w/ content merge' '
4070 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4072 git ls-files -u >out &&
4073 test_line_count = 12 out &&
4075 git rev-parse >actual \
4076 :1:node1/node2/node1/leaf1 \
4077 :1:node1/node2/node1/leaf2 \
4078 :1:node2/node1/node2/leaf3 \
4079 :1:node2/node1/node2/leaf4 \
4080 :2:node1/node2/node1/leaf1 \
4081 :2:node1/node2/node1/leaf2 \
4082 :2:node2/node1/node2/leaf3 \
4083 :2:node2/node1/node2/leaf4 \
4084 :3:node1/node2/node1/leaf1 \
4085 :3:node1/node2/node1/leaf2 \
4086 :3:node2/node1/node2/leaf3 \
4087 :3:node2/node1/node2/leaf4 &&
4088 git rev-parse >expect \
4095 A:node1/node2/leaf3 \
4096 A:node1/node2/leaf4 \
4097 B:node2/node1/leaf1 \
4098 B:node2/node1/leaf2 \
4101 test_cmp expect actual
4105 # Testcase 12d, Rename/merge of subdirectory into the root
4106 # Commit O: a/b/subdir/foo
4107 # Commit A: subdir/foo
4108 # Commit B: a/b/subdir/foo, a/b/bar
4109 # Expected: subdir/foo, bar
4112 test_create_repo 12d &&
4116 mkdir -p a/b/subdir &&
4117 test_commit a/b/subdir/foo &&
4125 git mv a/b/subdir/foo.t subdir/foo.t &&
4127 git commit -m "A" &&
4134 test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4141 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4143 git ls-files -s >out &&
4144 test_line_count = 2 out &&
4146 git rev-parse >actual \
4147 HEAD:subdir/foo.t HEAD:bar.t &&
4148 git rev-parse >expect \
4149 O:a/b/subdir/foo.t B:a/b/bar.t &&
4150 test_cmp expect actual &&
4152 git hash-object bar.t >actual &&
4153 git rev-parse B:a/b/bar.t >expect &&
4154 test_cmp expect actual &&
4156 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4157 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4158 test_path_is_missing a/ &&
4159 test_path_is_file bar.t
4163 # Testcase 12e, Rename/merge of subdirectory into the root
4166 # Commit B: a/b/foo, a/b/bar
4167 # Expected: foo, bar
4170 test_create_repo 12e &&
4175 test_commit a/b/foo &&
4183 git mv a/b/foo.t foo.t &&
4185 git commit -m "A" &&
4192 test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4199 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4201 git ls-files -s >out &&
4202 test_line_count = 2 out &&
4204 git rev-parse >actual \
4205 HEAD:foo.t HEAD:bar.t &&
4206 git rev-parse >expect \
4207 O:a/b/foo.t B:a/b/bar.t &&
4208 test_cmp expect actual &&
4210 git hash-object bar.t >actual &&
4211 git rev-parse B:a/b/bar.t >expect &&
4212 test_cmp expect actual &&
4214 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4215 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4216 test_path_is_missing a/ &&
4217 test_path_is_file bar.t
4221 ###########################################################################
4222 # SECTION 13: Checking informational and conflict messages
4224 # A year after directory rename detection became the default, it was
4225 # instead decided to report conflicts on the pathname on the basis that
4226 # some users may expect the new files added or moved into a directory to
4227 # be unrelated to all the other files in that directory, and thus that
4228 # directory rename detection is unexpected. Test that the messages printed
4229 # match our expectation.
4230 ###########################################################################
4232 # Testcase 13a, Basic directory rename with newly added files
4235 # Commit B: z/{b,c,d,e/f}
4236 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4239 test_create_repo 13a_$1 &&
4248 git commit -m "O" &&
4257 git commit -m "A" &&
4263 git add z/d z/e/f &&
4269 test_expect_success '13a(conflict): messages for newly added files' '
4270 test_setup_13a conflict &&
4276 test_must_fail git merge -s recursive B^0 >out 2>err &&
4278 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4279 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4281 git ls-files >paths &&
4283 grep "y/[de]" paths &&
4285 test_path_is_missing z/d &&
4286 test_path_is_file y/d &&
4287 test_path_is_missing z/e/f &&
4288 test_path_is_file y/e/f
4292 test_expect_success '13a(info): messages for newly added files' '
4293 test_setup_13a info &&
4300 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4302 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4303 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4305 git ls-files >paths &&
4307 grep "y/[de]" paths &&
4309 test_path_is_missing z/d &&
4310 test_path_is_file y/d &&
4311 test_path_is_missing z/e/f &&
4312 test_path_is_file y/e/f
4316 # Testcase 13b, Transitive rename with conflicted content merge and default
4317 # "conflict" setting
4318 # (Related to testcase 1c, 9b)
4319 # Commit O: z/{b,c}, x/d_1
4320 # Commit A: y/{b,c}, x/d_2
4321 # Commit B: z/{b,c,d_3}
4322 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4323 # one about content, and one about file location
4326 test_create_repo 13b_$1 &&
4332 test_seq 1 10 >x/d &&
4337 git commit -m "O" &&
4348 git commit -m "A" &&
4351 echo eleven >>x/d &&
4359 test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
4360 test_setup_13b conflict &&
4366 test_must_fail git merge -s recursive B^0 >out 2>err &&
4368 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4369 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4371 git ls-files >paths &&
4375 test_path_is_missing z/d &&
4376 test_path_is_file y/d
4380 test_expect_success '13b(info): messages for transitive rename with conflicted content' '
4381 test_setup_13b info &&
4388 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4390 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4391 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4393 git ls-files >paths &&
4397 test_path_is_missing z/d &&
4398 test_path_is_file y/d
4402 # Testcase 13c, Rename/rename(1to1) due to directory rename
4403 # Commit O: z/{b,c}, x/{d,e}
4404 # Commit A: y/{b,c,d}, x/e
4405 # Commit B: z/{b,c,d}, x/e
4406 # Expected: y/{b,c,d}, with info or conflict messages for d (
4407 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4408 # One could argue A had partial knowledge of what was done with
4409 # d and B had full knowledge, but that's a slippery slope as
4410 # shown in testcase 13d.
4413 test_create_repo 13c_$1 &&
4419 test_seq 1 10 >x/d &&
4425 git commit -m "O" &&
4435 git commit -m "A" &&
4445 test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
4446 test_setup_13c conflict &&
4452 test_must_fail git merge -s recursive B^0 >out 2>err &&
4454 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4456 git ls-files >paths &&
4460 test_path_is_missing z/d &&
4461 test_path_is_file y/d
4465 test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
4466 test_setup_13c info &&
4473 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4475 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4477 git ls-files >paths &&
4481 test_path_is_missing z/d &&
4482 test_path_is_file y/d
4486 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4487 # Commit O: a/{z,y}, b/x, c/w
4488 # Commit A: a/z, b/{y,x}, d/w
4489 # Commit B: a/z, d/x, c/{y,w}
4490 # Expected: a/z, d/{y,x,w} with no file location conflict for x
4492 # * z is always in a; so it stays in a.
4493 # * x starts in b, only modified on one side to move into d/
4494 # * w starts in c, only modified on one side to move into d/
4496 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
4497 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
4498 # No conflict in where a/y ends up, so put it in d/y.
4501 test_create_repo 13d_$1 &&
4514 git commit -m "O" &&
4524 git commit -m "A" &&
4534 test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
4535 test_setup_13d conflict &&
4541 test_must_fail git merge -s recursive B^0 >out 2>err &&
4543 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
4544 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
4546 git ls-files >paths &&
4551 test_path_is_missing b/y &&
4552 test_path_is_missing c/y &&
4553 test_path_is_file d/y
4557 test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
4558 test_setup_13d info &&
4565 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4567 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
4568 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
4570 git ls-files >paths &&
4575 test_path_is_missing b/y &&
4576 test_path_is_missing c/y &&
4577 test_path_is_file d/y
4581 # Testcase 13e, directory rename in virtual merge base
4583 # This testcase has a slightly different setup than all the above cases, in
4584 # order to include a recursive case:
4596 # Commit B: a/{z,y,x}
4597 # Commit C: b/{z,y,x}
4598 # Commit D: b/{z,y}, a/x
4599 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
4601 # NOTES: 'X' represents a virtual merge base. With the default of
4602 # directory rename detection yielding conflicts, merging A and B
4603 # results in a conflict complaining about whether 'x' should be
4604 # under 'a/' or 'b/'. However, when creating the virtual merge
4605 # base 'X', since virtual merge bases need to be written out as a
4606 # tree, we cannot have a conflict, so some resolution has to be
4609 # In choosing the right resolution, it's worth noting here that
4610 # commits C & D are merges of A & B that choose different
4611 # locations for 'x' (i.e. they resolve the conflict differently),
4612 # and so it would be nice when merging C & D if git could detect
4613 # this difference of opinion and report a conflict. But the only
4614 # way to do so that I can think of would be to have the virtual
4615 # merge base place 'x' in some directory other than either 'a/' or
4616 # 'b/', which seems a little weird -- especially since it'd result
4617 # in a rename/rename(1to2) conflict with a source path that never
4618 # existed in any version.
4620 # So, for now, when directory rename detection is set to
4621 # 'conflict' just avoid doing directory rename detection at all in
4622 # the recursive case. This will not allow us to detect a conflict
4623 # in the outer merge for this special kind of setup, but it at
4624 # least avoids hitting a BUG().
4627 test_create_repo 13e &&
4636 git commit -m "O" &&
4645 git commit -m "A" &&
4651 git commit -m "B" &&
4657 test_must_fail git -c merge.directoryRenames=conflict merge B &&
4660 git commit -m "C" &&
4664 test_must_fail git -c merge.directoryRenames=conflict merge A &&
4673 test_expect_success '13e: directory rename detection in recursive case' '
4678 git checkout --quiet D^0 &&
4680 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
4682 test_i18ngrep ! CONFLICT out &&
4683 test_i18ngrep ! BUG: err &&
4684 test_i18ngrep ! core.dumped err &&
4685 test_must_be_empty err &&
4687 git ls-files >paths &&