3 test_description
="recursive merge with directory renames"
4 # includes checking of many corner cases, with a similar methodology to:
5 # t6042: corner cases with renames but not criss-cross merges
6 # t6036: corner cases with both renames and criss-cross merges
8 # The setup for all of them, pictorially, is:
18 # To help make it easier to follow the flow of tests, they have been
19 # divided into sections and each test will start with a quick explanation
20 # of what commits O, A, and B contain.
23 # z/{b,c} means files z/b and z/c both exist
24 # x/d_1 means file x/d exists with content d1. (Purpose of the
25 # underscore notation is to differentiate different
26 # files that might be renamed into each other's paths.)
29 .
"$TEST_DIRECTORY"/lib-merge.sh
32 ###########################################################################
33 # SECTION 1: Basic cases we should be able to handle
34 ###########################################################################
36 # Testcase 1a, Basic directory rename.
39 # Commit B: z/{b,c,d,e/f}
40 # Expected: y/{b,c,d,e/f}
43 test_create_repo
1a
&&
73 test_expect_success
'1a: Simple directory rename detection' '
80 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
82 git ls-files -s >out &&
83 test_line_count = 4 out &&
85 git rev-parse >actual \
86 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
87 git rev-parse >expect \
88 O:z/b O:z/c B:z/d B:z/e/f &&
89 test_cmp expect actual &&
91 git hash-object y/d >actual &&
92 git rev-parse B:z/d >expect &&
93 test_cmp expect actual &&
95 test_must_fail git rev-parse HEAD:z/d &&
96 test_must_fail git rev-parse HEAD:z/e/f &&
97 test_path_is_missing z/d &&
98 test_path_is_missing z/e/f
102 # Testcase 1b, Merge a directory with another
103 # Commit O: z/{b,c}, y/d
104 # Commit A: z/{b,c,e}, y/d
105 # Commit B: y/{b,c,d}
106 # Expected: y/{b,c,d,e}
109 test_create_repo
1b
&&
141 test_expect_success
'1b: Merge a directory with another' '
148 git -c merge.directoryRenames=true merge -s recursive B^0 &&
150 git ls-files -s >out &&
151 test_line_count = 4 out &&
153 git rev-parse >actual \
154 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
155 git rev-parse >expect \
156 O:z/b O:z/c O:y/d A:z/e &&
157 test_cmp expect actual &&
158 test_must_fail git rev-parse HEAD:z/e
162 # Testcase 1c, Transitive renaming
163 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
164 # (Related to testcases 9c and 9d -- can transitivity repeat?)
165 # (Related to testcase 12b -- joint-transitivity?)
166 # Commit O: z/{b,c}, x/d
167 # Commit A: y/{b,c}, x/d
168 # Commit B: z/{b,c,d}
169 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
172 test_create_repo
1c
&&
201 test_expect_success
'1c: Transitive renaming' '
208 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
210 git ls-files -s >out &&
211 test_line_count = 3 out &&
213 git rev-parse >actual \
214 HEAD:y/b HEAD:y/c HEAD:y/d &&
215 git rev-parse >expect \
217 test_cmp expect actual &&
218 test_must_fail git rev-parse HEAD:x/d &&
219 test_must_fail git rev-parse HEAD:z/d &&
220 test_path_is_missing z/d
224 # Testcase 1d, Directory renames (merging two directories into one new one)
225 # cause a rename/rename(2to1) conflict
226 # (Related to testcases 1c and 7b)
227 # Commit O. z/{b,c}, y/{d,e}
228 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
229 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
230 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
231 # Note: y/m & z/n should definitely move into x. By the same token, both
232 # y/wham_1 & z/wham_2 should too...giving us a conflict.
235 test_create_repo
1d
&&
256 echo wham1
>y
/wham
&&
264 echo wham2
>z
/wham
&&
271 test_expect_success
'1d: Directory renames cause a rename/rename(2to1) conflict' '
278 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
279 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
281 git ls-files -s >out &&
282 test_line_count = 8 out &&
283 git ls-files -u >out &&
284 test_line_count = 2 out &&
285 git ls-files -o >out &&
286 test_line_count = 1 out &&
288 git rev-parse >actual \
289 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
290 git rev-parse >expect \
291 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
292 test_cmp expect actual &&
294 test_must_fail git rev-parse :0:x/wham &&
295 git rev-parse >actual \
296 :2:x/wham :3:x/wham &&
297 git rev-parse >expect \
299 test_cmp expect actual &&
301 # Test that the two-way merge in x/wham is as expected
302 git cat-file -p :2:x/wham >expect &&
303 git cat-file -p :3:x/wham >other &&
305 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
307 test_must_fail git merge-file \
313 test_must_fail git merge-file \
319 test_cmp expect x/wham
323 # Testcase 1e, Renamed directory, with all filenames being renamed too
324 # (Related to testcases 9f & 9g)
325 # Commit O: z/{oldb,oldc}
326 # Commit A: y/{newb,newc}
327 # Commit B: z/{oldb,oldc,d}
328 # Expected: y/{newb,newc,d}
331 test_create_repo
1e
&&
348 git
mv z
/oldb y
/newb
&&
349 git
mv z
/oldc y
/newc
&&
361 test_expect_success
'1e: Renamed directory, with all files being renamed too' '
368 git -c merge.directoryRenames=true merge -s recursive B^0 &&
370 git ls-files -s >out &&
371 test_line_count = 3 out &&
373 git rev-parse >actual \
374 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
375 git rev-parse >expect \
376 O:z/oldb O:z/oldc B:z/d &&
377 test_cmp expect actual &&
378 test_must_fail git rev-parse HEAD:z/d
382 # Testcase 1f, Split a directory into two other directories
383 # (Related to testcases 3a, all of section 2, and all of section 4)
384 # Commit O: z/{b,c,d,e,f}
385 # Commit A: z/{b,c,d,e,f,g}
386 # Commit B: y/{b,c}, x/{d,e,f}
387 # Expected: y/{b,c}, x/{d,e,f,g}
390 test_create_repo
1f
&&
428 test_expect_success
'1f: Split a directory into two other directories' '
435 git -c merge.directoryRenames=true merge -s recursive B^0 &&
437 git ls-files -s >out &&
438 test_line_count = 6 out &&
440 git rev-parse >actual \
441 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
442 git rev-parse >expect \
443 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
444 test_cmp expect actual &&
445 test_path_is_missing z/g &&
446 test_must_fail git rev-parse HEAD:z/g
450 ###########################################################################
451 # Rules suggested by testcases in section 1:
453 # We should still detect the directory rename even if it wasn't just
454 # the directory renamed, but the files within it. (see 1b)
456 # If renames split a directory into two or more others, the directory
457 # with the most renames, "wins" (see 1f). However, see the testcases
458 # in section 2, plus testcases 3a and 4a.
459 ###########################################################################
462 ###########################################################################
463 # SECTION 2: Split into multiple directories, with equal number of paths
465 # Explore the splitting-a-directory rules a bit; what happens in the
468 # Note that there is a closely related case of a directory not being
469 # split on either side of history, but being renamed differently on
470 # each side. See testcase 8e for that.
471 ###########################################################################
473 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
476 # Commit B: z/{b,c,d}
477 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
479 test_create_repo
2a
&&
510 test_expect_success
'2a: Directory split into two on one side, with equal numbers of paths' '
517 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
518 test_i18ngrep "CONFLICT.*directory rename split" out &&
520 git ls-files -s >out &&
521 test_line_count = 3 out &&
522 git ls-files -u >out &&
523 test_line_count = 0 out &&
524 git ls-files -o >out &&
525 test_line_count = 1 out &&
527 git rev-parse >actual \
528 :0:y/b :0:w/c :0:z/d &&
529 git rev-parse >expect \
531 test_cmp expect actual
535 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
538 # Commit B: z/{b,c}, x/d
539 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
541 test_create_repo
2b
&&
573 test_expect_success
'2b: Directory split into two on one side, with equal numbers of paths' '
580 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
582 git ls-files -s >out &&
583 test_line_count = 3 out &&
584 git ls-files -u >out &&
585 test_line_count = 0 out &&
586 git ls-files -o >out &&
587 test_line_count = 1 out &&
589 git rev-parse >actual \
590 :0:y/b :0:w/c :0:x/d &&
591 git rev-parse >expect \
593 test_cmp expect actual &&
594 test_i18ngrep ! "CONFLICT.*directory rename split" out
598 ###########################################################################
599 # Rules suggested by section 2:
601 # None; the rule was already covered in section 1. These testcases are
602 # here just to make sure the conflict resolution and necessary warning
603 # messages are handled correctly.
604 ###########################################################################
607 ###########################################################################
608 # SECTION 3: Path in question is the source path for some rename already
610 # Combining cases from Section 1 and trying to handle them could lead to
611 # directory renaming detection being over-applied. So, this section
612 # provides some good testcases to check that the implementation doesn't go
614 ###########################################################################
616 # Testcase 3a, Avoid implicit rename if involved as source on other side
617 # (Related to testcases 1c, 1f, and 9h)
618 # Commit O: z/{b,c,d}
619 # Commit A: z/{b,c,d} (no change)
620 # Commit B: y/{b,c}, x/d
621 # Expected: y/{b,c}, x/d
623 test_create_repo
3a
&&
641 git commit
--allow-empty -m "A" &&
655 test_expect_success
'3a: Avoid implicit rename if involved as source on other side' '
662 git -c merge.directoryRenames=true merge -s recursive B^0 &&
664 git ls-files -s >out &&
665 test_line_count = 3 out &&
667 git rev-parse >actual \
668 HEAD:y/b HEAD:y/c HEAD:x/d &&
669 git rev-parse >expect \
671 test_cmp expect actual
675 # Testcase 3b, Avoid implicit rename if involved as source on other side
676 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
677 # Commit O: z/{b,c,d}
678 # Commit A: y/{b,c}, x/d
679 # Commit B: z/{b,c}, w/d
680 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
681 # NOTE: We're particularly checking that since z/d is already involved as
682 # a source in a file rename on the same side of history, that we don't
683 # get it involved in directory rename detection. If it were, we might
684 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
685 # rename/rename/rename(1to3) conflict, which is just weird.
687 test_create_repo
3b
&&
721 test_expect_success
'3b: Avoid implicit rename if involved as source on current side' '
728 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
729 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
730 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
732 git ls-files -s >out &&
733 test_line_count = 5 out &&
734 git ls-files -u >out &&
735 test_line_count = 3 out &&
736 git ls-files -o >out &&
737 test_line_count = 1 out &&
739 git rev-parse >actual \
740 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
741 git rev-parse >expect \
742 O:z/b O:z/c O:z/d O:z/d O:z/d &&
743 test_cmp expect actual &&
745 test_path_is_missing z/d &&
746 git hash-object >actual \
748 git rev-parse >expect \
750 test_cmp expect actual
754 ###########################################################################
755 # Rules suggested by section 3:
757 # Avoid directory-rename-detection for a path, if that path is the source
758 # of a rename on either side of a merge.
759 ###########################################################################
762 ###########################################################################
763 # SECTION 4: Partially renamed directory; still exists on both sides of merge
765 # What if we were to attempt to do directory rename detection when someone
766 # "mostly" moved a directory but still left some files around, or,
767 # equivalently, fully renamed a directory in one commit and then recreated
768 # that directory in a later commit adding some new files and then tried to
771 # It's hard to divine user intent in these cases, because you can make an
772 # argument that, depending on the intermediate history of the side being
773 # merged, that some users will want files in that directory to
774 # automatically be detected and renamed, while users with a different
775 # intermediate history wouldn't want that rename to happen.
777 # I think that it is best to simply not have directory rename detection
778 # apply to such cases. My reasoning for this is four-fold: (1) it's
779 # easiest for users in general to figure out what happened if we don't
780 # apply directory rename detection in any such case, (2) it's an easy rule
781 # to explain ["We don't do directory rename detection if the directory
782 # still exists on both sides of the merge"], (3) we can get some hairy
783 # edge/corner cases that would be really confusing and possibly not even
784 # representable in the index if we were to even try, and [related to 3] (4)
785 # attempting to resolve this issue of divining user intent by examining
786 # intermediate history goes against the spirit of three-way merges and is a
787 # path towards crazy corner cases that are far more complex than what we're
788 # already dealing with.
790 # Note that the wording of the rule ("We don't do directory rename
791 # detection if the directory still exists on both sides of the merge.")
792 # also excludes "renaming" of a directory into a subdirectory of itself
793 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
794 # out an exception for "renaming"-beneath-itself cases without opening
795 # weird edge/corner cases for other partial directory renames, but for now
796 # we are keeping the rule simple.
798 # This section contains a test for a partially-renamed-directory case.
799 ###########################################################################
801 # Testcase 4a, Directory split, with original directory still present
802 # (Related to testcase 1f)
803 # Commit O: z/{b,c,d,e}
804 # Commit A: y/{b,c,d}, z/e
805 # Commit B: z/{b,c,d,e,f}
806 # Expected: y/{b,c,d}, z/{e,f}
807 # NOTE: Even though most files from z moved to y, we don't want f to follow.
810 test_create_repo
4a
&&
843 test_expect_success
'4a: Directory split, with original directory still present' '
850 git -c merge.directoryRenames=true merge -s recursive B^0 &&
852 git ls-files -s >out &&
853 test_line_count = 5 out &&
854 git ls-files -u >out &&
855 test_line_count = 0 out &&
856 git ls-files -o >out &&
857 test_line_count = 1 out &&
859 git rev-parse >actual \
860 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
861 git rev-parse >expect \
862 O:z/b O:z/c O:z/d O:z/e B:z/f &&
863 test_cmp expect actual
867 ###########################################################################
868 # Rules suggested by section 4:
870 # Directory-rename-detection should be turned off for any directories (as
871 # a source for renames) that exist on both sides of the merge. (The "as
872 # a source for renames" clarification is due to cases like 1c where
873 # the target directory exists on both sides and we do want the rename
874 # detection.) But, sadly, see testcase 8b.
875 ###########################################################################
878 ###########################################################################
879 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
881 # Implicitly renaming files due to a detected directory rename could run
882 # into problems if there are files or directories in the way of the paths
883 # we want to rename. Explore such cases in this section.
884 ###########################################################################
886 # Testcase 5a, Merge directories, other side adds files to original and target
887 # Commit O: z/{b,c}, y/d
888 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
889 # Commit B: y/{b,c,d}
890 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
891 # NOTE: While directory rename detection is active here causing z/f to
892 # become y/f, we did not apply this for z/e_1 because that would
893 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
894 # this add/add, is that both versions of y/e are from the same side
895 # of history, giving us no way to represent this conflict in the
899 test_create_repo
5a
&&
920 git add z
/e z
/f y
/e
&&
933 test_expect_success
'5a: Merge directories, other side adds files to original and target' '
940 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
941 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
943 git ls-files -s >out &&
944 test_line_count = 6 out &&
945 git ls-files -u >out &&
946 test_line_count = 0 out &&
947 git ls-files -o >out &&
948 test_line_count = 1 out &&
950 git rev-parse >actual \
951 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
952 git rev-parse >expect \
953 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
954 test_cmp expect actual
958 # Testcase 5b, Rename/delete in order to get add/add/add conflict
959 # (Related to testcase 8d; these may appear slightly inconsistent to users;
960 # Also related to testcases 7d and 7e)
961 # Commit O: z/{b,c,d_1}
962 # Commit A: y/{b,c,d_2}
963 # Commit B: z/{b,c,d_1,e}, y/d_3
964 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
965 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
966 # we normally would since z/ is being renamed to y/, then this would be
967 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
968 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
969 # representable in the index, so the existence of y/d_3 needs to
970 # cause us to bail on directory rename detection for that path, falling
971 # back to git behavior without the directory rename detection.
974 test_create_repo
5b
&&
1008 test_expect_success
'5b: Rename/delete in order to get add/add/add conflict' '
1015 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1016 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1018 git ls-files -s >out &&
1019 test_line_count = 5 out &&
1020 git ls-files -u >out &&
1021 test_line_count = 2 out &&
1022 git ls-files -o >out &&
1023 test_line_count = 1 out &&
1025 git rev-parse >actual \
1026 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1027 git rev-parse >expect \
1028 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1029 test_cmp expect actual &&
1031 test_must_fail git rev-parse :1:y/d &&
1032 test_path_is_file y/d
1036 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1037 # (Directory rename detection would result in transitive rename vs.
1038 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1039 # rename paths conflict with separate adds on the other side)
1040 # (Related to testcases 3b and 7c)
1041 # Commit O: z/{b,c}, x/d_1
1042 # Commit A: y/{b,c,d_2}, w/d_1
1043 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1044 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1045 # presence of y/d_4 in B to avoid doing transitive rename of
1046 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1047 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1048 # though, because it doesn't have anything in the way.
1051 test_create_repo
5c
&&
1062 git commit
-m "O" &&
1074 git commit
-m "A" &&
1083 git add w
/ y
/ z
/e
&&
1089 test_expect_success
'5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1096 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1097 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1098 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1100 git ls-files -s >out &&
1101 test_line_count = 9 out &&
1102 git ls-files -u >out &&
1103 test_line_count = 6 out &&
1104 git ls-files -o >out &&
1105 test_line_count = 1 out &&
1107 git rev-parse >actual \
1108 :0:y/b :0:y/c :0:y/e &&
1109 git rev-parse >expect \
1110 O:z/b O:z/c B:z/e &&
1111 test_cmp expect actual &&
1113 test_must_fail git rev-parse :1:y/d &&
1114 git rev-parse >actual \
1115 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1116 git rev-parse >expect \
1117 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1118 test_cmp expect actual &&
1120 git hash-object >actual \
1122 git rev-parse >expect \
1124 test_cmp expect actual &&
1125 test_path_is_missing x/d &&
1126 test_path_is_file y/d &&
1127 grep -q "<<<<" y/d # conflict markers should be present
1131 # Testcase 5d, Directory/file/file conflict due to directory rename
1133 # Commit A: y/{b,c,d_1}
1134 # Commit B: z/{b,c,d_2,f}, y/d/e
1135 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1136 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1137 # detection for z/d_2, but that doesn't prevent us from applying the
1138 # directory rename detection for z/f -> y/f.
1141 test_create_repo
5d
&&
1150 git commit
-m "O" &&
1161 git commit
-m "A" &&
1168 git add y
/d
/e z
/d z
/f
&&
1174 test_expect_success
'5d: Directory/file/file conflict due to directory rename' '
1181 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1182 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1184 git ls-files -s >out &&
1185 test_line_count = 6 out &&
1186 git ls-files -u >out &&
1187 test_line_count = 1 out &&
1188 git ls-files -o >out &&
1189 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1191 test_line_count = 1 out &&
1193 git rev-parse >actual \
1194 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e
1196 test_line_count = 2 out &&
1198 git rev-parse >actual \
1199 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e
1201 git rev-parse >expect \
1202 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1203 test_cmp expect actual &&
1205 git hash-object y/d~HEAD >actual &&
1206 git rev-parse A:y/d >expect &&
1207 test_cmp expect actual
1211 ###########################################################################
1212 # Rules suggested by section 5:
1214 # If a subset of to-be-renamed files have a file or directory in the way,
1215 # "turn off" the directory rename for those specific sub-paths, falling
1216 # back to old handling. But, sadly, see testcases 8a and 8b.
1217 ###########################################################################
1220 ###########################################################################
1221 # SECTION 6: Same side of the merge was the one that did the rename
1223 # It may sound obvious that you only want to apply implicit directory
1224 # renames to directories if the _other_ side of history did the renaming.
1225 # If you did make an implementation that didn't explicitly enforce this
1226 # rule, the majority of cases that would fall under this section would
1227 # also be solved by following the rules from the above sections. But
1228 # there are still a few that stick out, so this section covers them just
1229 # to make sure we also get them right.
1230 ###########################################################################
1232 # Testcase 6a, Tricky rename/delete
1233 # Commit O: z/{b,c,d}
1235 # Commit B: y/{b,c}, z/d
1236 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1237 # Note: We're just checking here that the rename of z/b and z/c to put
1238 # them under y/ doesn't accidentally catch z/d and make it look like
1239 # it is also involved in a rename/delete conflict.
1242 test_create_repo
6a
&&
1252 git commit
-m "O" &&
1262 git commit
-m "A" &&
1273 test_expect_success
'6a: Tricky rename/delete' '
1280 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1281 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1283 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1285 git ls-files -s >out &&
1286 test_line_count = 3 out &&
1287 git ls-files -u >out &&
1288 test_line_count = 2 out &&
1289 git ls-files -o >out &&
1290 test_line_count = 1 out &&
1292 git rev-parse >actual \
1293 :0:y/b :1:y/c :3:y/c &&
1294 git rev-parse >expect \
1297 git ls-files -s >out &&
1298 test_line_count = 2 out &&
1299 git ls-files -u >out &&
1300 test_line_count = 1 out &&
1301 git ls-files -o >out &&
1302 test_line_count = 1 out &&
1304 git rev-parse >actual \
1306 git rev-parse >expect \
1309 test_cmp expect actual
1313 # Testcase 6b1, Same rename done on both sides
1314 # (Related to testcase 6b2 and 8e)
1315 # Commit O: z/{b,c,d,e}
1316 # Commit A: y/{b,c,d}, x/e
1317 # Commit B: y/{b,c,d}, z/{e,f}
1318 # Expected: y/{b,c,d,f}, x/e
1319 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1320 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1321 # should be moved to 'y/f'.
1323 # This is a bit of an edge case where any behavior might surprise users,
1324 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1325 # z/ -> x/, or treating A as not doing any directory rename. However, I
1326 # think this answer is the least confusing and most consistent with the
1329 # A note about z/ -> x/, since it may not be clear how that could come
1330 # about: If we were to ignore files renamed by both sides
1331 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1332 # at least git-2.28, then we would note there are no renames from z/ to
1333 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1334 # A renamed z/ -> x/. This seems more confusing for end users than a
1335 # rename of z/ to y/, it makes directory rename detection behavior
1336 # harder for them to predict. As such, we modified the rule, changed
1337 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1340 test_create_repo
6b1
&&
1351 git commit
-m "O" &&
1362 git commit
-m "A" &&
1375 test_expect_merge_algorithm failure success
'6b1: Same renames done on both sides, plus another rename' '
1382 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1384 git ls-files -s >out &&
1385 test_line_count = 5 out &&
1386 git ls-files -u >out &&
1387 test_line_count = 0 out &&
1388 git ls-files -o >out &&
1389 test_line_count = 1 out &&
1391 git rev-parse >actual \
1392 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1393 git rev-parse >expect \
1394 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1395 test_cmp expect actual
1399 # Testcase 6b2, Same rename done on both sides
1400 # (Related to testcases 6c and 8e)
1403 # Commit B: y/{b,c}, z/d
1404 # Expected: y/{b,c,d}
1405 # Alternate: y/{b,c}, z/d
1406 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1407 # file 'z/d' in B should be moved to 'y/d'.
1409 # We could potentially ignore the renames of z/{b,c} on side A since
1410 # those were renamed on both sides. However, it's a bit of a corner
1411 # case because what if there was also a z/e that side A moved to x/e
1412 # and side B left alone? If we used the "ignore renames done on both
1413 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1414 # z/d to x/d. That seems more surprising and uglier than allowing
1415 # the z/ -> y/ rename.
1418 test_create_repo
6b2
&&
1427 git commit
-m "O" &&
1436 git commit
-m "A" &&
1448 test_expect_merge_algorithm failure success
'6b2: Same rename done on both sides' '
1455 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1457 git ls-files -s >out &&
1458 test_line_count = 3 out &&
1459 git ls-files -u >out &&
1460 test_line_count = 0 out &&
1461 git ls-files -o >out &&
1462 test_line_count = 1 out &&
1464 git rev-parse >actual \
1465 HEAD:y/b HEAD:y/c HEAD:y/d &&
1466 git rev-parse >expect \
1467 O:z/b O:z/c B:z/d &&
1468 test_cmp expect actual
1472 # Testcase 6c, Rename only done on same side
1473 # (Related to testcases 6b1, 6b2, and 8e)
1475 # Commit A: z/{b,c} (no change)
1476 # Commit B: y/{b,c}, z/d
1477 # Expected: y/{b,c}, z/d
1478 # NOTE: Seems obvious, but just checking that the implementation doesn't
1479 # "accidentally detect a rename" and give us y/{b,c,d}.
1482 test_create_repo
6c
&&
1491 git commit
-m "O" &&
1499 git commit
--allow-empty -m "A" &&
1511 test_expect_success
'6c: Rename only done on same side' '
1518 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1520 git ls-files -s >out &&
1521 test_line_count = 3 out &&
1522 git ls-files -u >out &&
1523 test_line_count = 0 out &&
1524 git ls-files -o >out &&
1525 test_line_count = 1 out &&
1527 git rev-parse >actual \
1528 HEAD:y/b HEAD:y/c HEAD:z/d &&
1529 git rev-parse >expect \
1530 O:z/b O:z/c B:z/d &&
1531 test_cmp expect actual
1535 # Testcase 6d, We don't always want transitive renaming
1536 # (Related to testcase 1c)
1537 # Commit O: z/{b,c}, x/d
1538 # Commit A: z/{b,c}, x/d (no change)
1539 # Commit B: y/{b,c}, z/d
1540 # Expected: y/{b,c}, z/d
1541 # NOTE: Again, this seems obvious but just checking that the implementation
1542 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1545 test_create_repo
6d
&&
1556 git commit
-m "O" &&
1564 git commit
--allow-empty -m "A" &&
1574 test_expect_success
'6d: We do not always want transitive renaming' '
1581 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1583 git ls-files -s >out &&
1584 test_line_count = 3 out &&
1585 git ls-files -u >out &&
1586 test_line_count = 0 out &&
1587 git ls-files -o >out &&
1588 test_line_count = 1 out &&
1590 git rev-parse >actual \
1591 HEAD:y/b HEAD:y/c HEAD:z/d &&
1592 git rev-parse >expect \
1593 O:z/b O:z/c O:x/d &&
1594 test_cmp expect actual
1598 # Testcase 6e, Add/add from one-side
1600 # Commit A: z/{b,c} (no change)
1601 # Commit B: y/{b,c,d_1}, z/d_2
1602 # Expected: y/{b,c,d_1}, z/d_2
1603 # NOTE: Again, this seems obvious but just checking that the implementation
1604 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1605 # add/add conflict on y/d_1 vs y/d_2.
1608 test_create_repo
6e
&&
1617 git commit
-m "O" &&
1625 git commit
--allow-empty -m "A" &&
1638 test_expect_success
'6e: Add/add from one side' '
1645 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1647 git ls-files -s >out &&
1648 test_line_count = 4 out &&
1649 git ls-files -u >out &&
1650 test_line_count = 0 out &&
1651 git ls-files -o >out &&
1652 test_line_count = 1 out &&
1654 git rev-parse >actual \
1655 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1656 git rev-parse >expect \
1657 O:z/b O:z/c B:y/d B:z/d &&
1658 test_cmp expect actual
1662 ###########################################################################
1663 # Rules suggested by section 6:
1665 # Only apply implicit directory renames to directories if the other
1666 # side of history is the one doing the renaming.
1667 ###########################################################################
1670 ###########################################################################
1671 # SECTION 7: More involved Edge/Corner cases
1673 # The ruleset we have generated in the above sections seems to provide
1674 # well-defined merges. But can we find edge/corner cases that either (a)
1675 # are harder for users to understand, or (b) have a resolution that is
1676 # non-intuitive or suboptimal?
1678 # The testcases in this section dive into cases that I've tried to craft in
1679 # a way to find some that might be surprising to users or difficult for
1680 # them to understand (the next section will look at non-intuitive or
1681 # suboptimal merge results). Some of the testcases are similar to ones
1682 # from past sections, but have been simplified to try to highlight error
1683 # messages using a "modified" path (due to the directory rename). Are
1684 # users okay with these?
1686 # In my opinion, testcases that are difficult to understand from this
1687 # section is due to difficulty in the testcase rather than the directory
1688 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1689 # to the problem setup itself being complex). And I don't think the
1690 # error messages are a problem.
1692 # On the other hand, the testcases in section 8 worry me slightly more...
1693 ###########################################################################
1695 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1698 # Commit B: w/b, x/c, z/d
1699 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1700 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1703 test_create_repo
7a
&&
1712 git commit
-m "O" &&
1721 git commit
-m "A" &&
1735 test_expect_success
'7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1742 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1743 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1744 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1746 git ls-files -s >out &&
1747 test_line_count = 7 out &&
1748 git ls-files -u >out &&
1749 test_line_count = 6 out &&
1750 git ls-files -o >out &&
1751 test_line_count = 1 out &&
1753 git rev-parse >actual \
1754 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1755 git rev-parse >expect \
1756 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1757 test_cmp expect actual &&
1759 git hash-object >actual \
1761 git rev-parse >expect \
1762 O:z/b O:z/b O:z/c O:z/c &&
1763 test_cmp expect actual
1767 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1768 # (Related to testcase 1d)
1769 # Commit O: z/{b,c}, x/d_1, w/d_2
1770 # Commit A: y/{b,c,d_2}, x/d_1
1771 # Commit B: z/{b,c,d_1}, w/d_2
1772 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1775 test_create_repo
7b
&&
1788 git commit
-m "O" &&
1798 git commit
-m "A" &&
1808 test_expect_success
'7b: rename/rename(2to1), but only due to transitive rename' '
1815 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1816 test_i18ngrep "CONFLICT (\(.*\)/\1)" out &&
1818 git ls-files -s >out &&
1819 test_line_count = 4 out &&
1820 git ls-files -u >out &&
1821 test_line_count = 2 out &&
1822 git ls-files -o >out &&
1823 test_line_count = 1 out &&
1825 git rev-parse >actual \
1826 :0:y/b :0:y/c :2:y/d :3:y/d &&
1827 git rev-parse >expect \
1828 O:z/b O:z/c O:w/d O:x/d &&
1829 test_cmp expect actual &&
1831 # Test that the two-way merge in y/d is as expected
1832 git cat-file -p :2:y/d >expect &&
1833 git cat-file -p :3:y/d >other &&
1835 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1837 test_must_fail git merge-file \
1843 test_must_fail git merge-file \
1853 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1854 # (Related to testcases 3b and 5c)
1855 # Commit O: z/{b,c}, x/d
1856 # Commit A: y/{b,c}, w/d
1857 # Commit B: z/{b,c,d}
1858 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1859 # NOTE: z/ was renamed to y/ so we do want to report
1860 # neither CONFLICT(x/d -> w/d vs. z/d)
1861 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1864 test_create_repo
7c
&&
1875 git commit
-m "O" &&
1885 git commit
-m "A" &&
1895 test_expect_success
'7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1902 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1903 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1905 git ls-files -s >out &&
1906 test_line_count = 5 out &&
1907 git ls-files -u >out &&
1908 test_line_count = 3 out &&
1909 git ls-files -o >out &&
1910 test_line_count = 1 out &&
1912 git rev-parse >actual \
1913 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1914 git rev-parse >expect \
1915 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1916 test_cmp expect actual
1920 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1921 # (Related somewhat to testcases 5b and 8d)
1922 # Commit O: z/{b,c}, x/d
1924 # Commit B: z/{b,c,d}
1925 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1926 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1929 test_create_repo
7d
&&
1940 git commit
-m "O" &&
1950 git commit
-m "A" &&
1960 test_expect_success
'7d: transitive rename involved in rename/delete; how is it reported?' '
1967 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1968 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1970 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1972 git ls-files -s >out &&
1973 test_line_count = 4 out &&
1974 git ls-files -u >out &&
1975 test_line_count = 2 out &&
1976 git ls-files -o >out &&
1977 test_line_count = 1 out &&
1979 git rev-parse >actual \
1980 :0:y/b :0:y/c :1:y/d :3:y/d &&
1981 git rev-parse >expect \
1982 O:z/b O:z/c O:x/d O:x/d
1984 git ls-files -s >out &&
1985 test_line_count = 3 out &&
1986 git ls-files -u >out &&
1987 test_line_count = 1 out &&
1988 git ls-files -o >out &&
1989 test_line_count = 1 out &&
1991 git rev-parse >actual \
1992 :0:y/b :0:y/c :3:y/d &&
1993 git rev-parse >expect \
1996 test_cmp expect actual
2000 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
2001 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
2002 # (Also related to testcases 9c and 9d)
2003 # Commit O: z/{b,c}, x/d_1
2004 # Commit A: y/{b,c,d/g}, x/d/f
2005 # Commit B: z/{b,c,d_1}
2006 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
2007 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
2009 # NOTE: The main path of interest here is d_1 and where it ends up, but
2010 # this is actually a case that has two potential directory renames
2011 # involved and D/F conflict(s), so it makes sense to walk through
2014 # Commit A renames z/ -> y/. Thus everything that B adds to z/
2015 # should be instead moved to y/. This gives us the D/F conflict on
2016 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
2018 # Further, commit B renames x/ -> z/, thus everything A adds to x/
2019 # should instead be moved to z/...BUT we removed z/ and renamed it
2020 # to y/, so maybe everything should move not from x/ to z/, but
2021 # from x/ to z/ to y/. Doing so might make sense from the logic so
2022 # far, but note that commit A had both an x/ and a y/; it did the
2023 # renaming of z/ to y/ and created x/d/f and it clearly made these
2024 # things separate, so it doesn't make much sense to push these
2025 # together. Doing so is what I'd call a doubly transitive rename;
2026 # see testcases 9c and 9d for further discussion of this issue and
2027 # how it's resolved.
2030 test_create_repo
7e
&&
2041 git commit
-m "O" &&
2054 git add x
/d
/f y
/d
/g
&&
2056 git commit
-m "A" &&
2066 test_expect_success
'7e: transitive rename in rename/delete AND dirs in the way' '
2073 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2074 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2076 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
2078 git ls-files -s >out &&
2079 test_line_count = 6 out &&
2080 git ls-files -u >out &&
2081 test_line_count = 2 out &&
2082 git ls-files -o >out &&
2083 test_line_count = 1 out &&
2085 git rev-parse >actual \
2086 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
2087 git rev-parse >expect \
2088 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d
2090 git ls-files -s >out &&
2091 test_line_count = 5 out &&
2092 git ls-files -u >out &&
2093 test_line_count = 1 out &&
2094 git ls-files -o >out &&
2095 test_line_count = 2 out &&
2097 git rev-parse >actual \
2098 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2099 git rev-parse >expect \
2100 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d
2102 test_cmp expect actual &&
2104 git hash-object y/d~B^0 >actual &&
2105 git rev-parse O:x/d >expect &&
2106 test_cmp expect actual
2110 ###########################################################################
2111 # SECTION 8: Suboptimal merges
2113 # As alluded to in the last section, the ruleset we have built up for
2114 # detecting directory renames unfortunately has some special cases where it
2115 # results in slightly suboptimal or non-intuitive behavior. This section
2116 # explores these cases.
2118 # To be fair, we already had non-intuitive or suboptimal behavior for most
2119 # of these cases in git before introducing implicit directory rename
2120 # detection, but it'd be nice if there was a modified ruleset out there
2121 # that handled these cases a bit better.
2122 ###########################################################################
2124 # Testcase 8a, Dual-directory rename, one into the others' way
2125 # Commit O. x/{a,b}, y/{c,d}
2126 # Commit A. x/{a,b,e}, y/{c,d,f}
2127 # Commit B. y/{a,b}, z/{c,d}
2129 # Possible Resolutions:
2130 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2131 # Currently expected: y/{a,b,e,f}, z/{c,d}
2132 # Optimal: y/{a,b,e}, z/{c,d,f}
2134 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2135 # better with directory rename detection than git did without, but the
2136 # simple rule from section 5 prevents me from handling this as optimally as
2137 # we potentially could.
2140 test_create_repo
8a
&&
2152 git commit
-m "O" &&
2163 git commit
-m "A" &&
2173 test_expect_success
'8a: Dual-directory rename, one into the others way' '
2180 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2182 git ls-files -s >out &&
2183 test_line_count = 6 out &&
2184 git ls-files -u >out &&
2185 test_line_count = 0 out &&
2186 git ls-files -o >out &&
2187 test_line_count = 1 out &&
2189 git rev-parse >actual \
2190 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2191 git rev-parse >expect \
2192 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2193 test_cmp expect actual
2197 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2198 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2199 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2200 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2202 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2203 # Currently expected: <same>
2204 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2205 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2207 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2208 # y, both are named 'e'. Without directory rename detection, neither file
2209 # moves directories. Implement directory rename detection suboptimally, and
2210 # you get an add/add conflict, but both files were added in commit A, so this
2211 # is an add/add conflict where one side of history added both files --
2212 # something we can't represent in the index. Obviously, we'd prefer the last
2213 # resolution, but our previous rules are too coarse to allow it. Using both
2214 # the rules from section 4 and section 5 save us from the Scary resolution,
2215 # making us fall back to pre-directory-rename-detection behavior for both
2219 test_create_repo
8b
&&
2231 git commit
-m "O" &&
2242 git commit
-m "A" &&
2252 test_expect_success
'8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2259 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2261 git ls-files -s >out &&
2262 test_line_count = 6 out &&
2263 git ls-files -u >out &&
2264 test_line_count = 0 out &&
2265 git ls-files -o >out &&
2266 test_line_count = 1 out &&
2268 git rev-parse >actual \
2269 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2270 git rev-parse >expect \
2271 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2272 test_cmp expect actual
2276 # Testcase 8c, modify/delete or rename+modify/delete?
2277 # (Related to testcases 5b, 8d, and 9h)
2278 # Commit O: z/{b,c,d}
2280 # Commit B: z/{b,c,d_modified,e}
2281 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2283 # Note: It could easily be argued that the correct resolution here is
2284 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2285 # and that the modified version of d should be present in y/ after
2286 # the merge, just marked as conflicted. Indeed, I previously did
2287 # argue that. But applying directory renames to the side of
2288 # history where a file is merely modified results in spurious
2289 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2293 test_create_repo
8c
&&
2300 test_seq
1 10 >z
/d
&&
2303 git commit
-m "O" &&
2313 git commit
-m "A" &&
2317 test_chmod
+x z
/d
&&
2325 test_expect_success
'8c: modify/delete or rename+modify/delete' '
2332 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2333 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2335 git ls-files -s >out &&
2336 test_line_count = 5 out &&
2337 git ls-files -u >out &&
2338 test_line_count = 2 out &&
2339 git ls-files -o >out &&
2340 test_line_count = 1 out &&
2342 git rev-parse >actual \
2343 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2344 git rev-parse >expect \
2345 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2346 test_cmp expect actual &&
2348 test_must_fail git rev-parse :2:z/d &&
2349 git ls-files -s z/d | grep ^100755 &&
2350 test_path_is_file z/d &&
2351 test_path_is_missing y/d
2355 # Testcase 8d, rename/delete...or not?
2356 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2357 # Also related to testcases 7d and 7e)
2358 # Commit O: z/{b,c,d}
2360 # Commit B: z/{b,c,d,e}
2361 # Expected: y/{b,c,e}
2363 # Note: It would also be somewhat reasonable to resolve this as
2364 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2366 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2367 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2368 # delete) are both coming from commit A, which is illogical. Conflicts
2369 # during merging are supposed to be about opposite sides doing things
2373 test_create_repo
8d
&&
2380 test_seq
1 10 >z
/d
&&
2383 git commit
-m "O" &&
2393 git commit
-m "A" &&
2403 test_expect_success
'8d: rename/delete...or not?' '
2410 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2412 git ls-files -s >out &&
2413 test_line_count = 3 out &&
2415 git rev-parse >actual \
2416 HEAD:y/b HEAD:y/c HEAD:y/e &&
2417 git rev-parse >expect \
2418 O:z/b O:z/c B:z/e &&
2419 test_cmp expect actual
2423 # Testcase 8e, Both sides rename, one side adds to original directory
2426 # Commit B: w/{b,c}, z/d
2428 # Possible Resolutions:
2429 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2430 # CONFLICT(z/c -> y/c vs. w/c)
2431 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2432 # CONFLICT(z/c -> y/c vs. w/c)
2435 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2436 # did NOT get renamed; the directory is still present; instead it is
2437 # considered to have just renamed a subset of paths in directory z
2438 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2439 # the original paths out of z/ but opted to keep d within z/).
2441 # It was not clear in the past what should be done with this testcase;
2442 # in fact, I noted that I "just picked one" previously. However,
2443 # following the new logic for testcase 6b2, we should take the rename
2444 # and move z/d to y/d.
2446 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2447 # whether they are optimal for end users, but (a) the default for
2448 # directory rename detection is to mark these all as conflicts
2449 # anyway, (b) it feels like this is less prone to higher order corner
2450 # case confusion, and (c) the current algorithm requires less global
2451 # knowledge (i.e. less coupling in the algorithm between renames done
2452 # on both sides) which thus means users are better able to predict
2453 # the behavior, and predict it without computing as many details.
2456 test_create_repo
8e
&&
2465 git commit
-m "O" &&
2474 git commit
-m "A" &&
2486 test_expect_success
'8e: Both sides rename, one side adds to original directory' '
2493 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2494 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2495 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2497 git ls-files -s >out &&
2498 test_line_count = 7 out &&
2499 git ls-files -u >out &&
2500 test_line_count = 6 out &&
2501 git ls-files -o >out &&
2502 test_line_count = 2 out &&
2504 git rev-parse >actual \
2505 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2506 git rev-parse >expect \
2507 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2508 test_cmp expect actual &&
2510 git hash-object >actual \
2512 git rev-parse >expect \
2513 O:z/b O:z/b O:z/c O:z/c &&
2514 test_cmp expect actual &&
2516 test_path_is_missing z/b &&
2517 test_path_is_missing z/c
2521 ###########################################################################
2522 # SECTION 9: Other testcases
2524 # This section consists of miscellaneous testcases I thought of during
2525 # the implementation which round out the testing.
2526 ###########################################################################
2528 # Testcase 9a, Inner renamed directory within outer renamed directory
2529 # (Related to testcase 1f)
2530 # Commit O: z/{b,c,d/{e,f,g}}
2531 # Commit A: y/{b,c}, x/w/{e,f,g}
2532 # Commit B: z/{b,c,d/{e,f,g,h},i}
2533 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2534 # NOTE: The only reason this one is interesting is because when a directory
2535 # is split into multiple other directories, we determine by the weight
2536 # of which one had the most paths going to it. A naive implementation
2537 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2540 test_create_repo
9a
&&
2552 git commit
-m "O" &&
2563 git commit
-m "A" &&
2574 test_expect_success
'9a: Inner renamed directory within outer renamed directory' '
2581 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2583 git ls-files -s >out &&
2584 test_line_count = 7 out &&
2585 git ls-files -u >out &&
2586 test_line_count = 0 out &&
2587 git ls-files -o >out &&
2588 test_line_count = 1 out &&
2590 git rev-parse >actual \
2591 HEAD:y/b HEAD:y/c HEAD:y/i &&
2592 git rev-parse >expect \
2593 O:z/b O:z/c B:z/i &&
2594 test_cmp expect actual &&
2596 git rev-parse >actual \
2597 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2598 git rev-parse >expect \
2599 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2600 test_cmp expect actual
2604 # Testcase 9b, Transitive rename with content merge
2605 # (Related to testcase 1c)
2606 # Commit O: z/{b,c}, x/d_1
2607 # Commit A: y/{b,c}, x/d_2
2608 # Commit B: z/{b,c,d_3}
2609 # Expected: y/{b,c,d_merged}
2612 test_create_repo
9b
&&
2620 test_seq
1 10 >x
/d
&&
2623 git commit
-m "O" &&
2631 test_seq
1 11 >x
/d
&&
2634 git commit
-m "A" &&
2637 test_seq
0 10 >x
/d
&&
2645 test_expect_success
'9b: Transitive rename with content merge' '
2652 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2654 git ls-files -s >out &&
2655 test_line_count = 3 out &&
2657 test_seq 0 11 >expected &&
2658 test_cmp expected y/d &&
2660 git rev-parse >actual \
2661 HEAD:y/b HEAD:y/c HEAD:y/d &&
2662 git rev-parse >expect \
2663 O:z/b O:z/c :0:expected &&
2664 test_cmp expect actual &&
2665 test_must_fail git rev-parse HEAD:x/d &&
2666 test_must_fail git rev-parse HEAD:z/d &&
2667 test_path_is_missing z/d &&
2669 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2670 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2671 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2675 # Testcase 9c, Doubly transitive rename?
2676 # (Related to testcase 1c, 7e, and 9d)
2677 # Commit O: z/{b,c}, x/{d,e}, w/f
2678 # Commit A: y/{b,c}, x/{d,e,f,g}
2679 # Commit B: z/{b,c,d,e}, w/f
2680 # Expected: y/{b,c,d,e}, x/{f,g}
2682 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2683 # x/f is clear. Let's look beyond that. Here's the logic:
2684 # Commit B renamed x/ -> z/
2685 # Commit A renamed z/ -> y/
2686 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2687 # transient rename. However, where does it end? We can chain these
2688 # indefinitely (see testcase 9d). What if there is a D/F conflict
2689 # at z/f/ or y/f/? Or just another file conflict at one of those
2690 # paths? In the case of an N-long chain of transient renamings,
2691 # where do we "abort" the rename at? Can the user make sense of
2692 # the resulting conflict and resolve it?
2694 # To avoid this confusion I use the simple rule that if the other side
2695 # of history did a directory rename to a path that your side renamed
2696 # away, then ignore that particular rename from the other side of
2697 # history for any implicit directory renames.
2700 test_create_repo
9c
&&
2714 git commit
-m "O" &&
2726 git commit
-m "A" &&
2736 test_expect_success
'9c: Doubly transitive rename?' '
2743 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2744 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2746 git ls-files -s >out &&
2747 test_line_count = 6 out &&
2748 git ls-files -o >out &&
2749 test_line_count = 1 out &&
2751 git rev-parse >actual \
2752 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2753 git rev-parse >expect \
2754 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2755 test_cmp expect actual
2759 # Testcase 9d, N-fold transitive rename?
2760 # (Related to testcase 9c...and 1c and 7e)
2761 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2762 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2763 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2764 # Expected: <see NOTE first>
2766 # NOTE: z/ -> y/ (in commit A)
2767 # y/ -> x/ (in commit B)
2768 # x/ -> w/ (in commit A)
2769 # w/ -> v/ (in commit B)
2770 # v/ -> u/ (in commit A)
2771 # So, if we add a file to z, say z/t, where should it end up? In u?
2772 # What if there's another file or directory named 't' in one of the
2773 # intervening directories and/or in u itself? Also, shouldn't the
2774 # same logic that places 't' in u/ also move ALL other files to u/?
2775 # What if there are file or directory conflicts in any of them? If
2776 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2777 # like this, would the user have any hope of understanding any
2778 # conflicts or how their working tree ended up? I think not, so I'm
2779 # ruling out N-ary transitive renames for N>1.
2781 # Therefore our expected result is:
2782 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2783 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2784 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2785 # simple rules that are consistent with what we need for all the other
2786 # testcases and simplifies things for the user.
2789 test_create_repo
9d
&&
2793 mkdir z y x w v u
&&
2800 git add z y x w v u
&&
2802 git commit
-m "O" &&
2813 git commit
-m "A" &&
2825 test_expect_success
'9d: N-way transitive rename?' '
2832 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2833 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2834 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2835 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2836 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2838 git ls-files -s >out &&
2839 test_line_count = 7 out &&
2840 git ls-files -o >out &&
2841 test_line_count = 1 out &&
2843 git rev-parse >actual \
2845 HEAD:y/a HEAD:x/b HEAD:w/c \
2846 HEAD:u/d HEAD:u/e HEAD:u/f &&
2847 git rev-parse >expect \
2850 O:w/d O:v/e A:u/f &&
2851 test_cmp expect actual
2855 # Testcase 9e, N-to-1 whammo
2856 # (Related to testcase 9c...and 1c and 7e)
2857 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2858 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2859 # Commit B: combined/{a,b,d,e,g,h,j,k}
2860 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2861 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2864 test_create_repo
9e
&&
2868 mkdir dir1 dir2 dir3 dirN
&&
2879 git commit
-m "O" &&
2896 git commit
-m "A" &&
2899 git
mv dir1 combined
&&
2900 git
mv dir
2/* combined
/ &&
2901 git
mv dir
3/* combined
/ &&
2902 git
mv dirN
/* combined
/ &&
2908 test_expect_success
'9e: N-to-1 whammo' '
2915 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2916 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2917 grep -q dir1/yo error_line &&
2918 grep -q dir2/yo error_line &&
2919 grep -q dir3/yo error_line &&
2920 grep -q dirN/yo error_line &&
2922 git ls-files -s >out &&
2923 test_line_count = 16 out &&
2924 git ls-files -u >out &&
2925 test_line_count = 0 out &&
2926 git ls-files -o >out &&
2927 test_line_count = 2 out &&
2929 git rev-parse >actual \
2930 :0:combined/a :0:combined/b :0:combined/c \
2931 :0:combined/d :0:combined/e :0:combined/f \
2932 :0:combined/g :0:combined/h :0:combined/i \
2933 :0:combined/j :0:combined/k :0:combined/l &&
2934 git rev-parse >expect \
2935 O:dir1/a O:dir1/b A:dir1/c \
2936 O:dir2/d O:dir2/e A:dir2/f \
2937 O:dir3/g O:dir3/h A:dir3/i \
2938 O:dirN/j O:dirN/k A:dirN/l &&
2939 test_cmp expect actual &&
2941 git rev-parse >actual \
2942 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2943 git rev-parse >expect \
2944 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2945 test_cmp expect actual
2949 # Testcase 9f, Renamed directory that only contained immediate subdirs
2950 # (Related to testcases 1e & 9g)
2951 # Commit O: goal/{a,b}/$more_files
2952 # Commit A: priority/{a,b}/$more_files
2953 # Commit B: goal/{a,b}/$more_files, goal/c
2954 # Expected: priority/{a,b}/$more_files, priority/c
2957 test_create_repo
9f
&&
2963 echo foo
>goal
/a
/foo
&&
2964 echo bar
>goal
/b
/bar
&&
2965 echo baz
>goal
/b
/baz
&&
2968 git commit
-m "O" &&
2975 git
mv goal
/ priority
&&
2977 git commit
-m "A" &&
2987 test_expect_success
'9f: Renamed directory that only contained immediate subdirs' '
2994 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2996 git ls-files -s >out &&
2997 test_line_count = 4 out &&
2999 git rev-parse >actual \
3000 HEAD:priority/a/foo \
3001 HEAD:priority/b/bar \
3002 HEAD:priority/b/baz \
3004 git rev-parse >expect \
3009 test_cmp expect actual &&
3010 test_must_fail git rev-parse HEAD:goal/c
3014 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
3015 # (Related to testcases 1e & 9f)
3016 # Commit O: goal/{a,b}/$more_files
3017 # Commit A: priority/{alpha,bravo}/$more_files
3018 # Commit B: goal/{a,b}/$more_files, goal/c
3019 # Expected: priority/{alpha,bravo}/$more_files, priority/c
3020 # We currently fail this test because the directory renames we detect are
3021 # goal/a/ -> priority/alpha/
3022 # goal/b/ -> priority/bravo/
3024 # goal/ -> priority/
3025 # because of no files found within goal/, and the fact that "a" != "alpha"
3026 # and "b" != "bravo". But I'm not sure it's really a failure given that
3030 test_create_repo
9g
&&
3036 echo foo
>goal
/a
/foo
&&
3037 echo bar
>goal
/b
/bar
&&
3038 echo baz
>goal
/b
/baz
&&
3041 git commit
-m "O" &&
3049 git
mv goal
/a
/ priority
/alpha
&&
3050 git
mv goal
/b
/ priority
/beta
&&
3053 git commit
-m "A" &&
3063 test_expect_failure
'9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
3070 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3072 git ls-files -s >out &&
3073 test_line_count = 4 out &&
3075 git rev-parse >actual \
3076 HEAD:priority/alpha/foo \
3077 HEAD:priority/beta/bar \
3078 HEAD:priority/beta/baz \
3080 git rev-parse >expect \
3085 test_cmp expect actual &&
3086 test_must_fail git rev-parse HEAD:goal/c
3090 # Testcase 9h, Avoid implicit rename if involved as source on other side
3091 # (Extremely closely related to testcase 3a)
3092 # Commit O: z/{b,c,d_1}
3093 # Commit A: z/{b,c,d_2}
3094 # Commit B: y/{b,c}, x/d_1
3095 # Expected: y/{b,c}, x/d_2
3096 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3097 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3099 test_create_repo
9h
&&
3106 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z
/d
&&
3109 git commit
-m "O" &&
3119 git commit
-m "A" &&
3133 test_expect_success
'9h: Avoid dir rename on merely modified path' '
3140 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3142 git ls-files -s >out &&
3143 test_line_count = 3 out &&
3145 git rev-parse >actual \
3146 HEAD:y/b HEAD:y/c HEAD:x/d &&
3147 git rev-parse >expect \
3148 O:z/b O:z/c A:z/d &&
3149 test_cmp expect actual
3153 ###########################################################################
3154 # Rules suggested by section 9:
3156 # If the other side of history did a directory rename to a path that your
3157 # side renamed away, then ignore that particular rename from the other
3158 # side of history for any implicit directory renames.
3159 ###########################################################################
3161 ###########################################################################
3162 # SECTION 10: Handling untracked files
3164 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3165 # the operation if untracked or dirty files would be deleted or overwritten
3166 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3167 # and if it doesn't abort, then it muddies up the working directory before
3168 # we even get to the point of detecting renames, so we need some special
3169 # handling, at least in the case of directory renames.
3170 ###########################################################################
3172 # Testcase 10a, Overwrite untracked: normal rename/delete
3173 # Commit O: z/{b,c_1}
3174 # Commit A: z/b + untracked z/c + untracked z/d
3175 # Commit B: z/{b,d_1}
3176 # Expected: Aborted Merge +
3177 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3180 test_create_repo
10a
&&
3189 git commit
-m "O" &&
3198 git commit
-m "A" &&
3207 test_expect_success
'10a: Overwrite untracked with normal rename/delete' '
3214 echo important >z/d &&
3216 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3217 test_path_is_missing .git/MERGE_HEAD &&
3218 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3220 git ls-files -s >out &&
3221 test_line_count = 1 out &&
3222 git ls-files -o >out &&
3223 test_line_count = 4 out &&
3225 echo very >expect &&
3226 test_cmp expect z/c &&
3228 echo important >expect &&
3229 test_cmp expect z/d &&
3231 git rev-parse HEAD:z/b >actual &&
3232 git rev-parse O:z/b >expect &&
3233 test_cmp expect actual
3237 # Testcase 10b, Overwrite untracked: dir rename + delete
3238 # Commit O: z/{b,c_1}
3239 # Commit A: y/b + untracked y/{c,d,e}
3240 # Commit B: z/{b,d_1,e}
3241 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3242 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3243 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3246 test_create_repo
10b
&&
3255 git commit
-m "O" &&
3265 git commit
-m "A" &&
3276 test_expect_success
'10b: Overwrite untracked with dir rename + delete' '
3283 echo important >y/d &&
3284 echo contents >y/e &&
3286 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3287 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3289 test_path_is_missing .git/MERGE_HEAD &&
3290 test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3292 git ls-files -s >out &&
3293 test_line_count = 1 out &&
3294 git ls-files -u >out &&
3295 test_line_count = 0 out &&
3296 git ls-files -o >out &&
3297 test_line_count = 5 out
3299 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3300 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3302 git ls-files -s >out &&
3303 test_line_count = 3 out &&
3304 git ls-files -u >out &&
3305 test_line_count = 2 out &&
3306 git ls-files -o >out &&
3307 test_line_count = 5 out &&
3309 git rev-parse >actual \
3310 :0:y/b :3:y/d :3:y/e &&
3311 git rev-parse >expect \
3312 O:z/b O:z/c B:z/e &&
3313 test_cmp expect actual
3316 echo very >expect &&
3317 test_cmp expect y/c &&
3319 echo important >expect &&
3320 test_cmp expect y/d &&
3322 echo contents >expect &&
3327 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3328 # Commit O: z/{a,b}, x/{c,d}
3329 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3330 # Commit B: z/{a,b,c}, x/d
3331 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3332 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3334 # ERROR_MSG(Refusing to lose untracked file at y/c)
3337 test_create_repo
10c_
$1 &&
3348 git commit
-m "O" &&
3359 git commit
-m "A" &&
3368 test_expect_success
'10c1: Overwrite untracked with dir rename/rename(1to2)' '
3374 echo important >y/c &&
3376 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3377 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3379 test_path_is_missing .git/MERGE_HEAD &&
3380 test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3382 git ls-files -s >out &&
3383 test_line_count = 4 out &&
3384 git ls-files -u >out &&
3385 test_line_count = 0 out &&
3386 git ls-files -o >out &&
3387 test_line_count = 3 out
3389 test_i18ngrep "CONFLICT (rename/rename)" out &&
3390 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3392 git ls-files -s >out &&
3393 test_line_count = 6 out &&
3394 git ls-files -u >out &&
3395 test_line_count = 3 out &&
3396 git ls-files -o >out &&
3397 test_line_count = 3 out &&
3399 git rev-parse >actual \
3400 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3401 git rev-parse >expect \
3402 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3403 test_cmp expect actual &&
3405 git hash-object y/c~B^0 >actual &&
3406 git rev-parse O:x/c >expect &&
3407 test_cmp expect actual
3410 echo important >expect &&
3415 test_expect_success
'10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3425 echo important >y/c &&
3427 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3428 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3430 test_path_is_missing .git/MERGE_HEAD &&
3431 test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3433 git ls-files -s >out &&
3434 test_line_count = 4 out &&
3435 git ls-files -u >out &&
3436 test_line_count = 0 out &&
3437 git ls-files -o >out &&
3438 test_line_count = 3 out
3440 test_i18ngrep "CONFLICT (rename/rename)" out &&
3441 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3443 git ls-files -s >out &&
3444 test_line_count = 6 out &&
3445 git ls-files -u >out &&
3446 test_line_count = 3 out &&
3447 git ls-files -o >out &&
3448 test_line_count = 3 out &&
3450 git rev-parse >actual \
3451 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3452 git rev-parse >expect \
3453 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3454 test_cmp expect actual &&
3456 git hash-object y/c~HEAD >actual &&
3457 git rev-parse O:x/c >expect &&
3458 test_cmp expect actual
3461 echo important >expect &&
3466 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3467 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3468 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3469 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3470 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3471 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3472 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3475 test_create_repo
10d
&&
3488 git commit
-m "O" &&
3495 git
mv z
/c x
/wham
&&
3498 git commit
-m "A" &&
3501 git
mv x
/f z
/wham
&&
3508 test_expect_success
'10d: Delete untracked with dir rename/rename(2to1)' '
3514 echo important >y/wham &&
3516 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3517 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3519 test_path_is_missing .git/MERGE_HEAD &&
3520 test_i18ngrep "error: The following untracked working tree files would be overwritten by merge" err &&
3522 git ls-files -s >out &&
3523 test_line_count = 6 out &&
3524 git ls-files -u >out &&
3525 test_line_count = 0 out &&
3526 git ls-files -o >out &&
3527 test_line_count = 3 out
3529 test_i18ngrep "CONFLICT (rename/rename)" out &&
3530 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3532 git ls-files -s >out &&
3533 test_line_count = 6 out &&
3534 git ls-files -u >out &&
3535 test_line_count = 2 out &&
3536 git ls-files -o >out &&
3537 test_line_count = 3 out &&
3539 git rev-parse >actual \
3540 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3541 git rev-parse >expect \
3542 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3543 test_cmp expect actual &&
3545 test_must_fail git rev-parse :1:y/wham &&
3547 # Test that two-way merge in y/wham~merged is as expected
3548 git cat-file -p :2:y/wham >expect &&
3549 git cat-file -p :3:y/wham >other &&
3551 test_must_fail git merge-file \
3555 expect empty other &&
3556 test_cmp expect y/wham~merged
3559 echo important >expect &&
3560 test_cmp expect y/wham
3564 # Testcase 10e, Does git complain about untracked file that's not in the way?
3566 # Commit A: y/{a,b} + untracked z/c
3567 # Commit B: z/{a,b,c}
3568 # Expected: y/{a,b,c} + untracked z/c
3571 test_create_repo
10e
&&
3580 git commit
-m "O" &&
3589 git commit
-m "A" &&
3599 test_expect_merge_algorithm failure success
'10e: Does git complain about untracked file that is not really in the way?' '
3608 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3609 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3611 git ls-files -s >out &&
3612 test_line_count = 3 out &&
3613 git ls-files -u >out &&
3614 test_line_count = 0 out &&
3615 git ls-files -o >out &&
3616 test_line_count = 3 out &&
3618 git rev-parse >actual \
3619 :0:y/a :0:y/b :0:y/c &&
3620 git rev-parse >expect \
3621 O:z/a O:z/b B:z/c &&
3622 test_cmp expect actual &&
3624 echo random >expect &&
3629 ###########################################################################
3630 # SECTION 11: Handling dirty (not up-to-date) files
3632 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3633 # the operation if untracked or dirty files would be deleted or overwritten
3634 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3635 # and if it doesn't abort, then it muddies up the working directory before
3636 # we even get to the point of detecting renames, so we need some special
3637 # handling. This was true even of normal renames, but there are additional
3638 # codepaths that need special handling with directory renames. Add
3639 # testcases for both renamed-by-directory-rename-detection and standard
3641 ###########################################################################
3643 # Testcase 11a, Avoid losing dirty contents with simple rename
3644 # Commit O: z/{a,b_v1},
3645 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3646 # Commit B: z/{a,b_v2}
3647 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3648 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3649 # z/c~HEAD with contents of B:z/b_v2,
3650 # z/c with uncommitted mods on top of A:z/c_v1
3653 test_create_repo
11a
&&
3659 test_seq
1 10 >z
/b
&&
3662 git commit
-m "O" &&
3671 git commit
-m "A" &&
3681 test_expect_success
'11a: Avoid losing dirty contents with simple rename' '
3689 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3690 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3692 test_path_is_missing .git/MERGE_HEAD &&
3693 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3695 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3697 git ls-files -s >out &&
3698 test_line_count = 2 out &&
3699 git ls-files -u >out &&
3700 test_line_count = 1 out &&
3701 git ls-files -o >out &&
3702 test_line_count = 3 out &&
3704 git rev-parse >actual \
3706 git rev-parse >expect \
3708 test_cmp expect actual &&
3710 git hash-object z/c~HEAD >actual &&
3711 git rev-parse B:z/b >expect &&
3712 test_cmp expect actual
3715 test_seq 1 10 >expected &&
3716 echo stuff >>expected &&
3717 test_cmp expected z/c
3722 # Testcase 11b, Avoid losing dirty file involved in directory rename
3723 # Commit O: z/a, x/{b,c_v1}
3724 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3725 # Commit B: y/a, x/{b,c_v2}
3726 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3727 # ERROR_MSG(Refusing to lose dirty file at z/c)
3731 test_create_repo
11b
&&
3738 test_seq
1 10 >x
/c
&&
3741 git commit
-m "O" &&
3750 git commit
-m "A" &&
3761 test_expect_success
'11b: Avoid losing dirty file involved in directory rename' '
3769 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3771 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3772 test_path_is_missing .git/MERGE_HEAD &&
3773 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3775 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3776 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3778 git ls-files -s >out &&
3779 test_line_count = 3 out &&
3780 git ls-files -u >out &&
3781 test_line_count = 0 out &&
3782 git ls-files -m >out &&
3783 test_line_count = 0 out &&
3784 git ls-files -o >out &&
3785 test_line_count = 3 out &&
3787 git rev-parse >actual \
3788 :0:x/b :0:y/a :0:y/c &&
3789 git rev-parse >expect \
3790 O:x/b O:z/a B:x/c &&
3791 test_cmp expect actual &&
3793 git hash-object y/c >actual &&
3794 git rev-parse B:x/c >expect &&
3795 test_cmp expect actual
3798 grep -q stuff z/c &&
3799 test_seq 1 10 >expected &&
3800 echo stuff >>expected &&
3801 test_cmp expected z/c
3805 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3806 # Commit O: y/a, x/{b,c_v1}
3807 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3808 # Commit B: y/{a,c/d}, x/{b,c_v2}
3809 # Expected: Abort_msg("following files would be overwritten by merge") +
3810 # y/c left untouched (still has uncommitted mods)
3813 test_create_repo
11c
&&
3820 test_seq
1 10 >x
/c
&&
3823 git commit
-m "O" &&
3832 git commit
-m "A" &&
3838 git add x
/c y
/c
/d
&&
3844 test_expect_success
'11c: Avoid losing not-uptodate with rename + D/F conflict' '
3852 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3853 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3855 test_path_is_missing .git/MERGE_HEAD &&
3856 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3858 test_i18ngrep "following files would be overwritten by merge" err
3861 grep -q stuff y/c &&
3862 test_seq 1 10 >expected &&
3863 echo stuff >>expected &&
3864 test_cmp expected y/c &&
3866 git ls-files -s >out &&
3867 test_line_count = 3 out &&
3868 git ls-files -u >out &&
3869 test_line_count = 0 out &&
3870 git ls-files -m >out &&
3871 test_line_count = 1 out &&
3872 git ls-files -o >out &&
3873 test_line_count = 3 out
3877 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3878 # Commit O: z/a, x/{b,c_v1}
3879 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3880 # Commit B: y/{a,c/d}, x/{b,c_v2}
3881 # Expected: D/F: y/c_v2 vs y/c/d) +
3882 # Warning_Msg("Refusing to lose dirty file at z/c) +
3883 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3886 test_create_repo
11d
&&
3893 test_seq
1 10 >x
/c
&&
3896 git commit
-m "O" &&
3905 git commit
-m "A" &&
3912 git add x
/c y
/c
/d
&&
3918 test_expect_success
'11d: Avoid losing not-uptodate with rename + D/F conflict' '
3926 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3927 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3929 test_path_is_missing .git/MERGE_HEAD &&
3930 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
3932 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3934 git ls-files -s >out &&
3935 test_line_count = 4 out &&
3936 git ls-files -u >out &&
3937 test_line_count = 1 out &&
3938 git ls-files -o >out &&
3939 test_line_count = 4 out &&
3941 git rev-parse >actual \
3942 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3943 git rev-parse >expect \
3944 O:x/b O:z/a B:y/c/d B:x/c &&
3945 test_cmp expect actual &&
3947 git hash-object y/c~HEAD >actual &&
3948 git rev-parse B:x/c >expect &&
3949 test_cmp expect actual
3952 grep -q stuff z/c &&
3953 test_seq 1 10 >expected &&
3954 echo stuff >>expected &&
3955 test_cmp expected z/c
3959 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3960 # Commit O: z/{a,b}, x/{c_1,d}
3961 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3962 # Commit B: z/{a,b,c_1}, x/d
3963 # Expected: Failed Merge; y/{a,b} + x/d +
3964 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3965 # ERROR_MSG(Refusing to lose dirty file at y/c)
3966 # y/c~B^0 has O:x/c_1 contents
3967 # y/c~HEAD has A:y/c_2 contents
3968 # y/c has dirty file from before merge
3971 test_create_repo
11e
&&
3982 git commit
-m "O" &&
3990 echo different
>y
/c
&&
3995 git commit
-m "A" &&
4004 test_expect_success
'11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
4012 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4013 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4015 test_path_is_missing .git/MERGE_HEAD &&
4016 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
4018 test_i18ngrep "CONFLICT (rename/rename)" out &&
4019 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
4021 git ls-files -s >out &&
4022 test_line_count = 7 out &&
4023 git ls-files -u >out &&
4024 test_line_count = 4 out &&
4025 git ls-files -o >out &&
4026 test_line_count = 3 out &&
4028 git rev-parse >actual \
4029 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
4030 git rev-parse >expect \
4031 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
4032 test_cmp expect actual &&
4034 # See if y/c~merged has expected contents; requires manually
4035 # doing the expected file merge
4036 git cat-file -p A:y/c >c1 &&
4037 git cat-file -p B:z/c >c2 &&
4039 test_must_fail git merge-file \
4044 test_cmp c1 y/c~merged
4047 echo different >expected &&
4048 echo mods >>expected &&
4049 test_cmp expected y/c
4053 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
4054 # Commit O: z/{a,b}, x/{c_1,d_2}
4055 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
4056 # Commit B: z/{a,b,wham_2}, x/c_1
4057 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
4058 # y/wham with dirty changes from before merge +
4059 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
4060 # ERROR_MSG(Refusing to lose dirty file at y/wham)
4063 test_create_repo
11f
&&
4070 test_seq
1 10 >x
/c
&&
4074 git commit
-m "O" &&
4082 git
mv x
/c y
/wham
&&
4084 git commit
-m "A" &&
4087 git
mv x
/d z
/wham
&&
4093 test_expect_success
'11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
4099 echo important >>y/wham &&
4101 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4102 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4104 test_path_is_missing .git/MERGE_HEAD &&
4105 test_i18ngrep "error: Your local changes to the following files would be overwritten by merge" err
4107 test_i18ngrep "CONFLICT (rename/rename)" out &&
4108 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
4110 git ls-files -s >out &&
4111 test_line_count = 4 out &&
4112 git ls-files -u >out &&
4113 test_line_count = 2 out &&
4114 git ls-files -o >out &&
4115 test_line_count = 3 out &&
4117 test_must_fail git rev-parse :1:y/wham &&
4119 git rev-parse >actual \
4120 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4121 git rev-parse >expect \
4122 O:z/a O:z/b O:x/c O:x/d &&
4123 test_cmp expect actual &&
4125 # Test that two-way merge in y/wham~merged is as expected
4126 git cat-file -p :2:y/wham >expect &&
4127 git cat-file -p :3:y/wham >other &&
4129 test_must_fail git merge-file \
4133 expect empty other &&
4134 test_cmp expect y/wham~merged
4137 test_seq 1 10 >expected &&
4138 echo important >>expected &&
4139 test_cmp expected y/wham
4143 ###########################################################################
4144 # SECTION 12: Everything else
4146 # Tests suggested by others. Tests added after implementation completed
4147 # and submitted. Grab bag.
4148 ###########################################################################
4150 # Testcase 12a, Moving one directory hierarchy into another
4151 # (Related to testcase 9a)
4152 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
4153 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
4154 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
4155 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
4158 test_create_repo
12a
&&
4162 mkdir
-p node1 node2
&&
4163 echo leaf1
>node
1/leaf1
&&
4164 echo leaf2
>node
1/leaf2
&&
4165 echo leaf3
>node
2/leaf3
&&
4166 echo leaf4
>node
2/leaf4
&&
4167 git add node1 node2
&&
4169 git commit
-m "O" &&
4176 git
mv node
2/ node
1/ &&
4178 git commit
-m "A" &&
4181 echo leaf5
>node
1/leaf5
&&
4182 echo leaf6
>node
2/leaf6
&&
4183 git add node1 node2
&&
4189 test_expect_success
'12a: Moving one directory hierarchy into another' '
4196 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4198 git ls-files -s >out &&
4199 test_line_count = 6 out &&
4201 git rev-parse >actual \
4202 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4203 HEAD:node1/node2/leaf3 \
4204 HEAD:node1/node2/leaf4 \
4205 HEAD:node1/node2/leaf6 &&
4206 git rev-parse >expect \
4207 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4211 test_cmp expect actual
4215 # Testcase 12b1, Moving two directory hierarchies into each other
4216 # (Related to testcases 1c and 12c)
4217 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4218 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4219 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4220 # Expected: node1/node2/{leaf3, leaf4}
4221 # node2/node1/{leaf1, leaf2}
4222 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4223 # then we would need to detect renames for those directories and would
4225 # commit A renames node2/ -> node1/node2/
4226 # commit B renames node1/ -> node2/node1/
4227 # Applying those directory renames to the initial result (making all
4228 # four paths experience a transitive renaming), yields
4229 # node1/node2/node1/{leaf1, leaf2}
4230 # node2/node1/node2/{leaf3, leaf4}
4231 # as the result. It may be really weird to have two directories
4232 # rename each other, but simple rules give weird results when given
4233 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4234 # false; there were no new files added and thus there is no directory
4235 # rename detection to perform. As such, we just have simple renames
4236 # and the expected answer is:
4237 # node1/node2/{leaf3, leaf4}
4238 # node2/node1/{leaf1, leaf2}
4240 test_setup_12b1
() {
4241 test_create_repo
12b1
&&
4245 mkdir
-p node1 node2
&&
4246 echo leaf1
>node
1/leaf1
&&
4247 echo leaf2
>node
1/leaf2
&&
4248 echo leaf3
>node
2/leaf3
&&
4249 echo leaf4
>node
2/leaf4
&&
4250 git add node1 node2
&&
4252 git commit
-m "O" &&
4259 git
mv node
2/ node
1/ &&
4261 git commit
-m "A" &&
4264 git
mv node
1/ node
2/ &&
4270 test_expect_merge_algorithm failure success
'12b1: Moving two directory hierarchies into each other' '
4277 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4279 git ls-files -s >out &&
4280 test_line_count = 4 out &&
4282 git rev-parse >actual \
4283 HEAD:node2/node1/leaf1 \
4284 HEAD:node2/node1/leaf2 \
4285 HEAD:node1/node2/leaf3 \
4286 HEAD:node1/node2/leaf4 &&
4287 git rev-parse >expect \
4292 test_cmp expect actual
4296 # Testcase 12b2, Moving two directory hierarchies into each other
4297 # (Related to testcases 1c and 12c)
4298 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4299 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4300 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4301 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4302 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4303 # NOTE: Without directory renames, we would expect
4304 # A: node2/leaf3 -> node1/node2/leaf3
4305 # A: node2/leaf1 -> node1/node2/leaf4
4306 # A: Adds node1/leaf5
4307 # B: node1/leaf1 -> node2/node1/leaf1
4308 # B: node1/leaf2 -> node2/node1/leaf2
4309 # B: Adds node2/leaf6
4310 # with directory rename detection, we note that
4311 # commit A renames node2/ -> node1/node2/
4312 # commit B renames node1/ -> node2/node1/
4313 # therefore, applying A's directory rename to the paths added in B gives:
4314 # B: node1/leaf1 -> node1/node2/node1/leaf1
4315 # B: node1/leaf2 -> node1/node2/node1/leaf2
4316 # B: Adds node1/node2/leaf6
4317 # and applying B's directory rename to the paths added in A gives:
4318 # A: node2/leaf3 -> node2/node1/node2/leaf3
4319 # A: node2/leaf1 -> node2/node1/node2/leaf4
4320 # A: Adds node2/node1/leaf5
4321 # resulting in the expected
4322 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4323 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4325 # You may ask, is it weird to have two directories rename each other?
4326 # To which, I can do no more than shrug my shoulders and say that
4327 # even simple rules give weird results when given weird inputs.
4329 test_setup_12b2
() {
4330 test_create_repo
12b2
&&
4334 mkdir
-p node1 node2
&&
4335 echo leaf1
>node
1/leaf1
&&
4336 echo leaf2
>node
1/leaf2
&&
4337 echo leaf3
>node
2/leaf3
&&
4338 echo leaf4
>node
2/leaf4
&&
4339 git add node1 node2
&&
4341 git commit
-m "O" &&
4348 git
mv node
2/ node
1/ &&
4349 echo leaf5
>node
1/leaf5
&&
4350 git add node
1/leaf5
&&
4352 git commit
-m "A" &&
4355 git
mv node
1/ node
2/ &&
4356 echo leaf6
>node
2/leaf6
&&
4357 git add node
2/leaf6
&&
4363 test_expect_success
'12b2: Moving two directory hierarchies into each other' '
4370 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4372 git ls-files -s >out &&
4373 test_line_count = 6 out &&
4375 git rev-parse >actual \
4376 HEAD:node1/node2/node1/leaf1 \
4377 HEAD:node1/node2/node1/leaf2 \
4378 HEAD:node2/node1/node2/leaf3 \
4379 HEAD:node2/node1/node2/leaf4 \
4380 HEAD:node2/node1/leaf5 \
4381 HEAD:node1/node2/leaf6 &&
4382 git rev-parse >expect \
4389 test_cmp expect actual
4393 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4394 # (Related to testcase 12b)
4395 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4396 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4397 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4398 # Expected: Content merge conflicts for each of:
4399 # node1/node2/node1/{leaf1, leaf2},
4400 # node2/node1/node2/{leaf3, leaf4}
4401 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4402 # each side of the merge.
4404 test_setup_12c1
() {
4405 test_create_repo
12c1
&&
4409 mkdir
-p node1 node2
&&
4410 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4411 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4412 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4413 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4414 git add node1 node2
&&
4416 git commit
-m "O" &&
4423 git
mv node
2/ node
1/ &&
4424 for i
in $
(git ls-files
); do echo side A
>>$i; done &&
4427 git commit
-m "A" &&
4430 git
mv node
1/ node
2/ &&
4431 for i
in $
(git ls-files
); do echo side B
>>$i; done &&
4438 test_expect_merge_algorithm failure success
'12c1: Moving one directory hierarchy into another w/ content merge' '
4445 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4447 git ls-files -u >out &&
4448 test_line_count = 12 out &&
4450 git rev-parse >actual \
4451 :1:node2/node1/leaf1 \
4452 :1:node2/node1/leaf2 \
4453 :1:node1/node2/leaf3 \
4454 :1:node1/node2/leaf4 \
4455 :2:node2/node1/leaf1 \
4456 :2:node2/node1/leaf2 \
4457 :2:node1/node2/leaf3 \
4458 :2:node1/node2/leaf4 \
4459 :3:node2/node1/leaf1 \
4460 :3:node2/node1/leaf2 \
4461 :3:node1/node2/leaf3 \
4462 :3:node1/node2/leaf4 &&
4463 git rev-parse >expect \
4470 A:node1/node2/leaf3 \
4471 A:node1/node2/leaf4 \
4472 B:node2/node1/leaf1 \
4473 B:node2/node1/leaf2 \
4476 test_cmp expect actual
4480 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4481 # (Related to testcase 12b)
4482 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4483 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4484 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4485 # Expected: Content merge conflicts for each of:
4486 # node1/node2/node1/{leaf1, leaf2}
4487 # node2/node1/node2/{leaf3, leaf4}
4491 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4492 # on each side of the merge.
4494 test_setup_12c2
() {
4495 test_create_repo
12c2
&&
4499 mkdir
-p node1 node2
&&
4500 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node
1/leaf1
&&
4501 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node
1/leaf2
&&
4502 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node
2/leaf3
&&
4503 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node
2/leaf4
&&
4504 git add node1 node2
&&
4506 git commit
-m "O" &&
4513 git
mv node
2/ node
1/ &&
4514 for i
in $
(git ls-files
); do echo side A
>>$i; done &&
4516 echo leaf5
>node
1/leaf5
&&
4517 git add node
1/leaf5
&&
4519 git commit
-m "A" &&
4522 git
mv node
1/ node
2/ &&
4523 for i
in $
(git ls-files
); do echo side B
>>$i; done &&
4525 echo leaf6
>node
2/leaf6
&&
4526 git add node
2/leaf6
&&
4532 test_expect_success
'12c2: Moving one directory hierarchy into another w/ content merge' '
4539 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4541 git ls-files -s >out &&
4542 test_line_count = 14 out &&
4543 git ls-files -u >out &&
4544 test_line_count = 12 out &&
4546 git rev-parse >actual \
4547 :1:node1/node2/node1/leaf1 \
4548 :1:node1/node2/node1/leaf2 \
4549 :1:node2/node1/node2/leaf3 \
4550 :1:node2/node1/node2/leaf4 \
4551 :2:node1/node2/node1/leaf1 \
4552 :2:node1/node2/node1/leaf2 \
4553 :2:node2/node1/node2/leaf3 \
4554 :2:node2/node1/node2/leaf4 \
4555 :3:node1/node2/node1/leaf1 \
4556 :3:node1/node2/node1/leaf2 \
4557 :3:node2/node1/node2/leaf3 \
4558 :3:node2/node1/node2/leaf4 \
4559 :0:node2/node1/leaf5 \
4560 :0:node1/node2/leaf6 &&
4561 git rev-parse >expect \
4568 A:node1/node2/leaf3 \
4569 A:node1/node2/leaf4 \
4570 B:node2/node1/leaf1 \
4571 B:node2/node1/leaf2 \
4576 test_cmp expect actual
4580 # Testcase 12d, Rename/merge of subdirectory into the root
4581 # Commit O: a/b/subdir/foo
4582 # Commit A: subdir/foo
4583 # Commit B: a/b/subdir/foo, a/b/bar
4584 # Expected: subdir/foo, bar
4587 test_create_repo
12d
&&
4591 mkdir
-p a
/b
/subdir
&&
4592 test_commit a
/b
/subdir
/foo
&&
4600 git
mv a
/b
/subdir
/foo.t subdir
/foo.t
&&
4602 git commit
-m "A" &&
4609 test_expect_success
'12d: Rename/merge subdir into the root, variant 1' '
4616 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4618 git ls-files -s >out &&
4619 test_line_count = 2 out &&
4621 git rev-parse >actual \
4622 HEAD:subdir/foo.t HEAD:bar.t &&
4623 git rev-parse >expect \
4624 O:a/b/subdir/foo.t B:a/b/bar.t &&
4625 test_cmp expect actual &&
4627 git hash-object bar.t >actual &&
4628 git rev-parse B:a/b/bar.t >expect &&
4629 test_cmp expect actual &&
4631 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4632 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4633 test_path_is_missing a/ &&
4634 test_path_is_file bar.t
4638 # Testcase 12e, Rename/merge of subdirectory into the root
4641 # Commit B: a/b/foo, a/b/bar
4642 # Expected: foo, bar
4645 test_create_repo
12e
&&
4650 test_commit a
/b
/foo
&&
4658 git
mv a
/b
/foo.t foo.t
&&
4660 git commit
-m "A" &&
4667 test_expect_success
'12e: Rename/merge subdir into the root, variant 2' '
4674 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4676 git ls-files -s >out &&
4677 test_line_count = 2 out &&
4679 git rev-parse >actual \
4680 HEAD:foo.t HEAD:bar.t &&
4681 git rev-parse >expect \
4682 O:a/b/foo.t B:a/b/bar.t &&
4683 test_cmp expect actual &&
4685 git hash-object bar.t >actual &&
4686 git rev-parse B:a/b/bar.t >expect &&
4687 test_cmp expect actual &&
4689 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4690 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4691 test_path_is_missing a/ &&
4692 test_path_is_file bar.t
4696 # Testcase 12f, Rebase of patches with big directory rename
4698 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4699 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4700 # dir/unchanged/<LOTS OF FILES>
4702 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4703 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4704 # folder/subdir/newsubdir/e_A
4705 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4706 # folder/unchanged/<LOTS OF FILES>
4708 # (add newfile.{c,py}, modify underscored files)
4709 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4710 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4711 # dir/unchanged/<LOTS OF FILES>
4713 # (Modify e further, add newfile.rs)
4714 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4715 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4716 # dir/unchanged/<LOTS OF FILES>
4719 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4720 # folder/subdir/newsubdir/e_Merge1
4721 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4722 # folder/unchanged/<LOTS OF FILES>
4724 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4725 # folder/subdir/newsubdir/e_Merge2
4726 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4727 # folder/unchanged/<LOTS OF FILES>
4728 # Things being checked here:
4729 # 1. dir/subdir/newfile.c does not get pushed into folder/subdir/newsubdir/.
4730 # dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d} looks like
4732 # whereas dir/subdir/e -> folder/subdir/newsubdir/e looks like
4733 # dir/subdir/ -> folder/subdir/newsubdir/
4734 # and if we note that newfile.c is found in dir/subdir/, we might overlook
4735 # the dir/ -> folder/ rule that has more weight. Older git versions did
4737 # 2. The code to do trivial directory resolves. Note that
4738 # dir/subdir/unchanged/ is unchanged and can be deleted, and files in the
4739 # new folder/subdir/unchanged/ are not needed as a target to any renames.
4740 # Thus, in the second collect_merge_info_callback() we can just resolve
4741 # these two directories trivially without recursing.)
4742 # 3. Exercising the codepaths for caching renames and deletes from one cherry
4743 # pick and re-applying them in the subsequent one.
4746 test_create_repo
12f
&&
4750 mkdir
-p dir
/unchanged
&&
4751 mkdir
-p dir
/subdir
/tweaked
&&
4752 echo a
>dir
/subdir
/a
&&
4753 echo b
>dir
/subdir
/b
&&
4754 echo c
>dir
/subdir
/c
&&
4755 echo d
>dir
/subdir
/d
&&
4756 test_seq
1 10 >dir
/subdir
/e
&&
4757 test_seq
10 20 >dir
/subdir
/Makefile
&&
4758 echo f
>dir
/subdir
/tweaked
/f
&&
4759 echo g
>dir
/subdir
/tweaked
/g
&&
4760 echo h
>dir
/subdir
/tweaked
/h
&&
4761 test_seq
20 30 >dir
/subdir
/tweaked
/Makefile
&&
4762 for i
in $
(test_seq
1 88); do
4763 echo content
$i >dir
/unchanged
/file_
$i
4766 git commit
-m "O" &&
4773 git
rm dir
/subdir
/tweaked
/f dir
/subdir
/tweaked
/g
&&
4774 test_seq
2 10 >dir
/subdir
/e
&&
4775 test_seq
11 20 >dir
/subdir
/Makefile
&&
4776 test_seq
21 30 >dir
/subdir
/tweaked
/Makefile
&&
4777 mkdir dir
/subdir
/newsubdir
&&
4778 git
mv dir
/subdir
/e dir
/subdir
/newsubdir
/ &&
4779 git
mv dir folder
&&
4781 git commit
-m "A" &&
4784 mkdir dir
/subdir
/newsubdir
/ &&
4785 echo c code
>dir
/subdir
/newfile.c
&&
4786 echo python code
>dir
/subdir
/newsubdir
/newfile.py
&&
4787 test_seq
1 11 >dir
/subdir
/e
&&
4788 test_seq
10 21 >dir
/subdir
/Makefile
&&
4789 test_seq
20 31 >dir
/subdir
/tweaked
/Makefile
&&
4791 git commit
-m "B1" &&
4793 echo rust code
>dir
/subdir
/newfile.rs
&&
4794 test_seq
1 12 >dir
/subdir
/e
&&
4800 test_expect_merge_algorithm failure success
'12f: Trivial directory resolve, caching, all kinds of fun' '
4806 git branch Bmod B &&
4808 GIT_TRACE2_PERF="$(pwd)/trace.output" git -c merge.directoryRenames=true rebase A Bmod &&
4810 echo Checking the pick of B1... &&
4812 test_must_fail git rev-parse Bmod~1:dir &&
4814 git ls-tree -r Bmod~1 >out &&
4815 test_line_count = 98 out &&
4817 git diff --name-status A Bmod~1 >actual &&
4818 q_to_tab >expect <<-\EOF &&
4819 MQfolder/subdir/Makefile
4820 AQfolder/subdir/newfile.c
4821 MQfolder/subdir/newsubdir/e
4822 AQfolder/subdir/newsubdir/newfile.py
4823 MQfolder/subdir/tweaked/Makefile
4825 test_cmp expect actual &&
4827 # Three-way merged files
4828 test_seq 2 11 >e_Merge1 &&
4829 test_seq 11 21 >Makefile_TOP &&
4830 test_seq 21 31 >Makefile_SUB &&
4831 git hash-object >expect \
4835 git rev-parse >actual \
4836 Bmod~1:folder/subdir/newsubdir/e \
4837 Bmod~1:folder/subdir/Makefile \
4838 Bmod~1:folder/subdir/tweaked/Makefile &&
4839 test_cmp expect actual &&
4841 # New files showed up at the right location with right contents
4842 git rev-parse >expect \
4843 B~1:dir/subdir/newfile.c \
4844 B~1:dir/subdir/newsubdir/newfile.py &&
4845 git rev-parse >actual \
4846 Bmod~1:folder/subdir/newfile.c \
4847 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4848 test_cmp expect actual &&
4851 test_path_is_missing folder/subdir/tweaked/f &&
4852 test_path_is_missing folder/subdir/tweaked/g &&
4854 # Unchanged files or directories
4855 git rev-parse >actual \
4856 Bmod~1:folder/subdir/a \
4857 Bmod~1:folder/subdir/b \
4858 Bmod~1:folder/subdir/c \
4859 Bmod~1:folder/subdir/d \
4860 Bmod~1:folder/unchanged \
4861 Bmod~1:folder/subdir/tweaked/h &&
4862 git rev-parse >expect \
4868 O:dir/subdir/tweaked/h &&
4869 test_cmp expect actual &&
4871 echo Checking the pick of B2... &&
4873 test_must_fail git rev-parse Bmod:dir &&
4875 git ls-tree -r Bmod >out &&
4876 test_line_count = 99 out &&
4878 git diff --name-status Bmod~1 Bmod >actual &&
4879 q_to_tab >expect <<-\EOF &&
4880 AQfolder/subdir/newfile.rs
4881 MQfolder/subdir/newsubdir/e
4883 test_cmp expect actual &&
4885 # Three-way merged file
4886 test_seq 2 12 >e_Merge2 &&
4887 git hash-object e_Merge2 >expect &&
4888 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4889 test_cmp expect actual &&
4891 grep region_enter.*collect_merge_info trace.output >collect &&
4892 test_line_count = 4 collect &&
4893 grep region_enter.*process_entries$ trace.output >process &&
4894 test_line_count = 2 process
4898 # Testcase 12g, Testcase with two kinds of "relevant" renames
4899 # Commit O: somefile_O, subdir/{a_O,b_O}
4900 # Commit A: somefile_A, subdir/{a_O,b_O,c_A}
4901 # Commit B: newfile_B, newdir/{a_B,b_B}
4902 # Expected: newfile_{merged}, newdir/{a_B,b_B,c_A}
4905 test_create_repo
12g
&&
4910 test_write_lines upon a
time there was a
>somefile
&&
4911 test_write_lines
1 2 3 4 5 6 7 8 9 10 >subdir
/a
&&
4912 test_write_lines one two three four five six
>subdir
/b
&&
4915 git commit
-m "O" &&
4922 test_write_lines once upon a
time there was a
>somefile
&&
4924 git add somefile subdir
/c
&&
4926 git commit
-m "A" &&
4929 git
mv somefile newfile
&&
4930 git
mv subdir newdir
&&
4931 echo repo
>>newfile
&&
4932 test_write_lines
1 2 3 4 5 6 7 8 9 10 11 >newdir
/a
&&
4933 test_write_lines one two three four five six seven
>newdir
/b
&&
4934 git add newfile newdir
&&
4940 test_expect_success
'12g: Testcase with two kinds of "relevant" renames' '
4947 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4949 test_write_lines once upon a time there was a repo >expect &&
4950 test_cmp expect newfile &&
4952 git ls-files -s >out &&
4953 test_line_count = 4 out &&
4955 git rev-parse >actual \
4956 HEAD:newdir/a HEAD:newdir/b HEAD:newdir/c &&
4957 git rev-parse >expect \
4958 B:newdir/a B:newdir/b A:subdir/c &&
4959 test_cmp expect actual &&
4961 test_must_fail git rev-parse HEAD:subdir/a &&
4962 test_must_fail git rev-parse HEAD:subdir/b &&
4963 test_must_fail git rev-parse HEAD:subdir/c &&
4964 test_path_is_missing subdir/ &&
4965 test_path_is_file newdir/c
4969 # Testcase 12h, Testcase with two kinds of "relevant" renames
4970 # Commit O: olddir/{a_1, b}
4971 # Commit A: newdir/{a_2, b}
4972 # Commit B: olddir/{alpha_1, b}
4973 # Expected: newdir/{alpha_2, b}
4976 test_create_repo
12h
&&
4981 test_seq
3 8 >olddir
/a
&&
4984 git commit
-m orig
&&
4991 test_seq
3 10 >olddir
/a
&&
4993 git
mv olddir newdir
&&
4998 git
mv olddir
/a olddir
/alpha
&&
5003 test_expect_failure
'12h: renaming a file within a renamed directory' '
5010 test_might_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5012 git ls-files >tracked &&
5013 test_line_count = 2 tracked &&
5015 test_path_is_missing olddir/a &&
5016 test_path_is_file newdir/alpha &&
5017 test_path_is_file newdir/b &&
5019 git rev-parse >actual \
5020 HEAD:newdir/alpha HEAD:newdir/b &&
5021 git rev-parse >expect \
5022 A:newdir/a O:oldir/b &&
5023 test_cmp expect actual
5027 # Testcase 12i, Directory rename causes rename-to-self
5028 # Commit O: source/{subdir/foo, bar, baz_1}
5029 # Commit A: source/{foo, bar, baz_1}
5030 # Commit B: source/{subdir/{foo, bar}, baz_2}
5031 # Expected: source/{foo, bar, baz_2}, with conflicts on
5032 # source/bar vs. source/subdir/bar
5035 test_create_repo
12i
&&
5039 mkdir
-p source
/subdir
&&
5040 echo foo
>source
/subdir
/foo
&&
5041 echo bar
>source
/bar
&&
5042 echo baz
>source
/baz
&&
5044 git commit
-m orig
&&
5051 git
mv source
/subdir
/foo source
/foo
&&
5055 git
mv source
/bar source
/subdir
/bar
&&
5056 echo more baz
>>source
/baz
&&
5061 test_expect_success
'12i: Directory rename causes rename-to-self' '
5068 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5070 test_path_is_missing source/subdir &&
5071 test_path_is_file source/bar &&
5072 test_path_is_file source/baz &&
5074 git ls-files | uniq >tracked &&
5075 test_line_count = 3 tracked &&
5077 git status --porcelain -uno >actual &&
5078 cat >expect <<-\EOF &&
5082 test_cmp expect actual
5086 # Testcase 12j, Directory rename to root causes rename-to-self
5087 # Commit O: {subdir/foo, bar, baz_1}
5088 # Commit A: {foo, bar, baz_1}
5089 # Commit B: {subdir/{foo, bar}, baz_2}
5090 # Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar
5093 test_create_repo
12j
&&
5098 echo foo
>subdir
/foo
&&
5102 git commit
-m orig
&&
5109 git
mv subdir
/foo foo
&&
5113 git
mv bar subdir
/bar
&&
5114 echo more baz
>>baz
&&
5119 test_expect_success
'12j: Directory rename to root causes rename-to-self' '
5126 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5128 test_path_is_missing subdir &&
5129 test_path_is_file bar &&
5130 test_path_is_file baz &&
5132 git ls-files | uniq >tracked &&
5133 test_line_count = 3 tracked &&
5135 git status --porcelain -uno >actual &&
5136 cat >expect <<-\EOF &&
5140 test_cmp expect actual
5144 # Testcase 12k, Directory rename with sibling causes rename-to-self
5145 # Commit O: dirB/foo, dirA/{bar, baz_1}
5146 # Commit A: dirA/{foo, bar, baz_1}
5147 # Commit B: dirB/{foo, bar}, dirA/baz_2
5148 # Expected: dirA/{foo, bar, baz_2}, with conflicts on dirA/bar vs. dirB/bar
5151 test_create_repo
12k
&&
5156 echo foo
>dirB
/foo
&&
5157 echo bar
>dirA
/bar
&&
5158 echo baz
>dirA
/baz
&&
5160 git commit
-m orig
&&
5167 git
mv dirB
/* dirA
/ &&
5171 git
mv dirA
/bar dirB
/bar
&&
5172 echo more baz
>>dirA
/baz
&&
5177 test_expect_success
'12k: Directory rename with sibling causes rename-to-self' '
5184 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5186 test_path_is_missing dirB &&
5187 test_path_is_file dirA/bar &&
5188 test_path_is_file dirA/baz &&
5190 git ls-files | uniq >tracked &&
5191 test_line_count = 3 tracked &&
5193 git status --porcelain -uno >actual &&
5194 cat >expect <<-\EOF &&
5198 test_cmp expect actual
5202 # Testcase 12l, Both sides rename a directory into the other side, both add
5203 # a file which after directory renames are the same filename
5204 # Commit O: sub1/file, sub2/other
5205 # Commit A: sub3/file, sub2/{other, new_add_add_file_1}
5206 # Commit B: sub1/{file, newfile}, sub1/sub2/{other, new_add_add_file_2}
5209 # A: sub1/ -> sub3/, add sub2/new_add_add_file_1
5210 # B: sub2/ -> sub1/sub2, add sub1/newfile, add sub1/sub2/new_add_add_file_2
5212 # Expected: sub3/{file, newfile, sub2/other}
5213 # CONFLICT (add/add): sub1/sub2/new_add_add_file
5215 # Note that sub1/newfile is not extraneous. Directory renames are only
5216 # detected if they are needed, and they are only needed if the old directory
5217 # had a new file added on the opposite side of history. So sub1/newfile
5218 # is needed for there to be a sub1/ -> sub3/ rename.
5221 test_create_repo
12l_
$1 &&
5226 echo file >sub
1/file &&
5227 echo other
>sub
2/other
&&
5228 git add sub1 sub2
&&
5229 git commit
-m "O" &&
5237 echo conflicting
>sub
2/new_add_add_file
&&
5241 git commit
-m "A" &&
5244 echo dissimilar
>sub
2/new_add_add_file
&&
5245 echo brand
>sub
1/newfile
&&
5246 git add sub1 sub2
&&
5253 test_expect_merge_algorithm failure success
'12l (B into A): Rename into each other + add/add conflict' '
5254 test_setup_12l BintoA &&
5258 git checkout -q A^0 &&
5260 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5262 test_stdout_line_count = 5 git ls-files -s &&
5264 git rev-parse >actual \
5265 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5266 :2:sub1/sub2/new_add_add_file \
5267 :3:sub1/sub2/new_add_add_file &&
5268 git rev-parse >expect \
5269 O:sub1/file B:sub1/newfile O:sub2/other \
5270 A:sub2/new_add_add_file \
5271 B:sub1/sub2/new_add_add_file &&
5272 test_cmp expect actual &&
5274 git ls-files -o >actual &&
5275 test_write_lines actual expect >expect &&
5276 test_cmp expect actual
5280 test_expect_merge_algorithm failure success
'12l (A into B): Rename into each other + add/add conflict' '
5281 test_setup_12l AintoB &&
5285 git checkout -q B^0 &&
5287 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 &&
5289 test_stdout_line_count = 5 git ls-files -s &&
5291 git rev-parse >actual \
5292 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5293 :2:sub1/sub2/new_add_add_file \
5294 :3:sub1/sub2/new_add_add_file &&
5295 git rev-parse >expect \
5296 O:sub1/file B:sub1/newfile O:sub2/other \
5297 B:sub1/sub2/new_add_add_file \
5298 A:sub2/new_add_add_file &&
5299 test_cmp expect actual &&
5301 git ls-files -o >actual &&
5302 test_write_lines actual expect >expect &&
5303 test_cmp expect actual
5307 ###########################################################################
5308 # SECTION 13: Checking informational and conflict messages
5310 # A year after directory rename detection became the default, it was
5311 # instead decided to report conflicts on the pathname on the basis that
5312 # some users may expect the new files added or moved into a directory to
5313 # be unrelated to all the other files in that directory, and thus that
5314 # directory rename detection is unexpected. Test that the messages printed
5315 # match our expectation.
5316 ###########################################################################
5318 # Testcase 13a, Basic directory rename with newly added files
5321 # Commit B: z/{b,c,d,e/f}
5322 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
5325 test_create_repo
13a_
$1 &&
5334 git commit
-m "O" &&
5343 git commit
-m "A" &&
5349 git add z
/d z
/e
/f
&&
5355 test_expect_success
'13a(conflict): messages for newly added files' '
5356 test_setup_13a conflict &&
5362 test_must_fail git merge -s recursive B^0 >out 2>err &&
5364 test_i18ngrep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
5365 test_i18ngrep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
5367 git ls-files >paths &&
5369 grep "y/[de]" paths &&
5371 test_path_is_missing z/d &&
5372 test_path_is_file y/d &&
5373 test_path_is_missing z/e/f &&
5374 test_path_is_file y/e/f
5378 test_expect_success
'13a(info): messages for newly added files' '
5379 test_setup_13a info &&
5386 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5388 test_i18ngrep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
5389 test_i18ngrep Path.updated:.*z/d.added.in.B^0.*y/d out &&
5391 git ls-files >paths &&
5393 grep "y/[de]" paths &&
5395 test_path_is_missing z/d &&
5396 test_path_is_file y/d &&
5397 test_path_is_missing z/e/f &&
5398 test_path_is_file y/e/f
5402 # Testcase 13b, Transitive rename with conflicted content merge and default
5403 # "conflict" setting
5404 # (Related to testcase 1c, 9b)
5405 # Commit O: z/{b,c}, x/d_1
5406 # Commit A: y/{b,c}, x/d_2
5407 # Commit B: z/{b,c,d_3}
5408 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
5409 # one about content, and one about file location
5412 test_create_repo
13b_
$1 &&
5418 test_seq
1 10 >x
/d
&&
5423 git commit
-m "O" &&
5434 git commit
-m "A" &&
5437 echo eleven
>>x
/d
&&
5445 test_expect_success
'13b(conflict): messages for transitive rename with conflicted content' '
5446 test_setup_13b conflict &&
5452 test_must_fail git merge -s recursive B^0 >out 2>err &&
5454 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5455 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5457 git ls-files >paths &&
5461 test_path_is_missing z/d &&
5462 test_path_is_file y/d
5466 test_expect_success
'13b(info): messages for transitive rename with conflicted content' '
5467 test_setup_13b info &&
5474 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5476 test_i18ngrep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5477 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5479 git ls-files >paths &&
5483 test_path_is_missing z/d &&
5484 test_path_is_file y/d
5488 # Testcase 13c, Rename/rename(1to1) due to directory rename
5489 # Commit O: z/{b,c}, x/{d,e}
5490 # Commit A: y/{b,c,d}, x/e
5491 # Commit B: z/{b,c,d}, x/e
5492 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
5493 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
5494 # One could argue A had partial knowledge of what was done with
5495 # d and B had full knowledge, but that's a slippery slope as
5496 # shown in testcase 13d.
5499 test_create_repo
13c_
$1 &&
5505 test_seq
1 10 >x
/d
&&
5511 git commit
-m "O" &&
5521 git commit
-m "A" &&
5531 test_expect_success
'13c(conflict): messages for rename/rename(1to1) via transitive rename' '
5532 test_setup_13c conflict &&
5538 test_must_fail git merge -s recursive B^0 >out 2>err &&
5540 test_i18ngrep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5542 git ls-files >paths &&
5546 test_path_is_missing z/d &&
5547 test_path_is_file y/d
5551 test_expect_success
'13c(info): messages for rename/rename(1to1) via transitive rename' '
5552 test_setup_13c info &&
5559 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5561 test_i18ngrep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5563 git ls-files >paths &&
5567 test_path_is_missing z/d &&
5568 test_path_is_file y/d
5572 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
5573 # Commit O: a/{z,y}, b/x, c/w
5574 # Commit A: a/z, b/{y,x}, d/w
5575 # Commit B: a/z, d/x, c/{y,w}
5576 # Expected: a/z, d/{y,x,w} with no file location conflict for x
5578 # * z is always in a; so it stays in a.
5579 # * x starts in b, only modified on one side to move into d/
5580 # * w starts in c, only modified on one side to move into d/
5582 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5583 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5584 # No conflict in where a/y ends up, so put it in d/y.
5587 test_create_repo
13d_
$1 &&
5600 git commit
-m "O" &&
5610 git commit
-m "A" &&
5620 test_expect_success
'13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5621 test_setup_13d conflict &&
5627 test_must_fail git merge -s recursive B^0 >out 2>err &&
5629 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5630 test_i18ngrep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5632 git ls-files >paths &&
5637 test_path_is_missing b/y &&
5638 test_path_is_missing c/y &&
5639 test_path_is_file d/y
5643 test_expect_success
'13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5644 test_setup_13d info &&
5651 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5653 test_i18ngrep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5654 test_i18ngrep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5656 git ls-files >paths &&
5661 test_path_is_missing b/y &&
5662 test_path_is_missing c/y &&
5663 test_path_is_file d/y
5667 # Testcase 13e, directory rename in virtual merge base
5669 # This testcase has a slightly different setup than all the above cases, in
5670 # order to include a recursive case:
5682 # Commit B: a/{z,y,x}
5683 # Commit C: b/{z,y,x}
5684 # Commit D: b/{z,y}, a/x
5685 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5687 # NOTES: 'X' represents a virtual merge base. With the default of
5688 # directory rename detection yielding conflicts, merging A and B
5689 # results in a conflict complaining about whether 'x' should be
5690 # under 'a/' or 'b/'. However, when creating the virtual merge
5691 # base 'X', since virtual merge bases need to be written out as a
5692 # tree, we cannot have a conflict, so some resolution has to be
5695 # In choosing the right resolution, it's worth noting here that
5696 # commits C & D are merges of A & B that choose different
5697 # locations for 'x' (i.e. they resolve the conflict differently),
5698 # and so it would be nice when merging C & D if git could detect
5699 # this difference of opinion and report a conflict. But the only
5700 # way to do so that I can think of would be to have the virtual
5701 # merge base place 'x' in some directory other than either 'a/' or
5702 # 'b/', which seems a little weird -- especially since it'd result
5703 # in a rename/rename(1to2) conflict with a source path that never
5704 # existed in any version.
5706 # So, for now, when directory rename detection is set to
5707 # 'conflict' just avoid doing directory rename detection at all in
5708 # the recursive case. This will not allow us to detect a conflict
5709 # in the outer merge for this special kind of setup, but it at
5710 # least avoids hitting a BUG().
5713 test_create_repo
13e
&&
5722 git commit
-m "O" &&
5731 git commit
-m "A" &&
5737 git commit
-m "B" &&
5743 test_must_fail git
-c merge.directoryRenames
=conflict merge B
&&
5746 git commit
-m "C" &&
5750 test_must_fail git
-c merge.directoryRenames
=conflict merge A
&&
5759 test_expect_success
'13e: directory rename detection in recursive case' '
5764 git checkout --quiet D^0 &&
5766 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5768 test_i18ngrep ! CONFLICT out &&
5769 test_i18ngrep ! BUG: err &&
5770 test_i18ngrep ! core.dumped err &&
5771 test_must_be_empty err &&
5773 git ls-files >paths &&