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 6b1, Same rename done on both sides
1281 # (Related to testcase 6b2 and 8e)
1282 # Commit O: z/{b,c,d,e}
1283 # Commit A: y/{b,c,d}, x/e
1284 # Commit B: y/{b,c,d}, z/{e,f}
1285 # Expected: y/{b,c,d,f}, x/e
1286 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1287 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1288 # should be moved to 'y/f'.
1290 # This is a bit of an edge case where any behavior might surprise users,
1291 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1292 # z/ -> x/, or treating A as not doing any directory rename. However, I
1293 # think this answer is the least confusing and most consistent with the
1296 # A note about z/ -> x/, since it may not be clear how that could come
1297 # about: If we were to ignore files renamed by both sides
1298 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1299 # at least git-2.28, then we would note there are no renames from z/ to
1300 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1301 # A renamed z/ -> x/. This seems more confusing for end users than a
1302 # rename of z/ to y/, it makes directory rename detection behavior
1303 # harder for them to predict. As such, we modified the rule, changed
1304 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1307 test_create_repo 6b1 &&
1318 git commit -m "O" &&
1329 git commit -m "A" &&
1342 test_expect_failure '6b1: Same renames done on both sides, plus another rename' '
1349 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1351 git ls-files -s >out &&
1352 test_line_count = 5 out &&
1353 git ls-files -u >out &&
1354 test_line_count = 0 out &&
1355 git ls-files -o >out &&
1356 test_line_count = 1 out &&
1358 git rev-parse >actual \
1359 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1360 git rev-parse >expect \
1361 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1362 test_cmp expect actual
1366 # Testcase 6b2, Same rename done on both sides
1367 # (Related to testcases 6c and 8e)
1370 # Commit B: y/{b,c}, z/d
1371 # Expected: y/{b,c,d}
1372 # Alternate: y/{b,c}, z/d
1373 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1374 # file 'z/d' in B should be moved to 'y/d'.
1376 # We could potentially ignore the renames of z/{b,c} on side A since
1377 # those were renamed on both sides. However, it's a bit of a corner
1378 # case because what if there was also a z/e that side A moved to x/e
1379 # and side B left alone? If we used the "ignore renames done on both
1380 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1381 # z/d to x/d. That seems more surprising and uglier than allowing
1382 # the z/ -> y/ rename.
1385 test_create_repo 6b2 &&
1394 git commit -m "O" &&
1403 git commit -m "A" &&
1415 test_expect_failure '6b2: Same rename done on both sides' '
1422 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1424 git ls-files -s >out &&
1425 test_line_count = 3 out &&
1426 git ls-files -u >out &&
1427 test_line_count = 0 out &&
1428 git ls-files -o >out &&
1429 test_line_count = 1 out &&
1431 git rev-parse >actual \
1432 HEAD:y/b HEAD:y/c HEAD:y/d &&
1433 git rev-parse >expect \
1434 O:z/b O:z/c B:z/d &&
1435 test_cmp expect actual
1439 # Testcase 6c, Rename only done on same side
1440 # (Related to testcases 6b1, 6b2, and 8e)
1442 # Commit A: z/{b,c} (no change)
1443 # Commit B: y/{b,c}, z/d
1444 # Expected: y/{b,c}, z/d
1445 # NOTE: Seems obvious, but just checking that the implementation doesn't
1446 # "accidentally detect a rename" and give us y/{b,c,d}.
1449 test_create_repo 6c &&
1458 git commit -m "O" &&
1466 git commit --allow-empty -m "A" &&
1478 test_expect_success '6c: Rename only done on same side' '
1485 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1487 git ls-files -s >out &&
1488 test_line_count = 3 out &&
1489 git ls-files -u >out &&
1490 test_line_count = 0 out &&
1491 git ls-files -o >out &&
1492 test_line_count = 1 out &&
1494 git rev-parse >actual \
1495 HEAD:y/b HEAD:y/c HEAD:z/d &&
1496 git rev-parse >expect \
1497 O:z/b O:z/c B:z/d &&
1498 test_cmp expect actual
1502 # Testcase 6d, We don't always want transitive renaming
1503 # (Related to testcase 1c)
1504 # Commit O: z/{b,c}, x/d
1505 # Commit A: z/{b,c}, x/d (no change)
1506 # Commit B: y/{b,c}, z/d
1507 # Expected: y/{b,c}, z/d
1508 # NOTE: Again, this seems obvious but just checking that the implementation
1509 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1512 test_create_repo 6d &&
1523 git commit -m "O" &&
1531 git commit --allow-empty -m "A" &&
1541 test_expect_success '6d: We do not always want transitive renaming' '
1548 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1550 git ls-files -s >out &&
1551 test_line_count = 3 out &&
1552 git ls-files -u >out &&
1553 test_line_count = 0 out &&
1554 git ls-files -o >out &&
1555 test_line_count = 1 out &&
1557 git rev-parse >actual \
1558 HEAD:y/b HEAD:y/c HEAD:z/d &&
1559 git rev-parse >expect \
1560 O:z/b O:z/c O:x/d &&
1561 test_cmp expect actual
1565 # Testcase 6e, Add/add from one-side
1567 # Commit A: z/{b,c} (no change)
1568 # Commit B: y/{b,c,d_1}, z/d_2
1569 # Expected: y/{b,c,d_1}, z/d_2
1570 # NOTE: Again, this seems obvious but just checking that the implementation
1571 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1572 # add/add conflict on y/d_1 vs y/d_2.
1575 test_create_repo 6e &&
1584 git commit -m "O" &&
1592 git commit --allow-empty -m "A" &&
1605 test_expect_success '6e: Add/add from one side' '
1612 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1614 git ls-files -s >out &&
1615 test_line_count = 4 out &&
1616 git ls-files -u >out &&
1617 test_line_count = 0 out &&
1618 git ls-files -o >out &&
1619 test_line_count = 1 out &&
1621 git rev-parse >actual \
1622 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1623 git rev-parse >expect \
1624 O:z/b O:z/c B:y/d B:z/d &&
1625 test_cmp expect actual
1629 ###########################################################################
1630 # Rules suggested by section 6:
1632 # Only apply implicit directory renames to directories if the other
1633 # side of history is the one doing the renaming.
1634 ###########################################################################
1637 ###########################################################################
1638 # SECTION 7: More involved Edge/Corner cases
1640 # The ruleset we have generated in the above sections seems to provide
1641 # well-defined merges. But can we find edge/corner cases that either (a)
1642 # are harder for users to understand, or (b) have a resolution that is
1643 # non-intuitive or suboptimal?
1645 # The testcases in this section dive into cases that I've tried to craft in
1646 # a way to find some that might be surprising to users or difficult for
1647 # them to understand (the next section will look at non-intuitive or
1648 # suboptimal merge results). Some of the testcases are similar to ones
1649 # from past sections, but have been simplified to try to highlight error
1650 # messages using a "modified" path (due to the directory rename). Are
1651 # users okay with these?
1653 # In my opinion, testcases that are difficult to understand from this
1654 # section is due to difficulty in the testcase rather than the directory
1655 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1656 # to the problem setup itself being complex). And I don't think the
1657 # error messages are a problem.
1659 # On the other hand, the testcases in section 8 worry me slightly more...
1660 ###########################################################################
1662 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1665 # Commit B: w/b, x/c, z/d
1666 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1667 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1670 test_create_repo 7a &&
1679 git commit -m "O" &&
1688 git commit -m "A" &&
1702 test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1709 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1710 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1711 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1713 git ls-files -s >out &&
1714 test_line_count = 7 out &&
1715 git ls-files -u >out &&
1716 test_line_count = 6 out &&
1717 git ls-files -o >out &&
1718 test_line_count = 1 out &&
1720 git rev-parse >actual \
1721 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1722 git rev-parse >expect \
1723 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1724 test_cmp expect actual &&
1726 git hash-object >actual \
1728 git rev-parse >expect \
1729 O:z/b O:z/b O:z/c O:z/c &&
1730 test_cmp expect actual
1734 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1735 # (Related to testcase 1d)
1736 # Commit O: z/{b,c}, x/d_1, w/d_2
1737 # Commit A: y/{b,c,d_2}, x/d_1
1738 # Commit B: z/{b,c,d_1}, w/d_2
1739 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1742 test_create_repo 7b &&
1755 git commit -m "O" &&
1765 git commit -m "A" &&
1775 test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' '
1782 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1783 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
1785 git ls-files -s >out &&
1786 test_line_count = 4 out &&
1787 git ls-files -u >out &&
1788 test_line_count = 2 out &&
1789 git ls-files -o >out &&
1790 test_line_count = 1 out &&
1792 git rev-parse >actual \
1793 :0:y/b :0:y/c :2:y/d :3:y/d &&
1794 git rev-parse >expect \
1795 O:z/b O:z/c O:w/d O:x/d &&
1796 test_cmp expect actual &&
1798 # Test that the two-way merge in y/d is as expected
1799 git cat-file -p :2:y/d >expect &&
1800 git cat-file -p :3:y/d >other &&
1802 test_must_fail git merge-file \
1806 expect empty other &&
1811 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1812 # (Related to testcases 3b and 5c)
1813 # Commit O: z/{b,c}, x/d
1814 # Commit A: y/{b,c}, w/d
1815 # Commit B: z/{b,c,d}
1816 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1817 # NOTE: z/ was renamed to y/ so we do want to report
1818 # neither CONFLICT(x/d -> w/d vs. z/d)
1819 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1822 test_create_repo 7c &&
1833 git commit -m "O" &&
1843 git commit -m "A" &&
1853 test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1860 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1861 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1863 git ls-files -s >out &&
1864 test_line_count = 5 out &&
1865 git ls-files -u >out &&
1866 test_line_count = 3 out &&
1867 git ls-files -o >out &&
1868 test_line_count = 1 out &&
1870 git rev-parse >actual \
1871 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1872 git rev-parse >expect \
1873 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1874 test_cmp expect actual
1878 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1879 # (Related somewhat to testcases 5b and 8d)
1880 # Commit O: z/{b,c}, x/d
1882 # Commit B: z/{b,c,d}
1883 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1884 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1887 test_create_repo 7d &&
1898 git commit -m "O" &&
1908 git commit -m "A" &&
1918 test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' '
1925 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1926 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1928 git ls-files -s >out &&
1929 test_line_count = 3 out &&
1930 git ls-files -u >out &&
1931 test_line_count = 1 out &&
1932 git ls-files -o >out &&
1933 test_line_count = 1 out &&
1935 git rev-parse >actual \
1936 :0:y/b :0:y/c :3:y/d &&
1937 git rev-parse >expect \
1938 O:z/b O:z/c O:x/d &&
1939 test_cmp expect actual
1943 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1944 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1945 # (Also related to testcases 9c and 9d)
1946 # Commit O: z/{b,c}, x/d_1
1947 # Commit A: y/{b,c,d/g}, x/d/f
1948 # Commit B: z/{b,c,d_1}
1949 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1950 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1952 # NOTE: The main path of interest here is d_1 and where it ends up, but
1953 # this is actually a case that has two potential directory renames
1954 # involved and D/F conflict(s), so it makes sense to walk through
1957 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1958 # should be instead moved to y/. This gives us the D/F conflict on
1959 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1961 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1962 # should instead be moved to z/...BUT we removed z/ and renamed it
1963 # to y/, so maybe everything should move not from x/ to z/, but
1964 # from x/ to z/ to y/. Doing so might make sense from the logic so
1965 # far, but note that commit A had both an x/ and a y/; it did the
1966 # renaming of z/ to y/ and created x/d/f and it clearly made these
1967 # things separate, so it doesn't make much sense to push these
1968 # together. Doing so is what I'd call a doubly transitive rename;
1969 # see testcases 9c and 9d for further discussion of this issue and
1970 # how it's resolved.
1973 test_create_repo 7e &&
1984 git commit -m "O" &&
1997 git add x/d/f y/d/g &&
1999 git commit -m "A" &&
2009 test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' '
2016 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2017 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2019 git ls-files -s >out &&
2020 test_line_count = 5 out &&
2021 git ls-files -u >out &&
2022 test_line_count = 1 out &&
2023 git ls-files -o >out &&
2024 test_line_count = 2 out &&
2026 git rev-parse >actual \
2027 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2028 git rev-parse >expect \
2029 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
2030 test_cmp expect actual &&
2032 git hash-object y/d~B^0 >actual &&
2033 git rev-parse O:x/d >expect &&
2034 test_cmp expect actual
2038 ###########################################################################
2039 # SECTION 8: Suboptimal merges
2041 # As alluded to in the last section, the ruleset we have built up for
2042 # detecting directory renames unfortunately has some special cases where it
2043 # results in slightly suboptimal or non-intuitive behavior. This section
2044 # explores these cases.
2046 # To be fair, we already had non-intuitive or suboptimal behavior for most
2047 # of these cases in git before introducing implicit directory rename
2048 # detection, but it'd be nice if there was a modified ruleset out there
2049 # that handled these cases a bit better.
2050 ###########################################################################
2052 # Testcase 8a, Dual-directory rename, one into the others' way
2053 # Commit O. x/{a,b}, y/{c,d}
2054 # Commit A. x/{a,b,e}, y/{c,d,f}
2055 # Commit B. y/{a,b}, z/{c,d}
2057 # Possible Resolutions:
2058 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2059 # Currently expected: y/{a,b,e,f}, z/{c,d}
2060 # Optimal: y/{a,b,e}, z/{c,d,f}
2062 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2063 # better with directory rename detection than git did without, but the
2064 # simple rule from section 5 prevents me from handling this as optimally as
2065 # we potentially could.
2068 test_create_repo 8a &&
2080 git commit -m "O" &&
2091 git commit -m "A" &&
2101 test_expect_success '8a: Dual-directory rename, one into the others way' '
2108 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2110 git ls-files -s >out &&
2111 test_line_count = 6 out &&
2112 git ls-files -u >out &&
2113 test_line_count = 0 out &&
2114 git ls-files -o >out &&
2115 test_line_count = 1 out &&
2117 git rev-parse >actual \
2118 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2119 git rev-parse >expect \
2120 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2121 test_cmp expect actual
2125 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2126 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2127 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2128 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2130 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2131 # Currently expected: <same>
2132 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2133 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2135 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2136 # y, both are named 'e'. Without directory rename detection, neither file
2137 # moves directories. Implement directory rename detection suboptimally, and
2138 # you get an add/add conflict, but both files were added in commit A, so this
2139 # is an add/add conflict where one side of history added both files --
2140 # something we can't represent in the index. Obviously, we'd prefer the last
2141 # resolution, but our previous rules are too coarse to allow it. Using both
2142 # the rules from section 4 and section 5 save us from the Scary resolution,
2143 # making us fall back to pre-directory-rename-detection behavior for both
2147 test_create_repo 8b &&
2159 git commit -m "O" &&
2170 git commit -m "A" &&
2180 test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2187 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2189 git ls-files -s >out &&
2190 test_line_count = 6 out &&
2191 git ls-files -u >out &&
2192 test_line_count = 0 out &&
2193 git ls-files -o >out &&
2194 test_line_count = 1 out &&
2196 git rev-parse >actual \
2197 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2198 git rev-parse >expect \
2199 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2200 test_cmp expect actual
2204 # Testcase 8c, modify/delete or rename+modify/delete?
2205 # (Related to testcases 5b, 8d, and 9h)
2206 # Commit O: z/{b,c,d}
2208 # Commit B: z/{b,c,d_modified,e}
2209 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2211 # Note: It could easily be argued that the correct resolution here is
2212 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2213 # and that the modified version of d should be present in y/ after
2214 # the merge, just marked as conflicted. Indeed, I previously did
2215 # argue that. But applying directory renames to the side of
2216 # history where a file is merely modified results in spurious
2217 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2221 test_create_repo 8c &&
2228 test_seq 1 10 >z/d &&
2231 git commit -m "O" &&
2241 git commit -m "A" &&
2245 test_chmod +x z/d &&
2253 test_expect_success '8c: modify/delete or rename+modify/delete' '
2260 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2261 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2263 git ls-files -s >out &&
2264 test_line_count = 5 out &&
2265 git ls-files -u >out &&
2266 test_line_count = 2 out &&
2267 git ls-files -o >out &&
2268 test_line_count = 1 out &&
2270 git rev-parse >actual \
2271 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2272 git rev-parse >expect \
2273 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2274 test_cmp expect actual &&
2276 test_must_fail git rev-parse :2:z/d &&
2277 git ls-files -s z/d | grep ^100755 &&
2278 test_path_is_file z/d &&
2279 test_path_is_missing y/d
2283 # Testcase 8d, rename/delete...or not?
2284 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2285 # Also related to testcases 7d and 7e)
2286 # Commit O: z/{b,c,d}
2288 # Commit B: z/{b,c,d,e}
2289 # Expected: y/{b,c,e}
2291 # Note: It would also be somewhat reasonable to resolve this as
2292 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2294 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2295 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2296 # delete) are both coming from commit A, which is illogical. Conflicts
2297 # during merging are supposed to be about opposite sides doing things
2301 test_create_repo 8d &&
2308 test_seq 1 10 >z/d &&
2311 git commit -m "O" &&
2321 git commit -m "A" &&
2331 test_expect_success '8d: rename/delete...or not?' '
2338 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2340 git ls-files -s >out &&
2341 test_line_count = 3 out &&
2343 git rev-parse >actual \
2344 HEAD:y/b HEAD:y/c HEAD:y/e &&
2345 git rev-parse >expect \
2346 O:z/b O:z/c B:z/e &&
2347 test_cmp expect actual
2351 # Testcase 8e, Both sides rename, one side adds to original directory
2354 # Commit B: w/{b,c}, z/d
2356 # Possible Resolutions:
2357 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2358 # CONFLICT(z/c -> y/c vs. w/c)
2359 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2360 # CONFLICT(z/c -> y/c vs. w/c)
2363 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2364 # did NOT get renamed; the directory is still present; instead it is
2365 # considered to have just renamed a subset of paths in directory z
2366 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2367 # the original paths out of z/ but opted to keep d within z/).
2369 # It was not clear in the past what should be done with this testcase;
2370 # in fact, I noted that I "just picked one" previously. However,
2371 # following the new logic for testcase 6b2, we should take the rename
2372 # and move z/d to y/d.
2374 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2375 # whether they are optimal for end users, but (a) the default for
2376 # directory rename detection is to mark these all as conflicts
2377 # anyway, (b) it feels like this is less prone to higher order corner
2378 # case confusion, and (c) the current algorithm requires less global
2379 # knowledge (i.e. less coupling in the algorithm between renames done
2380 # on both sides) which thus means users are better able to predict
2381 # the behavior, and predict it without computing as many details.
2384 test_create_repo 8e &&
2393 git commit -m "O" &&
2402 git commit -m "A" &&
2414 test_expect_success '8e: Both sides rename, one side adds to original directory' '
2421 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2422 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2423 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2425 git ls-files -s >out &&
2426 test_line_count = 7 out &&
2427 git ls-files -u >out &&
2428 test_line_count = 6 out &&
2429 git ls-files -o >out &&
2430 test_line_count = 2 out &&
2432 git rev-parse >actual \
2433 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2434 git rev-parse >expect \
2435 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2436 test_cmp expect actual &&
2438 git hash-object >actual \
2440 git rev-parse >expect \
2441 O:z/b O:z/b O:z/c O:z/c &&
2442 test_cmp expect actual &&
2444 test_path_is_missing z/b &&
2445 test_path_is_missing z/c
2449 ###########################################################################
2450 # SECTION 9: Other testcases
2452 # This section consists of miscellaneous testcases I thought of during
2453 # the implementation which round out the testing.
2454 ###########################################################################
2456 # Testcase 9a, Inner renamed directory within outer renamed directory
2457 # (Related to testcase 1f)
2458 # Commit O: z/{b,c,d/{e,f,g}}
2459 # Commit A: y/{b,c}, x/w/{e,f,g}
2460 # Commit B: z/{b,c,d/{e,f,g,h},i}
2461 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2462 # NOTE: The only reason this one is interesting is because when a directory
2463 # is split into multiple other directories, we determine by the weight
2464 # of which one had the most paths going to it. A naive implementation
2465 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2468 test_create_repo 9a &&
2480 git commit -m "O" &&
2491 git commit -m "A" &&
2502 test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2509 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2511 git ls-files -s >out &&
2512 test_line_count = 7 out &&
2513 git ls-files -u >out &&
2514 test_line_count = 0 out &&
2515 git ls-files -o >out &&
2516 test_line_count = 1 out &&
2518 git rev-parse >actual \
2519 HEAD:y/b HEAD:y/c HEAD:y/i &&
2520 git rev-parse >expect \
2521 O:z/b O:z/c B:z/i &&
2522 test_cmp expect actual &&
2524 git rev-parse >actual \
2525 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2526 git rev-parse >expect \
2527 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2528 test_cmp expect actual
2532 # Testcase 9b, Transitive rename with content merge
2533 # (Related to testcase 1c)
2534 # Commit O: z/{b,c}, x/d_1
2535 # Commit A: y/{b,c}, x/d_2
2536 # Commit B: z/{b,c,d_3}
2537 # Expected: y/{b,c,d_merged}
2540 test_create_repo 9b &&
2548 test_seq 1 10 >x/d &&
2551 git commit -m "O" &&
2559 test_seq 1 11 >x/d &&
2562 git commit -m "A" &&
2565 test_seq 0 10 >x/d &&
2573 test_expect_success '9b: Transitive rename with content merge' '
2580 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2582 git ls-files -s >out &&
2583 test_line_count = 3 out &&
2585 test_seq 0 11 >expected &&
2586 test_cmp expected y/d &&
2588 git rev-parse >actual \
2589 HEAD:y/b HEAD:y/c HEAD:y/d &&
2590 git rev-parse >expect \
2591 O:z/b O:z/c :0:expected &&
2592 test_cmp expect actual &&
2593 test_must_fail git rev-parse HEAD:x/d &&
2594 test_must_fail git rev-parse HEAD:z/d &&
2595 test_path_is_missing z/d &&
2597 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2598 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2599 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2603 # Testcase 9c, Doubly transitive rename?
2604 # (Related to testcase 1c, 7e, and 9d)
2605 # Commit O: z/{b,c}, x/{d,e}, w/f
2606 # Commit A: y/{b,c}, x/{d,e,f,g}
2607 # Commit B: z/{b,c,d,e}, w/f
2608 # Expected: y/{b,c,d,e}, x/{f,g}
2610 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2611 # x/f is clear. Let's look beyond that. Here's the logic:
2612 # Commit B renamed x/ -> z/
2613 # Commit A renamed z/ -> y/
2614 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2615 # transient rename. However, where does it end? We can chain these
2616 # indefinitely (see testcase 9d). What if there is a D/F conflict
2617 # at z/f/ or y/f/? Or just another file conflict at one of those
2618 # paths? In the case of an N-long chain of transient renamings,
2619 # where do we "abort" the rename at? Can the user make sense of
2620 # the resulting conflict and resolve it?
2622 # To avoid this confusion I use the simple rule that if the other side
2623 # of history did a directory rename to a path that your side renamed
2624 # away, then ignore that particular rename from the other side of
2625 # history for any implicit directory renames.
2628 test_create_repo 9c &&
2642 git commit -m "O" &&
2654 git commit -m "A" &&
2664 test_expect_success '9c: Doubly transitive rename?' '
2671 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2672 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2674 git ls-files -s >out &&
2675 test_line_count = 6 out &&
2676 git ls-files -o >out &&
2677 test_line_count = 1 out &&
2679 git rev-parse >actual \
2680 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2681 git rev-parse >expect \
2682 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2683 test_cmp expect actual
2687 # Testcase 9d, N-fold transitive rename?
2688 # (Related to testcase 9c...and 1c and 7e)
2689 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2690 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2691 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2692 # Expected: <see NOTE first>
2694 # NOTE: z/ -> y/ (in commit A)
2695 # y/ -> x/ (in commit B)
2696 # x/ -> w/ (in commit A)
2697 # w/ -> v/ (in commit B)
2698 # v/ -> u/ (in commit A)
2699 # So, if we add a file to z, say z/t, where should it end up? In u?
2700 # What if there's another file or directory named 't' in one of the
2701 # intervening directories and/or in u itself? Also, shouldn't the
2702 # same logic that places 't' in u/ also move ALL other files to u/?
2703 # What if there are file or directory conflicts in any of them? If
2704 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2705 # like this, would the user have any hope of understanding any
2706 # conflicts or how their working tree ended up? I think not, so I'm
2707 # ruling out N-ary transitive renames for N>1.
2709 # Therefore our expected result is:
2710 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2711 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2712 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2713 # simple rules that are consistent with what we need for all the other
2714 # testcases and simplifies things for the user.
2717 test_create_repo 9d &&
2721 mkdir z y x w v u &&
2728 git add z y x w v u &&
2730 git commit -m "O" &&
2741 git commit -m "A" &&
2753 test_expect_success '9d: N-way transitive rename?' '
2760 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2761 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2762 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2763 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2764 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2766 git ls-files -s >out &&
2767 test_line_count = 7 out &&
2768 git ls-files -o >out &&
2769 test_line_count = 1 out &&
2771 git rev-parse >actual \
2773 HEAD:y/a HEAD:x/b HEAD:w/c \
2774 HEAD:u/d HEAD:u/e HEAD:u/f &&
2775 git rev-parse >expect \
2778 O:w/d O:v/e A:u/f &&
2779 test_cmp expect actual
2783 # Testcase 9e, N-to-1 whammo
2784 # (Related to testcase 9c...and 1c and 7e)
2785 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2786 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2787 # Commit B: combined/{a,b,d,e,g,h,j,k}
2788 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2789 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2792 test_create_repo 9e &&
2796 mkdir dir1 dir2 dir3 dirN &&
2807 git commit -m "O" &&
2824 git commit -m "A" &&
2827 git mv dir1 combined &&
2828 git mv dir2/* combined/ &&
2829 git mv dir3/* combined/ &&
2830 git mv dirN/* combined/ &&
2836 test_expect_success C_LOCALE_OUTPUT '9e: N-to-1 whammo' '
2843 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2844 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2845 grep -q dir1/yo error_line &&
2846 grep -q dir2/yo error_line &&
2847 grep -q dir3/yo error_line &&
2848 grep -q dirN/yo error_line &&
2850 git ls-files -s >out &&
2851 test_line_count = 16 out &&
2852 git ls-files -u >out &&
2853 test_line_count = 0 out &&
2854 git ls-files -o >out &&
2855 test_line_count = 2 out &&
2857 git rev-parse >actual \
2858 :0:combined/a :0:combined/b :0:combined/c \
2859 :0:combined/d :0:combined/e :0:combined/f \
2860 :0:combined/g :0:combined/h :0:combined/i \
2861 :0:combined/j :0:combined/k :0:combined/l &&
2862 git rev-parse >expect \
2863 O:dir1/a O:dir1/b A:dir1/c \
2864 O:dir2/d O:dir2/e A:dir2/f \
2865 O:dir3/g O:dir3/h A:dir3/i \
2866 O:dirN/j O:dirN/k A:dirN/l &&
2867 test_cmp expect actual &&
2869 git rev-parse >actual \
2870 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2871 git rev-parse >expect \
2872 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2873 test_cmp expect actual
2877 # Testcase 9f, Renamed directory that only contained immediate subdirs
2878 # (Related to testcases 1e & 9g)
2879 # Commit O: goal/{a,b}/$more_files
2880 # Commit A: priority/{a,b}/$more_files
2881 # Commit B: goal/{a,b}/$more_files, goal/c
2882 # Expected: priority/{a,b}/$more_files, priority/c
2885 test_create_repo 9f &&
2891 echo foo >goal/a/foo &&
2892 echo bar >goal/b/bar &&
2893 echo baz >goal/b/baz &&
2896 git commit -m "O" &&
2903 git mv goal/ priority &&
2905 git commit -m "A" &&
2915 test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2922 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2924 git ls-files -s >out &&
2925 test_line_count = 4 out &&
2927 git rev-parse >actual \
2928 HEAD:priority/a/foo \
2929 HEAD:priority/b/bar \
2930 HEAD:priority/b/baz \
2932 git rev-parse >expect \
2937 test_cmp expect actual &&
2938 test_must_fail git rev-parse HEAD:goal/c
2942 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2943 # (Related to testcases 1e & 9f)
2944 # Commit O: goal/{a,b}/$more_files
2945 # Commit A: priority/{alpha,bravo}/$more_files
2946 # Commit B: goal/{a,b}/$more_files, goal/c
2947 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2948 # We currently fail this test because the directory renames we detect are
2949 # goal/a/ -> priority/alpha/
2950 # goal/b/ -> priority/bravo/
2952 # goal/ -> priority/
2953 # because of no files found within goal/, and the fact that "a" != "alpha"
2954 # and "b" != "bravo". But I'm not sure it's really a failure given that
2958 test_create_repo 9g &&
2964 echo foo >goal/a/foo &&
2965 echo bar >goal/b/bar &&
2966 echo baz >goal/b/baz &&
2969 git commit -m "O" &&
2977 git mv goal/a/ priority/alpha &&
2978 git mv goal/b/ priority/beta &&
2981 git commit -m "A" &&
2991 test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2998 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3000 git ls-files -s >out &&
3001 test_line_count = 4 out &&
3003 git rev-parse >actual \
3004 HEAD:priority/alpha/foo \
3005 HEAD:priority/beta/bar \
3006 HEAD:priority/beta/baz \
3008 git rev-parse >expect \
3013 test_cmp expect actual &&
3014 test_must_fail git rev-parse HEAD:goal/c
3018 # Testcase 9h, Avoid implicit rename if involved as source on other side
3019 # (Extremely closely related to testcase 3a)
3020 # Commit O: z/{b,c,d_1}
3021 # Commit A: z/{b,c,d_2}
3022 # Commit B: y/{b,c}, x/d_1
3023 # Expected: y/{b,c}, x/d_2
3024 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3025 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3027 test_create_repo 9h &&
3034 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
3037 git commit -m "O" &&
3047 git commit -m "A" &&
3061 test_expect_success '9h: Avoid dir rename on merely modified path' '
3068 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3070 git ls-files -s >out &&
3071 test_line_count = 3 out &&
3073 git rev-parse >actual \
3074 HEAD:y/b HEAD:y/c HEAD:x/d &&
3075 git rev-parse >expect \
3076 O:z/b O:z/c A:z/d &&
3077 test_cmp expect actual
3081 ###########################################################################
3082 # Rules suggested by section 9:
3084 # If the other side of history did a directory rename to a path that your
3085 # side renamed away, then ignore that particular rename from the other
3086 # side of history for any implicit directory renames.
3087 ###########################################################################
3089 ###########################################################################
3090 # SECTION 10: Handling untracked files
3092 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3093 # the operation if untracked or dirty files would be deleted or overwritten
3094 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3095 # and if it doesn't abort, then it muddies up the working directory before
3096 # we even get to the point of detecting renames, so we need some special
3097 # handling, at least in the case of directory renames.
3098 ###########################################################################
3100 # Testcase 10a, Overwrite untracked: normal rename/delete
3101 # Commit O: z/{b,c_1}
3102 # Commit A: z/b + untracked z/c + untracked z/d
3103 # Commit B: z/{b,d_1}
3104 # Expected: Aborted Merge +
3105 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3108 test_create_repo 10a &&
3117 git commit -m "O" &&
3126 git commit -m "A" &&
3135 test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3142 echo important >z/d &&
3144 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3145 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3147 git ls-files -s >out &&
3148 test_line_count = 1 out &&
3149 git ls-files -o >out &&
3150 test_line_count = 4 out &&
3152 echo very >expect &&
3153 test_cmp expect z/c &&
3155 echo important >expect &&
3156 test_cmp expect z/d &&
3158 git rev-parse HEAD:z/b >actual &&
3159 git rev-parse O:z/b >expect &&
3160 test_cmp expect actual
3164 # Testcase 10b, Overwrite untracked: dir rename + delete
3165 # Commit O: z/{b,c_1}
3166 # Commit A: y/b + untracked y/{c,d,e}
3167 # Commit B: z/{b,d_1,e}
3168 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3169 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3170 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3173 test_create_repo 10b &&
3182 git commit -m "O" &&
3192 git commit -m "A" &&
3203 test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3210 echo important >y/d &&
3211 echo contents >y/e &&
3213 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3214 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3215 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3217 git ls-files -s >out &&
3218 test_line_count = 3 out &&
3219 git ls-files -u >out &&
3220 test_line_count = 2 out &&
3221 git ls-files -o >out &&
3222 test_line_count = 5 out &&
3224 git rev-parse >actual \
3225 :0:y/b :3:y/d :3:y/e &&
3226 git rev-parse >expect \
3227 O:z/b O:z/c B:z/e &&
3228 test_cmp expect actual &&
3230 echo very >expect &&
3231 test_cmp expect y/c &&
3233 echo important >expect &&
3234 test_cmp expect y/d &&
3236 echo contents >expect &&
3241 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3242 # Commit O: z/{a,b}, x/{c,d}
3243 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3244 # Commit B: z/{a,b,c}, x/d
3245 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3246 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3248 # ERROR_MSG(Refusing to lose untracked file at y/c)
3251 test_create_repo 10c_$1 &&
3262 git commit -m "O" &&
3273 git commit -m "A" &&
3282 test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3288 echo important >y/c &&
3290 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3291 test_i18ngrep "CONFLICT (rename/rename)" out &&
3292 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3294 git ls-files -s >out &&
3295 test_line_count = 6 out &&
3296 git ls-files -u >out &&
3297 test_line_count = 3 out &&
3298 git ls-files -o >out &&
3299 test_line_count = 3 out &&
3301 git rev-parse >actual \
3302 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3303 git rev-parse >expect \
3304 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3305 test_cmp expect actual &&
3307 git hash-object y/c~B^0 >actual &&
3308 git rev-parse O:x/c >expect &&
3309 test_cmp expect actual &&
3311 echo important >expect &&
3316 test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3326 echo important >y/c &&
3328 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3329 test_i18ngrep "CONFLICT (rename/rename)" out &&
3330 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3332 git ls-files -s >out &&
3333 test_line_count = 6 out &&
3334 git ls-files -u >out &&
3335 test_line_count = 3 out &&
3336 git ls-files -o >out &&
3337 test_line_count = 3 out &&
3339 git rev-parse >actual \
3340 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3341 git rev-parse >expect \
3342 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3343 test_cmp expect actual &&
3345 git hash-object y/c~HEAD >actual &&
3346 git rev-parse O:x/c >expect &&
3347 test_cmp expect actual &&
3349 echo important >expect &&
3354 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3355 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3356 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3357 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3358 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3359 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3360 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3363 test_create_repo 10d &&
3376 git commit -m "O" &&
3383 git mv z/c x/wham &&
3386 git commit -m "A" &&
3389 git mv x/f z/wham &&
3396 test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3402 echo important >y/wham &&
3404 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3405 test_i18ngrep "CONFLICT (rename/rename)" out &&
3406 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3408 git ls-files -s >out &&
3409 test_line_count = 6 out &&
3410 git ls-files -u >out &&
3411 test_line_count = 2 out &&
3412 git ls-files -o >out &&
3413 test_line_count = 3 out &&
3415 git rev-parse >actual \
3416 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3417 git rev-parse >expect \
3418 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3419 test_cmp expect actual &&
3421 test_must_fail git rev-parse :1:y/wham &&
3423 echo important >expect &&
3424 test_cmp expect y/wham &&
3426 # Test that the two-way merge in y/wham~merged is as expected
3427 git cat-file -p :2:y/wham >expect &&
3428 git cat-file -p :3:y/wham >other &&
3430 test_must_fail git merge-file \
3434 expect empty other &&
3435 test_cmp expect y/wham~merged
3439 # Testcase 10e, Does git complain about untracked file that's not in the way?
3441 # Commit A: y/{a,b} + untracked z/c
3442 # Commit B: z/{a,b,c}
3443 # Expected: y/{a,b,c} + untracked z/c
3446 test_create_repo 10e &&
3455 git commit -m "O" &&
3464 git commit -m "A" &&
3474 test_expect_failure '10e: Does git complain about untracked file that is not really in the way?' '
3483 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3484 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3486 git ls-files -s >out &&
3487 test_line_count = 3 out &&
3488 git ls-files -u >out &&
3489 test_line_count = 0 out &&
3490 git ls-files -o >out &&
3491 test_line_count = 3 out &&
3493 git rev-parse >actual \
3494 :0:y/a :0:y/b :0:y/c &&
3495 git rev-parse >expect \
3496 O:z/a O:z/b B:z/c &&
3497 test_cmp expect actual &&
3499 echo random >expect &&
3504 ###########################################################################
3505 # SECTION 11: Handling dirty (not up-to-date) files
3507 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3508 # the operation if untracked or dirty files would be deleted or overwritten
3509 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3510 # and if it doesn't abort, then it muddies up the working directory before
3511 # we even get to the point of detecting renames, so we need some special
3512 # handling. This was true even of normal renames, but there are additional
3513 # codepaths that need special handling with directory renames. Add
3514 # testcases for both renamed-by-directory-rename-detection and standard
3516 ###########################################################################
3518 # Testcase 11a, Avoid losing dirty contents with simple rename
3519 # Commit O: z/{a,b_v1},
3520 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3521 # Commit B: z/{a,b_v2}
3522 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3523 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3524 # z/c~HEAD with contents of B:z/b_v2,
3525 # z/c with uncommitted mods on top of A:z/c_v1
3528 test_create_repo 11a &&
3534 test_seq 1 10 >z/b &&
3537 git commit -m "O" &&
3546 git commit -m "A" &&
3556 test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3564 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3565 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3567 test_seq 1 10 >expected &&
3568 echo stuff >>expected &&
3569 test_cmp expected z/c &&
3571 git ls-files -s >out &&
3572 test_line_count = 2 out &&
3573 git ls-files -u >out &&
3574 test_line_count = 1 out &&
3575 git ls-files -o >out &&
3576 test_line_count = 4 out &&
3578 git rev-parse >actual \
3580 git rev-parse >expect \
3582 test_cmp expect actual &&
3584 git hash-object z/c~HEAD >actual &&
3585 git rev-parse B:z/b >expect &&
3586 test_cmp expect actual
3590 # Testcase 11b, Avoid losing dirty file involved in directory rename
3591 # Commit O: z/a, x/{b,c_v1}
3592 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3593 # Commit B: y/a, x/{b,c_v2}
3594 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3595 # ERROR_MSG(Refusing to lose dirty file at z/c)
3599 test_create_repo 11b &&
3606 test_seq 1 10 >x/c &&
3609 git commit -m "O" &&
3618 git commit -m "A" &&
3629 test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3637 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3638 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3640 grep -q stuff z/c &&
3641 test_seq 1 10 >expected &&
3642 echo stuff >>expected &&
3643 test_cmp expected z/c &&
3645 git ls-files -s >out &&
3646 test_line_count = 3 out &&
3647 git ls-files -u >out &&
3648 test_line_count = 0 out &&
3649 git ls-files -m >out &&
3650 test_line_count = 0 out &&
3651 git ls-files -o >out &&
3652 test_line_count = 4 out &&
3654 git rev-parse >actual \
3655 :0:x/b :0:y/a :0:y/c &&
3656 git rev-parse >expect \
3657 O:x/b O:z/a B:x/c &&
3658 test_cmp expect actual &&
3660 git hash-object y/c >actual &&
3661 git rev-parse B:x/c >expect &&
3662 test_cmp expect actual
3666 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3667 # Commit O: y/a, x/{b,c_v1}
3668 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3669 # Commit B: y/{a,c/d}, x/{b,c_v2}
3670 # Expected: Abort_msg("following files would be overwritten by merge") +
3671 # y/c left untouched (still has uncommitted mods)
3674 test_create_repo 11c &&
3681 test_seq 1 10 >x/c &&
3684 git commit -m "O" &&
3693 git commit -m "A" &&
3699 git add x/c y/c/d &&
3705 test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3713 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3714 test_i18ngrep "following files would be overwritten by merge" err &&
3716 grep -q stuff y/c &&
3717 test_seq 1 10 >expected &&
3718 echo stuff >>expected &&
3719 test_cmp expected y/c &&
3721 git ls-files -s >out &&
3722 test_line_count = 3 out &&
3723 git ls-files -u >out &&
3724 test_line_count = 0 out &&
3725 git ls-files -m >out &&
3726 test_line_count = 1 out &&
3727 git ls-files -o >out &&
3728 test_line_count = 3 out
3732 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3733 # Commit O: z/a, x/{b,c_v1}
3734 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3735 # Commit B: y/{a,c/d}, x/{b,c_v2}
3736 # Expected: D/F: y/c_v2 vs y/c/d) +
3737 # Warning_Msg("Refusing to lose dirty file at z/c) +
3738 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3741 test_create_repo 11d &&
3748 test_seq 1 10 >x/c &&
3751 git commit -m "O" &&
3760 git commit -m "A" &&
3767 git add x/c y/c/d &&
3773 test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3781 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3782 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3784 grep -q stuff z/c &&
3785 test_seq 1 10 >expected &&
3786 echo stuff >>expected &&
3787 test_cmp expected z/c &&
3789 git ls-files -s >out &&
3790 test_line_count = 4 out &&
3791 git ls-files -u >out &&
3792 test_line_count = 1 out &&
3793 git ls-files -o >out &&
3794 test_line_count = 5 out &&
3796 git rev-parse >actual \
3797 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3798 git rev-parse >expect \
3799 O:x/b O:z/a B:y/c/d B:x/c &&
3800 test_cmp expect actual &&
3802 git hash-object y/c~HEAD >actual &&
3803 git rev-parse B:x/c >expect &&
3804 test_cmp expect actual
3808 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3809 # Commit O: z/{a,b}, x/{c_1,d}
3810 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3811 # Commit B: z/{a,b,c_1}, x/d
3812 # Expected: Failed Merge; y/{a,b} + x/d +
3813 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3814 # ERROR_MSG(Refusing to lose dirty file at y/c)
3815 # y/c~B^0 has O:x/c_1 contents
3816 # y/c~HEAD has A:y/c_2 contents
3817 # y/c has dirty file from before merge
3820 test_create_repo 11e &&
3831 git commit -m "O" &&
3839 echo different >y/c &&
3844 git commit -m "A" &&
3853 test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3861 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3862 test_i18ngrep "CONFLICT (rename/rename)" out &&
3863 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3865 git ls-files -s >out &&
3866 test_line_count = 7 out &&
3867 git ls-files -u >out &&
3868 test_line_count = 4 out &&
3869 git ls-files -o >out &&
3870 test_line_count = 3 out &&
3872 echo different >expected &&
3873 echo mods >>expected &&
3874 test_cmp expected y/c &&
3876 git rev-parse >actual \
3877 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3878 git rev-parse >expect \
3879 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3880 test_cmp expect actual &&
3882 # See if y/c~merged has expected contents; requires manually
3883 # doing the expected file merge
3884 git cat-file -p A:y/c >c1 &&
3885 git cat-file -p B:z/c >c2 &&
3887 test_must_fail git merge-file \
3892 test_cmp c1 y/c~merged
3896 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3897 # Commit O: z/{a,b}, x/{c_1,d_2}
3898 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3899 # Commit B: z/{a,b,wham_2}, x/c_1
3900 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
3901 # y/wham with dirty changes from before merge +
3902 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3903 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3906 test_create_repo 11f &&
3913 test_seq 1 10 >x/c &&
3917 git commit -m "O" &&
3925 git mv x/c y/wham &&
3927 git commit -m "A" &&
3930 git mv x/d z/wham &&
3936 test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3942 echo important >>y/wham &&
3944 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3945 test_i18ngrep "CONFLICT (rename/rename)" out &&
3946 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3948 git ls-files -s >out &&
3949 test_line_count = 4 out &&
3950 git ls-files -u >out &&
3951 test_line_count = 2 out &&
3952 git ls-files -o >out &&
3953 test_line_count = 3 out &&
3955 test_seq 1 10 >expected &&
3956 echo important >>expected &&
3957 test_cmp expected y/wham &&
3959 test_must_fail git rev-parse :1:y/wham &&
3961 git rev-parse >actual \
3962 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3963 git rev-parse >expect \
3964 O:z/a O:z/b O:x/c O:x/d &&
3965 test_cmp expect actual &&
3967 # Test that the two-way merge in y/wham~merged is as expected
3968 git cat-file -p :2:y/wham >expect &&
3969 git cat-file -p :3:y/wham >other &&
3971 test_must_fail git merge-file \
3975 expect empty other &&
3976 test_cmp expect y/wham~merged
3980 ###########################################################################
3981 # SECTION 12: Everything else
3983 # Tests suggested by others. Tests added after implementation completed
3984 # and submitted. Grab bag.
3985 ###########################################################################
3987 # Testcase 12a, Moving one directory hierarchy into another
3988 # (Related to testcase 9a)
3989 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3990 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3991 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3992 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3995 test_create_repo 12a &&
3999 mkdir -p node1 node2 &&
4000 echo leaf1 >node1/leaf1 &&
4001 echo leaf2 >node1/leaf2 &&
4002 echo leaf3 >node2/leaf3 &&
4003 echo leaf4 >node2/leaf4 &&
4004 git add node1 node2 &&
4006 git commit -m "O" &&
4013 git mv node2/ node1/ &&
4015 git commit -m "A" &&
4018 echo leaf5 >node1/leaf5 &&
4019 echo leaf6 >node2/leaf6 &&
4020 git add node1 node2 &&
4026 test_expect_success '12a: Moving one directory hierarchy into another' '
4033 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4035 git ls-files -s >out &&
4036 test_line_count = 6 out &&
4038 git rev-parse >actual \
4039 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4040 HEAD:node1/node2/leaf3 \
4041 HEAD:node1/node2/leaf4 \
4042 HEAD:node1/node2/leaf6 &&
4043 git rev-parse >expect \
4044 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4048 test_cmp expect actual
4052 # Testcase 12b1, Moving two directory hierarchies into each other
4053 # (Related to testcases 1c and 12c)
4054 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4055 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4056 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4057 # Expected: node1/node2/{leaf3, leaf4}
4058 # node2/node1/{leaf1, leaf2}
4059 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4060 # then we would need to detect renames for those directories and would
4062 # commit A renames node2/ -> node1/node2/
4063 # commit B renames node1/ -> node2/node1/
4064 # Applying those directory renames to the initial result (making all
4065 # four paths experience a transitive renaming), yields
4066 # node1/node2/node1/{leaf1, leaf2}
4067 # node2/node1/node2/{leaf3, leaf4}
4068 # as the result. It may be really weird to have two directories
4069 # rename each other, but simple rules give weird results when given
4070 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4071 # false; there were no new files added and thus there is no directory
4072 # rename detection to perform. As such, we just have simple renames
4073 # and the expected answer is:
4074 # node1/node2/{leaf3, leaf4}
4075 # node2/node1/{leaf1, leaf2}
4077 test_setup_12b1 () {
4078 test_create_repo 12b1 &&
4082 mkdir -p node1 node2 &&
4083 echo leaf1 >node1/leaf1 &&
4084 echo leaf2 >node1/leaf2 &&
4085 echo leaf3 >node2/leaf3 &&
4086 echo leaf4 >node2/leaf4 &&
4087 git add node1 node2 &&
4089 git commit -m "O" &&
4096 git mv node2/ node1/ &&
4098 git commit -m "A" &&
4101 git mv node1/ node2/ &&
4107 test_expect_failure '12b1: Moving two directory hierarchies into each other' '
4114 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4116 git ls-files -s >out &&
4117 test_line_count = 4 out &&
4119 git rev-parse >actual \
4120 HEAD:node2/node1/leaf1 \
4121 HEAD:node2/node1/leaf2 \
4122 HEAD:node1/node2/leaf3 \
4123 HEAD:node1/node2/leaf4 &&
4124 git rev-parse >expect \
4129 test_cmp expect actual
4133 # Testcase 12b2, Moving two directory hierarchies into each other
4134 # (Related to testcases 1c and 12c)
4135 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4136 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4137 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4138 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4139 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4140 # NOTE: Without directory renames, we would expect
4141 # A: node2/leaf3 -> node1/node2/leaf3
4142 # A: node2/leaf1 -> node1/node2/leaf4
4143 # A: Adds node1/leaf5
4144 # B: node1/leaf1 -> node2/node1/leaf1
4145 # B: node1/leaf2 -> node2/node1/leaf2
4146 # B: Adds node2/leaf6
4147 # with directory rename detection, we note that
4148 # commit A renames node2/ -> node1/node2/
4149 # commit B renames node1/ -> node2/node1/
4150 # therefore, applying A's directory rename to the paths added in B gives:
4151 # B: node1/leaf1 -> node1/node2/node1/leaf1
4152 # B: node1/leaf2 -> node1/node2/node1/leaf2
4153 # B: Adds node1/node2/leaf6
4154 # and applying B's directory rename to the paths added in A gives:
4155 # A: node2/leaf3 -> node2/node1/node2/leaf3
4156 # A: node2/leaf1 -> node2/node1/node2/leaf4
4157 # A: Adds node2/node1/leaf5
4158 # resulting in the expected
4159 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4160 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4162 # You may ask, is it weird to have two directories rename each other?
4163 # To which, I can do no more than shrug my shoulders and say that
4164 # even simple rules give weird results when given weird inputs.
4166 test_setup_12b2 () {
4167 test_create_repo 12b2 &&
4171 mkdir -p node1 node2 &&
4172 echo leaf1 >node1/leaf1 &&
4173 echo leaf2 >node1/leaf2 &&
4174 echo leaf3 >node2/leaf3 &&
4175 echo leaf4 >node2/leaf4 &&
4176 git add node1 node2 &&
4178 git commit -m "O" &&
4185 git mv node2/ node1/ &&
4186 echo leaf5 >node1/leaf5 &&
4187 git add node1/leaf5 &&
4189 git commit -m "A" &&
4192 git mv node1/ node2/ &&
4193 echo leaf6 >node2/leaf6 &&
4194 git add node2/leaf6 &&
4200 test_expect_success '12b2: Moving two directory hierarchies into each other' '
4207 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4209 git ls-files -s >out &&
4210 test_line_count = 6 out &&
4212 git rev-parse >actual \
4213 HEAD:node1/node2/node1/leaf1 \
4214 HEAD:node1/node2/node1/leaf2 \
4215 HEAD:node2/node1/node2/leaf3 \
4216 HEAD:node2/node1/node2/leaf4 \
4217 HEAD:node2/node1/leaf5 \
4218 HEAD:node1/node2/leaf6 &&
4219 git rev-parse >expect \
4226 test_cmp expect actual
4230 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4231 # (Related to testcase 12b)
4232 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4233 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4234 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4235 # Expected: Content merge conflicts for each of:
4236 # node1/node2/node1/{leaf1, leaf2},
4237 # node2/node1/node2/{leaf3, leaf4}
4238 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4239 # each side of the merge.
4241 test_setup_12c1 () {
4242 test_create_repo 12c1 &&
4246 mkdir -p node1 node2 &&
4247 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4248 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4249 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4250 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4251 git add node1 node2 &&
4253 git commit -m "O" &&
4260 git mv node2/ node1/ &&
4261 for i in `git ls-files`; do echo side A >>$i; done &&
4264 git commit -m "A" &&
4267 git mv node1/ node2/ &&
4268 for i in `git ls-files`; do echo side B >>$i; done &&
4275 test_expect_failure '12c1: Moving one directory hierarchy into another w/ content merge' '
4282 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4284 git ls-files -u >out &&
4285 test_line_count = 12 out &&
4287 git rev-parse >actual \
4288 :1:node2/node1/leaf1 \
4289 :1:node2/node1/leaf2 \
4290 :1:node1/node2/leaf3 \
4291 :1:node1/node2/leaf4 \
4292 :2:node2/node1/leaf1 \
4293 :2:node2/node1/leaf2 \
4294 :2:node1/node2/leaf3 \
4295 :2:node1/node2/leaf4 \
4296 :3:node2/node1/leaf1 \
4297 :3:node2/node1/leaf2 \
4298 :3:node1/node2/leaf3 \
4299 :3:node1/node2/leaf4 &&
4300 git rev-parse >expect \
4307 A:node1/node2/leaf3 \
4308 A:node1/node2/leaf4 \
4309 B:node2/node1/leaf1 \
4310 B:node2/node1/leaf2 \
4313 test_cmp expect actual
4317 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4318 # (Related to testcase 12b)
4319 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4320 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4321 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4322 # Expected: Content merge conflicts for each of:
4323 # node1/node2/node1/{leaf1, leaf2}
4324 # node2/node1/node2/{leaf3, leaf4}
4328 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4329 # on each side of the merge.
4331 test_setup_12c2 () {
4332 test_create_repo 12c2 &&
4336 mkdir -p node1 node2 &&
4337 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4338 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4339 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4340 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4341 git add node1 node2 &&
4343 git commit -m "O" &&
4350 git mv node2/ node1/ &&
4351 for i in `git ls-files`; do echo side A >>$i; done &&
4353 echo leaf5 >node1/leaf5 &&
4354 git add node1/leaf5 &&
4356 git commit -m "A" &&
4359 git mv node1/ node2/ &&
4360 for i in `git ls-files`; do echo side B >>$i; done &&
4362 echo leaf6 >node2/leaf6 &&
4363 git add node2/leaf6 &&
4369 test_expect_success '12c2: Moving one directory hierarchy into another w/ content merge' '
4376 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4378 git ls-files -s >out &&
4379 test_line_count = 14 out &&
4380 git ls-files -u >out &&
4381 test_line_count = 12 out &&
4383 git rev-parse >actual \
4384 :1:node1/node2/node1/leaf1 \
4385 :1:node1/node2/node1/leaf2 \
4386 :1:node2/node1/node2/leaf3 \
4387 :1:node2/node1/node2/leaf4 \
4388 :2:node1/node2/node1/leaf1 \
4389 :2:node1/node2/node1/leaf2 \
4390 :2:node2/node1/node2/leaf3 \
4391 :2:node2/node1/node2/leaf4 \
4392 :3:node1/node2/node1/leaf1 \
4393 :3:node1/node2/node1/leaf2 \
4394 :3:node2/node1/node2/leaf3 \
4395 :3:node2/node1/node2/leaf4 \
4396 :0:node2/node1/leaf5 \
4397 :0:node1/node2/leaf6 &&
4398 git rev-parse >expect \
4405 A:node1/node2/leaf3 \
4406 A:node1/node2/leaf4 \
4407 B:node2/node1/leaf1 \
4408 B:node2/node1/leaf2 \
4413 test_cmp expect actual
4417 # Testcase 12d, Rename/merge of subdirectory into the root
4418 # Commit O: a/b/subdir/foo
4419 # Commit A: subdir/foo
4420 # Commit B: a/b/subdir/foo, a/b/bar
4421 # Expected: subdir/foo, bar
4424 test_create_repo 12d &&
4428 mkdir -p a/b/subdir &&
4429 test_commit a/b/subdir/foo &&
4437 git mv a/b/subdir/foo.t subdir/foo.t &&
4439 git commit -m "A" &&
4446 test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4453 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4455 git ls-files -s >out &&
4456 test_line_count = 2 out &&
4458 git rev-parse >actual \
4459 HEAD:subdir/foo.t HEAD:bar.t &&
4460 git rev-parse >expect \
4461 O:a/b/subdir/foo.t B:a/b/bar.t &&
4462 test_cmp expect actual &&
4464 git hash-object bar.t >actual &&
4465 git rev-parse B:a/b/bar.t >expect &&
4466 test_cmp expect actual &&
4468 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4469 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4470 test_path_is_missing a/ &&
4471 test_path_is_file bar.t
4475 # Testcase 12e, Rename/merge of subdirectory into the root
4478 # Commit B: a/b/foo, a/b/bar
4479 # Expected: foo, bar
4482 test_create_repo 12e &&
4487 test_commit a/b/foo &&
4495 git mv a/b/foo.t foo.t &&
4497 git commit -m "A" &&
4504 test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4511 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4513 git ls-files -s >out &&
4514 test_line_count = 2 out &&
4516 git rev-parse >actual \
4517 HEAD:foo.t HEAD:bar.t &&
4518 git rev-parse >expect \
4519 O:a/b/foo.t B:a/b/bar.t &&
4520 test_cmp expect actual &&
4522 git hash-object bar.t >actual &&
4523 git rev-parse B:a/b/bar.t >expect &&
4524 test_cmp expect actual &&
4526 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4527 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4528 test_path_is_missing a/ &&
4529 test_path_is_file bar.t
4533 # Testcase 12f, Rebase of patches with big directory rename
4535 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4536 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4537 # dir/unchanged/<LOTS OF FILES>
4539 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4540 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4541 # folder/subdir/newsubdir/e_A
4542 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4543 # folder/unchanged/<LOTS OF FILES>
4545 # (add newfile.{c,py}, modify underscored files)
4546 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4547 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4548 # dir/unchanged/<LOTS OF FILES>
4550 # (Modify e further, add newfile.rs)
4551 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4552 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4553 # dir/unchanged/<LOTS OF FILES>
4556 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4557 # folder/subdir/newsubdir/e_Merge1
4558 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4559 # folder/unchanged/<LOTS OF FILES>
4561 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4562 # folder/subdir/newsubdir/e_Merge2
4563 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4564 # folder/unchanged/<LOTS OF FILES>
4566 # Notes: This testcase happens to exercise lots of the
4567 # optimization-specific codepaths in merge-ort, and also
4568 # demonstrated a failing of the directory rename detection algorithm
4569 # in merge-recursive; newfile.c should not get pushed into
4570 # folder/subdir/newsubdir/, yet merge-recursive put it there because
4571 # the rename of dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d}
4574 # whereas the rename of dir/subdir/e -> folder/subdir/newsubdir/e
4576 # dir/subdir/ -> folder/subdir/newsubdir/
4577 # and if we note that newfile.c is found in dir/subdir/, we might
4578 # overlook the dir/ -> folder/ rule that has more weight.
4581 test_create_repo 12f &&
4585 mkdir -p dir/unchanged &&
4586 mkdir -p dir/subdir/tweaked &&
4587 echo a >dir/subdir/a &&
4588 echo b >dir/subdir/b &&
4589 echo c >dir/subdir/c &&
4590 echo d >dir/subdir/d &&
4591 test_seq 1 10 >dir/subdir/e &&
4592 test_seq 10 20 >dir/subdir/Makefile &&
4593 echo f >dir/subdir/tweaked/f &&
4594 echo g >dir/subdir/tweaked/g &&
4595 echo h >dir/subdir/tweaked/h &&
4596 test_seq 20 30 >dir/subdir/tweaked/Makefile &&
4597 for i in `test_seq 1 88`; do
4598 echo content $i >dir/unchanged/file_$i
4601 git commit -m "O" &&
4608 git rm dir/subdir/tweaked/f dir/subdir/tweaked/g &&
4609 test_seq 2 10 >dir/subdir/e &&
4610 test_seq 11 20 >dir/subdir/Makefile &&
4611 test_seq 21 30 >dir/subdir/tweaked/Makefile &&
4612 mkdir dir/subdir/newsubdir &&
4613 git mv dir/subdir/e dir/subdir/newsubdir/ &&
4614 git mv dir folder &&
4616 git commit -m "A" &&
4619 mkdir dir/subdir/newsubdir/ &&
4620 echo c code >dir/subdir/newfile.c &&
4621 echo python code >dir/subdir/newsubdir/newfile.py &&
4622 test_seq 1 11 >dir/subdir/e &&
4623 test_seq 10 21 >dir/subdir/Makefile &&
4624 test_seq 20 31 >dir/subdir/tweaked/Makefile &&
4626 git commit -m "B1" &&
4628 echo rust code >dir/subdir/newfile.rs &&
4629 test_seq 1 12 >dir/subdir/e &&
4635 test_expect_failure '12f: Trivial directory resolve, caching, all kinds of fun' '
4641 git branch Bmod B &&
4643 git -c merge.directoryRenames=true rebase A Bmod &&
4645 echo Checking the pick of B1... &&
4647 test_must_fail git rev-parse Bmod~1:dir &&
4649 git ls-tree -r Bmod~1 >out &&
4650 test_line_count = 98 out &&
4652 git diff --name-status A Bmod~1 >actual &&
4653 q_to_tab >expect <<-\EOF &&
4654 MQfolder/subdir/Makefile
4655 AQfolder/subdir/newfile.c
4656 MQfolder/subdir/newsubdir/e
4657 AQfolder/subdir/newsubdir/newfile.py
4658 MQfolder/subdir/tweaked/Makefile
4660 test_cmp expect actual &&
4662 # Three-way merged files
4663 test_seq 2 11 >e_Merge1 &&
4664 test_seq 11 21 >Makefile_TOP &&
4665 test_seq 21 31 >Makefile_SUB &&
4666 git hash-object >expect \
4670 git rev-parse >actual \
4671 Bmod~1:folder/subdir/newsubdir/e \
4672 Bmod~1:folder/subdir/Makefile \
4673 Bmod~1:folder/subdir/tweaked/Makefile &&
4674 test_cmp expect actual &&
4676 # New files showed up at the right location with right contents
4677 git rev-parse >expect \
4678 B~1:dir/subdir/newfile.c \
4679 B~1:dir/subdir/newsubdir/newfile.py &&
4680 git rev-parse >actual \
4681 Bmod~1:folder/subdir/newfile.c \
4682 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4683 test_cmp expect actual &&
4686 test_path_is_missing folder/subdir/tweaked/f &&
4687 test_path_is_missing folder/subdir/tweaked/g &&
4689 # Unchanged files or directories
4690 git rev-parse >actual \
4691 Bmod~1:folder/subdir/a \
4692 Bmod~1:folder/subdir/b \
4693 Bmod~1:folder/subdir/c \
4694 Bmod~1:folder/subdir/d \
4695 Bmod~1:folder/unchanged \
4696 Bmod~1:folder/subdir/tweaked/h &&
4697 git rev-parse >expect \
4703 O:dir/subdir/tweaked/h &&
4704 test_cmp expect actual &&
4706 echo Checking the pick of B2... &&
4708 test_must_fail git rev-parse Bmod:dir &&
4710 git ls-tree -r Bmod >out &&
4711 test_line_count = 99 out &&
4713 git diff --name-status Bmod~1 Bmod >actual &&
4714 q_to_tab >expect <<-\EOF &&
4715 AQfolder/subdir/newfile.rs
4716 MQfolder/subdir/newsubdir/e
4718 test_cmp expect actual &&
4720 # Three-way merged file
4721 test_seq 2 12 >e_Merge2 &&
4722 git hash-object e_Merge2 >expect &&
4723 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4724 test_cmp expect actual
4728 ###########################################################################
4729 # SECTION 13: Checking informational and conflict messages
4731 # A year after directory rename detection became the default, it was
4732 # instead decided to report conflicts on the pathname on the basis that
4733 # some users may expect the new files added or moved into a directory to
4734 # be unrelated to all the other files in that directory, and thus that
4735 # directory rename detection is unexpected. Test that the messages printed
4736 # match our expectation.
4737 ###########################################################################
4739 # Testcase 13a, Basic directory rename with newly added files
4742 # Commit B: z/{b,c,d,e/f}
4743 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
4746 test_create_repo 13a_$1 &&
4755 git commit -m "O" &&
4764 git commit -m "A" &&
4770 git add z/d z/e/f &&
4776 test_expect_success '13a(conflict): messages for newly added files' '
4777 test_setup_13a conflict &&
4783 test_must_fail git merge -s recursive B^0 >out 2>err &&
4785 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
4786 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
4788 git ls-files >paths &&
4790 grep "y/[de]" paths &&
4792 test_path_is_missing z/d &&
4793 test_path_is_file y/d &&
4794 test_path_is_missing z/e/f &&
4795 test_path_is_file y/e/f
4799 test_expect_success '13a(info): messages for newly added files' '
4800 test_setup_13a info &&
4807 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4809 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
4810 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
4812 git ls-files >paths &&
4814 grep "y/[de]" paths &&
4816 test_path_is_missing z/d &&
4817 test_path_is_file y/d &&
4818 test_path_is_missing z/e/f &&
4819 test_path_is_file y/e/f
4823 # Testcase 13b, Transitive rename with conflicted content merge and default
4824 # "conflict" setting
4825 # (Related to testcase 1c, 9b)
4826 # Commit O: z/{b,c}, x/d_1
4827 # Commit A: y/{b,c}, x/d_2
4828 # Commit B: z/{b,c,d_3}
4829 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
4830 # one about content, and one about file location
4833 test_create_repo 13b_$1 &&
4839 test_seq 1 10 >x/d &&
4844 git commit -m "O" &&
4855 git commit -m "A" &&
4858 echo eleven >>x/d &&
4866 test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
4867 test_setup_13b conflict &&
4873 test_must_fail git merge -s recursive B^0 >out 2>err &&
4875 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4876 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4878 git ls-files >paths &&
4882 test_path_is_missing z/d &&
4883 test_path_is_file y/d
4887 test_expect_success '13b(info): messages for transitive rename with conflicted content' '
4888 test_setup_13b info &&
4895 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4897 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
4898 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4900 git ls-files >paths &&
4904 test_path_is_missing z/d &&
4905 test_path_is_file y/d
4909 # Testcase 13c, Rename/rename(1to1) due to directory rename
4910 # Commit O: z/{b,c}, x/{d,e}
4911 # Commit A: y/{b,c,d}, x/e
4912 # Commit B: z/{b,c,d}, x/e
4913 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
4914 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
4915 # One could argue A had partial knowledge of what was done with
4916 # d and B had full knowledge, but that's a slippery slope as
4917 # shown in testcase 13d.
4920 test_create_repo 13c_$1 &&
4926 test_seq 1 10 >x/d &&
4932 git commit -m "O" &&
4942 git commit -m "A" &&
4952 test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
4953 test_setup_13c conflict &&
4959 test_must_fail git merge -s recursive B^0 >out 2>err &&
4961 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
4963 git ls-files >paths &&
4967 test_path_is_missing z/d &&
4968 test_path_is_file y/d
4972 test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
4973 test_setup_13c info &&
4980 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4982 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
4984 git ls-files >paths &&
4988 test_path_is_missing z/d &&
4989 test_path_is_file y/d
4993 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
4994 # Commit O: a/{z,y}, b/x, c/w
4995 # Commit A: a/z, b/{y,x}, d/w
4996 # Commit B: a/z, d/x, c/{y,w}
4997 # Expected: a/z, d/{y,x,w} with no file location conflict for x
4999 # * z is always in a; so it stays in a.
5000 # * x starts in b, only modified on one side to move into d/
5001 # * w starts in c, only modified on one side to move into d/
5003 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5004 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5005 # No conflict in where a/y ends up, so put it in d/y.
5008 test_create_repo 13d_$1 &&
5021 git commit -m "O" &&
5031 git commit -m "A" &&
5041 test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5042 test_setup_13d conflict &&
5048 test_must_fail git merge -s recursive B^0 >out 2>err &&
5050 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5051 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5053 git ls-files >paths &&
5058 test_path_is_missing b/y &&
5059 test_path_is_missing c/y &&
5060 test_path_is_file d/y
5064 test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5065 test_setup_13d info &&
5072 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5074 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5075 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5077 git ls-files >paths &&
5082 test_path_is_missing b/y &&
5083 test_path_is_missing c/y &&
5084 test_path_is_file d/y
5088 # Testcase 13e, directory rename in virtual merge base
5090 # This testcase has a slightly different setup than all the above cases, in
5091 # order to include a recursive case:
5103 # Commit B: a/{z,y,x}
5104 # Commit C: b/{z,y,x}
5105 # Commit D: b/{z,y}, a/x
5106 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5108 # NOTES: 'X' represents a virtual merge base. With the default of
5109 # directory rename detection yielding conflicts, merging A and B
5110 # results in a conflict complaining about whether 'x' should be
5111 # under 'a/' or 'b/'. However, when creating the virtual merge
5112 # base 'X', since virtual merge bases need to be written out as a
5113 # tree, we cannot have a conflict, so some resolution has to be
5116 # In choosing the right resolution, it's worth noting here that
5117 # commits C & D are merges of A & B that choose different
5118 # locations for 'x' (i.e. they resolve the conflict differently),
5119 # and so it would be nice when merging C & D if git could detect
5120 # this difference of opinion and report a conflict. But the only
5121 # way to do so that I can think of would be to have the virtual
5122 # merge base place 'x' in some directory other than either 'a/' or
5123 # 'b/', which seems a little weird -- especially since it'd result
5124 # in a rename/rename(1to2) conflict with a source path that never
5125 # existed in any version.
5127 # So, for now, when directory rename detection is set to
5128 # 'conflict' just avoid doing directory rename detection at all in
5129 # the recursive case. This will not allow us to detect a conflict
5130 # in the outer merge for this special kind of setup, but it at
5131 # least avoids hitting a BUG().
5134 test_create_repo 13e &&
5143 git commit -m "O" &&
5152 git commit -m "A" &&
5158 git commit -m "B" &&
5164 test_must_fail git -c merge.directoryRenames=conflict merge B &&
5167 git commit -m "C" &&
5171 test_must_fail git -c merge.directoryRenames=conflict merge A &&
5180 test_expect_success '13e: directory rename detection in recursive case' '
5185 git checkout --quiet D^0 &&
5187 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5189 test_i18ngrep ! CONFLICT out &&
5190 test_i18ngrep ! BUG: err &&
5191 test_i18ngrep ! core.dumped err &&
5192 test_must_be_empty err &&
5194 git ls-files >paths &&