3 test_description
="recursive merge with directory renames"
4 # includes checking of many corner cases, with a similar methodology to:
5 # t6042: corner cases with renames but not criss-cross merges
6 # t6036: corner cases with both renames and criss-cross merges
8 # The setup for all of them, pictorially, is:
18 # To help make it easier to follow the flow of tests, they have been
19 # divided into sections and each test will start with a quick explanation
20 # of what commits O, A, and B contain.
23 # z/{b,c} means files z/b and z/c both exist
24 # x/d_1 means file x/d exists with content d1. (Purpose of the
25 # underscore notation is to differentiate different
26 # files that might be renamed into each other's paths.)
31 ###########################################################################
32 # SECTION 1: Basic cases we should be able to handle
33 ###########################################################################
35 # Testcase 1a, Basic directory rename.
38 # Commit B: z/{b,c,d,e/f}
39 # Expected: y/{b,c,d,e/f}
41 test_expect_success
'1a-setup: Simple directory rename detection' '
42 test_create_repo 1a &&
72 test_expect_success
'1a-check: Simple directory rename detection' '
78 git merge -s recursive B^0 &&
80 git ls-files -s >out &&
81 test_line_count = 4 out &&
83 git rev-parse >actual \
84 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
85 git rev-parse >expect \
86 O:z/b O:z/c B:z/d B:z/e/f &&
87 test_cmp expect actual &&
89 git hash-object y/d >actual &&
90 git rev-parse B:z/d >expect &&
91 test_cmp expect actual &&
93 test_must_fail git rev-parse HEAD:z/d &&
94 test_must_fail git rev-parse HEAD:z/e/f &&
95 test_path_is_missing z/d &&
96 test_path_is_missing z/e/f
100 # Testcase 1b, Merge a directory with another
101 # Commit O: z/{b,c}, y/d
102 # Commit A: z/{b,c,e}, y/d
103 # Commit B: y/{b,c,d}
104 # Expected: y/{b,c,d,e}
106 test_expect_success
'1b-setup: Merge a directory with another' '
107 test_create_repo 1b &&
139 test_expect_success
'1b-check: Merge a directory with another' '
145 git merge -s recursive B^0 &&
147 git ls-files -s >out &&
148 test_line_count = 4 out &&
150 git rev-parse >actual \
151 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
152 git rev-parse >expect \
153 O:z/b O:z/c O:y/d A:z/e &&
154 test_cmp expect actual &&
155 test_must_fail git rev-parse HEAD:z/e
159 # Testcase 1c, Transitive renaming
160 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
161 # (Related to testcases 9c and 9d -- can transitivity repeat?)
162 # (Related to testcase 12b -- joint-transitivity?)
163 # Commit O: z/{b,c}, x/d
164 # Commit A: y/{b,c}, x/d
165 # Commit B: z/{b,c,d}
166 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
168 test_expect_success
'1c-setup: Transitive renaming' '
169 test_create_repo 1c &&
198 test_expect_success
'1c-check: Transitive renaming' '
204 git merge -s recursive B^0 &&
206 git ls-files -s >out &&
207 test_line_count = 3 out &&
209 git rev-parse >actual \
210 HEAD:y/b HEAD:y/c HEAD:y/d &&
211 git rev-parse >expect \
213 test_cmp expect actual &&
214 test_must_fail git rev-parse HEAD:x/d &&
215 test_must_fail git rev-parse HEAD:z/d &&
216 test_path_is_missing z/d
220 # Testcase 1d, Directory renames (merging two directories into one new one)
221 # cause a rename/rename(2to1) conflict
222 # (Related to testcases 1c and 7b)
223 # Commit O. z/{b,c}, y/{d,e}
224 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
225 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
226 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
227 # Note: y/m & z/n should definitely move into x. By the same token, both
228 # y/wham_1 & z/wham_2 should too...giving us a conflict.
230 test_expect_success
'1d-setup: Directory renames cause a rename/rename(2to1) conflict' '
231 test_create_repo 1d &&
252 echo wham1 >y/wham &&
260 echo wham2 >z/wham &&
267 test_expect_success
'1d-check: Directory renames cause a rename/rename(2to1) conflict' '
273 test_must_fail git merge -s recursive B^0 >out &&
274 test_i18ngrep "CONFLICT (rename/rename)" out &&
276 git ls-files -s >out &&
277 test_line_count = 8 out &&
278 git ls-files -u >out &&
279 test_line_count = 2 out &&
280 git ls-files -o >out &&
281 test_line_count = 3 out &&
283 git rev-parse >actual \
284 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
285 git rev-parse >expect \
286 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
287 test_cmp expect actual &&
289 test_must_fail git rev-parse :0:x/wham &&
290 git rev-parse >actual \
291 :2:x/wham :3:x/wham &&
292 git rev-parse >expect \
294 test_cmp expect actual &&
296 test_path_is_missing x/wham &&
297 test_path_is_file x/wham~HEAD &&
298 test_path_is_file x/wham~B^0 &&
300 git hash-object >actual \
301 x/wham~HEAD x/wham~B^0 &&
302 git rev-parse >expect \
304 test_cmp expect actual
308 # Testcase 1e, Renamed directory, with all filenames being renamed too
309 # (Related to testcases 9f & 9g)
310 # Commit O: z/{oldb,oldc}
311 # Commit A: y/{newb,newc}
312 # Commit B: z/{oldb,oldc,d}
313 # Expected: y/{newb,newc,d}
315 test_expect_success
'1e-setup: Renamed directory, with all files being renamed too' '
316 test_create_repo 1e &&
333 git mv z/oldb y/newb &&
334 git mv z/oldc y/newc &&
346 test_expect_success
'1e-check: Renamed directory, with all files being renamed too' '
352 git merge -s recursive B^0 &&
354 git ls-files -s >out &&
355 test_line_count = 3 out &&
357 git rev-parse >actual \
358 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
359 git rev-parse >expect \
360 O:z/oldb O:z/oldc B:z/d &&
361 test_cmp expect actual &&
362 test_must_fail git rev-parse HEAD:z/d
366 # Testcase 1f, Split a directory into two other directories
367 # (Related to testcases 3a, all of section 2, and all of section 4)
368 # Commit O: z/{b,c,d,e,f}
369 # Commit A: z/{b,c,d,e,f,g}
370 # Commit B: y/{b,c}, x/{d,e,f}
371 # Expected: y/{b,c}, x/{d,e,f,g}
373 test_expect_success
'1f-setup: Split a directory into two other directories' '
374 test_create_repo 1f &&
412 test_expect_success
'1f-check: Split a directory into two other directories' '
418 git merge -s recursive B^0 &&
420 git ls-files -s >out &&
421 test_line_count = 6 out &&
423 git rev-parse >actual \
424 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
425 git rev-parse >expect \
426 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
427 test_cmp expect actual &&
428 test_path_is_missing z/g &&
429 test_must_fail git rev-parse HEAD:z/g
433 ###########################################################################
434 # Rules suggested by testcases in section 1:
436 # We should still detect the directory rename even if it wasn't just
437 # the directory renamed, but the files within it. (see 1b)
439 # If renames split a directory into two or more others, the directory
440 # with the most renames, "wins" (see 1c). However, see the testcases
441 # in section 2, plus testcases 3a and 4a.
442 ###########################################################################
445 ###########################################################################
446 # SECTION 2: Split into multiple directories, with equal number of paths
448 # Explore the splitting-a-directory rules a bit; what happens in the
451 # Note that there is a closely related case of a directory not being
452 # split on either side of history, but being renamed differently on
453 # each side. See testcase 8e for that.
454 ###########################################################################
456 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
459 # Commit B: z/{b,c,d}
460 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
461 test_expect_success
'2a-setup: Directory split into two on one side, with equal numbers of paths' '
462 test_create_repo 2a &&
493 test_expect_success
'2a-check: Directory split into two on one side, with equal numbers of paths' '
499 test_must_fail git merge -s recursive B^0 >out &&
500 test_i18ngrep "CONFLICT.*directory rename split" out &&
502 git ls-files -s >out &&
503 test_line_count = 3 out &&
504 git ls-files -u >out &&
505 test_line_count = 0 out &&
506 git ls-files -o >out &&
507 test_line_count = 1 out &&
509 git rev-parse >actual \
510 :0:y/b :0:w/c :0:z/d &&
511 git rev-parse >expect \
513 test_cmp expect actual
517 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
520 # Commit B: z/{b,c}, x/d
521 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
522 test_expect_success
'2b-setup: Directory split into two on one side, with equal numbers of paths' '
523 test_create_repo 2b &&
555 test_expect_success
'2b-check: Directory split into two on one side, with equal numbers of paths' '
561 git merge -s recursive B^0 >out &&
563 git ls-files -s >out &&
564 test_line_count = 3 out &&
565 git ls-files -u >out &&
566 test_line_count = 0 out &&
567 git ls-files -o >out &&
568 test_line_count = 1 out &&
570 git rev-parse >actual \
571 :0:y/b :0:w/c :0:x/d &&
572 git rev-parse >expect \
574 test_cmp expect actual &&
575 test_i18ngrep ! "CONFLICT.*directory rename split" out
579 ###########################################################################
580 # Rules suggested by section 2:
582 # None; the rule was already covered in section 1. These testcases are
583 # here just to make sure the conflict resolution and necessary warning
584 # messages are handled correctly.
585 ###########################################################################
588 ###########################################################################
589 # SECTION 3: Path in question is the source path for some rename already
591 # Combining cases from Section 1 and trying to handle them could lead to
592 # directory renaming detection being over-applied. So, this section
593 # provides some good testcases to check that the implementation doesn't go
595 ###########################################################################
597 # Testcase 3a, Avoid implicit rename if involved as source on other side
598 # (Related to testcases 1c, 1f, and 9h)
599 # Commit O: z/{b,c,d}
600 # Commit A: z/{b,c,d} (no change)
601 # Commit B: y/{b,c}, x/d
602 # Expected: y/{b,c}, x/d
603 test_expect_success
'3a-setup: Avoid implicit rename if involved as source on other side' '
604 test_create_repo 3a &&
622 git commit --allow-empty -m "A" &&
636 test_expect_success
'3a-check: Avoid implicit rename if involved as source on other side' '
642 git merge -s recursive B^0 &&
644 git ls-files -s >out &&
645 test_line_count = 3 out &&
647 git rev-parse >actual \
648 HEAD:y/b HEAD:y/c HEAD:x/d &&
649 git rev-parse >expect \
651 test_cmp expect actual
655 # Testcase 3b, Avoid implicit rename if involved as source on other side
656 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
657 # Commit O: z/{b,c,d}
658 # Commit A: y/{b,c}, x/d
659 # Commit B: z/{b,c}, w/d
660 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
661 # NOTE: We're particularly checking that since z/d is already involved as
662 # a source in a file rename on the same side of history, that we don't
663 # get it involved in directory rename detection. If it were, we might
664 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
665 # rename/rename/rename(1to3) conflict, which is just weird.
666 test_expect_success
'3b-setup: Avoid implicit rename if involved as source on current side' '
667 test_create_repo 3b &&
701 test_expect_success
'3b-check: Avoid implicit rename if involved as source on current side' '
707 test_must_fail git merge -s recursive B^0 >out &&
708 test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
709 test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
711 git ls-files -s >out &&
712 test_line_count = 5 out &&
713 git ls-files -u >out &&
714 test_line_count = 3 out &&
715 git ls-files -o >out &&
716 test_line_count = 1 out &&
718 git rev-parse >actual \
719 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
720 git rev-parse >expect \
721 O:z/b O:z/c O:z/d O:z/d O:z/d &&
722 test_cmp expect actual &&
724 test_path_is_missing z/d &&
725 git hash-object >actual \
727 git rev-parse >expect \
729 test_cmp expect actual
733 ###########################################################################
734 # Rules suggested by section 3:
736 # Avoid directory-rename-detection for a path, if that path is the source
737 # of a rename on either side of a merge.
738 ###########################################################################
741 ###########################################################################
742 # SECTION 4: Partially renamed directory; still exists on both sides of merge
744 # What if we were to attempt to do directory rename detection when someone
745 # "mostly" moved a directory but still left some files around, or,
746 # equivalently, fully renamed a directory in one commmit and then recreated
747 # that directory in a later commit adding some new files and then tried to
750 # It's hard to divine user intent in these cases, because you can make an
751 # argument that, depending on the intermediate history of the side being
752 # merged, that some users will want files in that directory to
753 # automatically be detected and renamed, while users with a different
754 # intermediate history wouldn't want that rename to happen.
756 # I think that it is best to simply not have directory rename detection
757 # apply to such cases. My reasoning for this is four-fold: (1) it's
758 # easiest for users in general to figure out what happened if we don't
759 # apply directory rename detection in any such case, (2) it's an easy rule
760 # to explain ["We don't do directory rename detection if the directory
761 # still exists on both sides of the merge"], (3) we can get some hairy
762 # edge/corner cases that would be really confusing and possibly not even
763 # representable in the index if we were to even try, and [related to 3] (4)
764 # attempting to resolve this issue of divining user intent by examining
765 # intermediate history goes against the spirit of three-way merges and is a
766 # path towards crazy corner cases that are far more complex than what we're
767 # already dealing with.
769 # Note that the wording of the rule ("We don't do directory rename
770 # detection if the directory still exists on both sides of the merge.")
771 # also excludes "renaming" of a directory into a subdirectory of itself
772 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
773 # out an exception for "renaming"-beneath-itself cases without opening
774 # weird edge/corner cases for other partial directory renames, but for now
775 # we are keeping the rule simple.
777 # This section contains a test for a partially-renamed-directory case.
778 ###########################################################################
780 # Testcase 4a, Directory split, with original directory still present
781 # (Related to testcase 1f)
782 # Commit O: z/{b,c,d,e}
783 # Commit A: y/{b,c,d}, z/e
784 # Commit B: z/{b,c,d,e,f}
785 # Expected: y/{b,c,d}, z/{e,f}
786 # NOTE: Even though most files from z moved to y, we don't want f to follow.
788 test_expect_success
'4a-setup: Directory split, with original directory still present' '
789 test_create_repo 4a &&
822 test_expect_success
'4a-check: Directory split, with original directory still present' '
828 git merge -s recursive B^0 &&
830 git ls-files -s >out &&
831 test_line_count = 5 out &&
832 git ls-files -u >out &&
833 test_line_count = 0 out &&
834 git ls-files -o >out &&
835 test_line_count = 1 out &&
837 git rev-parse >actual \
838 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
839 git rev-parse >expect \
840 O:z/b O:z/c O:z/d O:z/e B:z/f &&
841 test_cmp expect actual
845 ###########################################################################
846 # Rules suggested by section 4:
848 # Directory-rename-detection should be turned off for any directories (as
849 # a source for renames) that exist on both sides of the merge. (The "as
850 # a source for renames" clarification is due to cases like 1c where
851 # the target directory exists on both sides and we do want the rename
852 # detection.) But, sadly, see testcase 8b.
853 ###########################################################################
856 ###########################################################################
857 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
859 # Implicitly renaming files due to a detected directory rename could run
860 # into problems if there are files or directories in the way of the paths
861 # we want to rename. Explore such cases in this section.
862 ###########################################################################
864 # Testcase 5a, Merge directories, other side adds files to original and target
865 # Commit O: z/{b,c}, y/d
866 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
867 # Commit B: y/{b,c,d}
868 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
869 # NOTE: While directory rename detection is active here causing z/f to
870 # become y/f, we did not apply this for z/e_1 because that would
871 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
872 # this add/add, is that both versions of y/e are from the same side
873 # of history, giving us no way to represent this conflict in the
876 test_expect_success
'5a-setup: Merge directories, other side adds files to original and target' '
877 test_create_repo 5a &&
898 git add z/e z/f y/e &&
911 test_expect_success
'5a-check: Merge directories, other side adds files to original and target' '
917 test_must_fail git merge -s recursive B^0 >out &&
918 test_i18ngrep "CONFLICT.*implicit dir rename" out &&
920 git ls-files -s >out &&
921 test_line_count = 6 out &&
922 git ls-files -u >out &&
923 test_line_count = 0 out &&
924 git ls-files -o >out &&
925 test_line_count = 1 out &&
927 git rev-parse >actual \
928 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
929 git rev-parse >expect \
930 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
931 test_cmp expect actual
935 # Testcase 5b, Rename/delete in order to get add/add/add conflict
936 # (Related to testcase 8d; these may appear slightly inconsistent to users;
937 # Also related to testcases 7d and 7e)
938 # Commit O: z/{b,c,d_1}
939 # Commit A: y/{b,c,d_2}
940 # Commit B: z/{b,c,d_1,e}, y/d_3
941 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
942 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
943 # we normaly would since z/ is being renamed to y/, then this would be
944 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
945 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
946 # representable in the index, so the existence of y/d_3 needs to
947 # cause us to bail on directory rename detection for that path, falling
948 # back to git behavior without the directory rename detection.
950 test_expect_success
'5b-setup: Rename/delete in order to get add/add/add conflict' '
951 test_create_repo 5b &&
985 test_expect_success
'5b-check: Rename/delete in order to get add/add/add conflict' '
991 test_must_fail git merge -s recursive B^0 >out &&
992 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
994 git ls-files -s >out &&
995 test_line_count = 5 out &&
996 git ls-files -u >out &&
997 test_line_count = 2 out &&
998 git ls-files -o >out &&
999 test_line_count = 1 out &&
1001 git rev-parse >actual \
1002 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1003 git rev-parse >expect \
1004 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1005 test_cmp expect actual &&
1007 test_must_fail git rev-parse :1:y/d &&
1008 test_path_is_file y/d
1012 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1013 # (Directory rename detection would result in transitive rename vs.
1014 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1015 # rename paths conflict with separate adds on the other side)
1016 # (Related to testcases 3b and 7c)
1017 # Commit O: z/{b,c}, x/d_1
1018 # Commit A: y/{b,c,d_2}, w/d_1
1019 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1020 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1021 # presence of y/d_4 in B to avoid doing transitive rename of
1022 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1023 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1024 # though, because it doesn't have anything in the way.
1026 test_expect_success
'5c-setup: Transitive rename would cause rename/rename/rename/add/add/add' '
1027 test_create_repo 5c &&
1038 git commit -m "O" &&
1050 git commit -m "A" &&
1059 git add w/ y/ z/e &&
1065 test_expect_success
'5c-check: Transitive rename would cause rename/rename/rename/add/add/add' '
1071 test_must_fail git merge -s recursive B^0 >out &&
1072 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1073 test_i18ngrep "CONFLICT (add/add).* y/d" out &&
1075 git ls-files -s >out &&
1076 test_line_count = 9 out &&
1077 git ls-files -u >out &&
1078 test_line_count = 6 out &&
1079 git ls-files -o >out &&
1080 test_line_count = 3 out &&
1082 git rev-parse >actual \
1083 :0:y/b :0:y/c :0:y/e &&
1084 git rev-parse >expect \
1085 O:z/b O:z/c B:z/e &&
1086 test_cmp expect actual &&
1088 test_must_fail git rev-parse :1:y/d &&
1089 git rev-parse >actual \
1090 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1091 git rev-parse >expect \
1092 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1093 test_cmp expect actual &&
1095 git hash-object >actual \
1096 w/d~HEAD w/d~B^0 z/d &&
1097 git rev-parse >expect \
1098 O:x/d B:w/d O:x/d &&
1099 test_cmp expect actual &&
1100 test_path_is_missing x/d &&
1101 test_path_is_file y/d &&
1102 grep -q "<<<<" y/d # conflict markers should be present
1106 # Testcase 5d, Directory/file/file conflict due to directory rename
1108 # Commit A: y/{b,c,d_1}
1109 # Commit B: z/{b,c,d_2,f}, y/d/e
1110 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1111 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1112 # detection for z/d_2, but that doesn't prevent us from applying the
1113 # directory rename detection for z/f -> y/f.
1115 test_expect_success
'5d-setup: Directory/file/file conflict due to directory rename' '
1116 test_create_repo 5d &&
1125 git commit -m "O" &&
1136 git commit -m "A" &&
1143 git add y/d/e z/d z/f &&
1149 test_expect_success
'5d-check: Directory/file/file conflict due to directory rename' '
1155 test_must_fail git merge -s recursive B^0 >out &&
1156 test_i18ngrep "CONFLICT (file/directory).*y/d" out &&
1158 git ls-files -s >out &&
1159 test_line_count = 6 out &&
1160 git ls-files -u >out &&
1161 test_line_count = 1 out &&
1162 git ls-files -o >out &&
1163 test_line_count = 2 out &&
1165 git rev-parse >actual \
1166 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e &&
1167 git rev-parse >expect \
1168 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1169 test_cmp expect actual &&
1171 git hash-object y/d~HEAD >actual &&
1172 git rev-parse A:y/d >expect &&
1173 test_cmp expect actual
1177 ###########################################################################
1178 # Rules suggested by section 5:
1180 # If a subset of to-be-renamed files have a file or directory in the way,
1181 # "turn off" the directory rename for those specific sub-paths, falling
1182 # back to old handling. But, sadly, see testcases 8a and 8b.
1183 ###########################################################################
1186 ###########################################################################
1187 # SECTION 6: Same side of the merge was the one that did the rename
1189 # It may sound obvious that you only want to apply implicit directory
1190 # renames to directories if the _other_ side of history did the renaming.
1191 # If you did make an implementation that didn't explicitly enforce this
1192 # rule, the majority of cases that would fall under this section would
1193 # also be solved by following the rules from the above sections. But
1194 # there are still a few that stick out, so this section covers them just
1195 # to make sure we also get them right.
1196 ###########################################################################
1198 # Testcase 6a, Tricky rename/delete
1199 # Commit O: z/{b,c,d}
1201 # Commit B: y/{b,c}, z/d
1202 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1203 # Note: We're just checking here that the rename of z/b and z/c to put
1204 # them under y/ doesn't accidentally catch z/d and make it look like
1205 # it is also involved in a rename/delete conflict.
1207 test_expect_success
'6a-setup: Tricky rename/delete' '
1208 test_create_repo 6a &&
1218 git commit -m "O" &&
1228 git commit -m "A" &&
1239 test_expect_success
'6a-check: Tricky rename/delete' '
1245 test_must_fail git merge -s recursive B^0 >out &&
1246 test_i18ngrep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1248 git ls-files -s >out &&
1249 test_line_count = 2 out &&
1250 git ls-files -u >out &&
1251 test_line_count = 1 out &&
1252 git ls-files -o >out &&
1253 test_line_count = 1 out &&
1255 git rev-parse >actual \
1257 git rev-parse >expect \
1259 test_cmp expect actual
1263 # Testcase 6b, Same rename done on both sides
1264 # (Related to testcases 6c and 8e)
1267 # Commit B: y/{b,c}, z/d
1268 # Expected: y/{b,c}, z/d
1269 # Note: If we did directory rename detection here, we'd move z/d into y/,
1270 # but B did that rename and still decided to put the file into z/,
1271 # so we probably shouldn't apply directory rename detection for it.
1273 test_expect_success
'6b-setup: Same rename done on both sides' '
1274 test_create_repo 6b &&
1283 git commit -m "O" &&
1292 git commit -m "A" &&
1304 test_expect_success
'6b-check: Same rename done on both sides' '
1310 git merge -s recursive B^0 &&
1312 git ls-files -s >out &&
1313 test_line_count = 3 out &&
1314 git ls-files -u >out &&
1315 test_line_count = 0 out &&
1316 git ls-files -o >out &&
1317 test_line_count = 1 out &&
1319 git rev-parse >actual \
1320 HEAD:y/b HEAD:y/c HEAD:z/d &&
1321 git rev-parse >expect \
1322 O:z/b O:z/c B:z/d &&
1323 test_cmp expect actual
1327 # Testcase 6c, Rename only done on same side
1328 # (Related to testcases 6b and 8e)
1330 # Commit A: z/{b,c} (no change)
1331 # Commit B: y/{b,c}, z/d
1332 # Expected: y/{b,c}, z/d
1333 # NOTE: Seems obvious, but just checking that the implementation doesn't
1334 # "accidentally detect a rename" and give us y/{b,c,d}.
1336 test_expect_success
'6c-setup: Rename only done on same side' '
1337 test_create_repo 6c &&
1346 git commit -m "O" &&
1354 git commit --allow-empty -m "A" &&
1366 test_expect_success
'6c-check: Rename only done on same side' '
1372 git merge -s recursive B^0 &&
1374 git ls-files -s >out &&
1375 test_line_count = 3 out &&
1376 git ls-files -u >out &&
1377 test_line_count = 0 out &&
1378 git ls-files -o >out &&
1379 test_line_count = 1 out &&
1381 git rev-parse >actual \
1382 HEAD:y/b HEAD:y/c HEAD:z/d &&
1383 git rev-parse >expect \
1384 O:z/b O:z/c B:z/d &&
1385 test_cmp expect actual
1389 # Testcase 6d, We don't always want transitive renaming
1390 # (Related to testcase 1c)
1391 # Commit O: z/{b,c}, x/d
1392 # Commit A: z/{b,c}, x/d (no change)
1393 # Commit B: y/{b,c}, z/d
1394 # Expected: y/{b,c}, z/d
1395 # NOTE: Again, this seems obvious but just checking that the implementation
1396 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1398 test_expect_success
'6d-setup: We do not always want transitive renaming' '
1399 test_create_repo 6d &&
1410 git commit -m "O" &&
1418 git commit --allow-empty -m "A" &&
1428 test_expect_success
'6d-check: We do not always want transitive renaming' '
1434 git merge -s recursive B^0 &&
1436 git ls-files -s >out &&
1437 test_line_count = 3 out &&
1438 git ls-files -u >out &&
1439 test_line_count = 0 out &&
1440 git ls-files -o >out &&
1441 test_line_count = 1 out &&
1443 git rev-parse >actual \
1444 HEAD:y/b HEAD:y/c HEAD:z/d &&
1445 git rev-parse >expect \
1446 O:z/b O:z/c O:x/d &&
1447 test_cmp expect actual
1451 # Testcase 6e, Add/add from one-side
1453 # Commit A: z/{b,c} (no change)
1454 # Commit B: y/{b,c,d_1}, z/d_2
1455 # Expected: y/{b,c,d_1}, z/d_2
1456 # NOTE: Again, this seems obvious but just checking that the implementation
1457 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1458 # add/add conflict on y/d_1 vs y/d_2.
1460 test_expect_success
'6e-setup: Add/add from one side' '
1461 test_create_repo 6e &&
1470 git commit -m "O" &&
1478 git commit --allow-empty -m "A" &&
1491 test_expect_success
'6e-check: Add/add from one side' '
1497 git merge -s recursive B^0 &&
1499 git ls-files -s >out &&
1500 test_line_count = 4 out &&
1501 git ls-files -u >out &&
1502 test_line_count = 0 out &&
1503 git ls-files -o >out &&
1504 test_line_count = 1 out &&
1506 git rev-parse >actual \
1507 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1508 git rev-parse >expect \
1509 O:z/b O:z/c B:y/d B:z/d &&
1510 test_cmp expect actual
1514 ###########################################################################
1515 # Rules suggested by section 6:
1517 # Only apply implicit directory renames to directories if the other
1518 # side of history is the one doing the renaming.
1519 ###########################################################################
1522 ###########################################################################
1523 # SECTION 7: More involved Edge/Corner cases
1525 # The ruleset we have generated in the above sections seems to provide
1526 # well-defined merges. But can we find edge/corner cases that either (a)
1527 # are harder for users to understand, or (b) have a resolution that is
1528 # non-intuitive or suboptimal?
1530 # The testcases in this section dive into cases that I've tried to craft in
1531 # a way to find some that might be surprising to users or difficult for
1532 # them to understand (the next section will look at non-intuitive or
1533 # suboptimal merge results). Some of the testcases are similar to ones
1534 # from past sections, but have been simplified to try to highlight error
1535 # messages using a "modified" path (due to the directory rename). Are
1536 # users okay with these?
1538 # In my opinion, testcases that are difficult to understand from this
1539 # section is due to difficulty in the testcase rather than the directory
1540 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1541 # to the problem setup itself being complex). And I don't think the
1542 # error messages are a problem.
1544 # On the other hand, the testcases in section 8 worry me slightly more...
1545 ###########################################################################
1547 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1550 # Commit B: w/b, x/c, z/d
1551 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1552 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1554 test_expect_success
'7a-setup: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1555 test_create_repo 7a &&
1564 git commit -m "O" &&
1573 git commit -m "A" &&
1587 test_expect_success
'7a-check: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1593 test_must_fail git merge -s recursive B^0 >out &&
1594 test_i18ngrep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1595 test_i18ngrep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1597 git ls-files -s >out &&
1598 test_line_count = 7 out &&
1599 git ls-files -u >out &&
1600 test_line_count = 6 out &&
1601 git ls-files -o >out &&
1602 test_line_count = 1 out &&
1604 git rev-parse >actual \
1605 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1606 git rev-parse >expect \
1607 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1608 test_cmp expect actual &&
1610 git hash-object >actual \
1612 git rev-parse >expect \
1613 O:z/b O:z/b O:z/c O:z/c &&
1614 test_cmp expect actual
1618 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1619 # (Related to testcase 1d)
1620 # Commit O: z/{b,c}, x/d_1, w/d_2
1621 # Commit A: y/{b,c,d_2}, x/d_1
1622 # Commit B: z/{b,c,d_1}, w/d_2
1623 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1625 test_expect_success
'7b-setup: rename/rename(2to1), but only due to transitive rename' '
1626 test_create_repo 7b &&
1639 git commit -m "O" &&
1649 git commit -m "A" &&
1659 test_expect_success
'7b-check: rename/rename(2to1), but only due to transitive rename' '
1665 test_must_fail git merge -s recursive B^0 >out &&
1666 test_i18ngrep "CONFLICT (rename/rename)" out &&
1668 git ls-files -s >out &&
1669 test_line_count = 4 out &&
1670 git ls-files -u >out &&
1671 test_line_count = 2 out &&
1672 git ls-files -o >out &&
1673 test_line_count = 3 out &&
1675 git rev-parse >actual \
1676 :0:y/b :0:y/c :2:y/d :3:y/d &&
1677 git rev-parse >expect \
1678 O:z/b O:z/c O:w/d O:x/d &&
1679 test_cmp expect actual &&
1681 test_path_is_missing y/d &&
1682 test_path_is_file y/d~HEAD &&
1683 test_path_is_file y/d~B^0 &&
1685 git hash-object >actual \
1687 git rev-parse >expect \
1689 test_cmp expect actual
1693 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1694 # (Related to testcases 3b and 5c)
1695 # Commit O: z/{b,c}, x/d
1696 # Commit A: y/{b,c}, w/d
1697 # Commit B: z/{b,c,d}
1698 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1699 # NOTE: z/ was renamed to y/ so we do want to report
1700 # neither CONFLICT(x/d -> w/d vs. z/d)
1701 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1703 test_expect_success
'7c-setup: rename/rename(1to...2or3); transitive rename may add complexity' '
1704 test_create_repo 7c &&
1715 git commit -m "O" &&
1725 git commit -m "A" &&
1735 test_expect_success
'7c-check: rename/rename(1to...2or3); transitive rename may add complexity' '
1741 test_must_fail git merge -s recursive B^0 >out &&
1742 test_i18ngrep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1744 git ls-files -s >out &&
1745 test_line_count = 5 out &&
1746 git ls-files -u >out &&
1747 test_line_count = 3 out &&
1748 git ls-files -o >out &&
1749 test_line_count = 1 out &&
1751 git rev-parse >actual \
1752 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1753 git rev-parse >expect \
1754 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1755 test_cmp expect actual
1759 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1760 # (Related somewhat to testcases 5b and 8d)
1761 # Commit O: z/{b,c}, x/d
1763 # Commit B: z/{b,c,d}
1764 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1765 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1767 test_expect_success
'7d-setup: transitive rename involved in rename/delete; how is it reported?' '
1768 test_create_repo 7d &&
1779 git commit -m "O" &&
1789 git commit -m "A" &&
1799 test_expect_success
'7d-check: transitive rename involved in rename/delete; how is it reported?' '
1805 test_must_fail git merge -s recursive B^0 >out &&
1806 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1808 git ls-files -s >out &&
1809 test_line_count = 3 out &&
1810 git ls-files -u >out &&
1811 test_line_count = 1 out &&
1812 git ls-files -o >out &&
1813 test_line_count = 1 out &&
1815 git rev-parse >actual \
1816 :0:y/b :0:y/c :3:y/d &&
1817 git rev-parse >expect \
1818 O:z/b O:z/c O:x/d &&
1819 test_cmp expect actual
1823 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
1824 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
1825 # (Also related to testcases 9c and 9d)
1826 # Commit O: z/{b,c}, x/d_1
1827 # Commit A: y/{b,c,d/g}, x/d/f
1828 # Commit B: z/{b,c,d_1}
1829 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
1830 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
1832 # NOTE: The main path of interest here is d_1 and where it ends up, but
1833 # this is actually a case that has two potential directory renames
1834 # involved and D/F conflict(s), so it makes sense to walk through
1837 # Commit A renames z/ -> y/. Thus everything that B adds to z/
1838 # should be instead moved to y/. This gives us the D/F conflict on
1839 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
1841 # Further, commit B renames x/ -> z/, thus everything A adds to x/
1842 # should instead be moved to z/...BUT we removed z/ and renamed it
1843 # to y/, so maybe everything should move not from x/ to z/, but
1844 # from x/ to z/ to y/. Doing so might make sense from the logic so
1845 # far, but note that commit A had both an x/ and a y/; it did the
1846 # renaming of z/ to y/ and created x/d/f and it clearly made these
1847 # things separate, so it doesn't make much sense to push these
1848 # together. Doing so is what I'd call a doubly transitive rename;
1849 # see testcases 9c and 9d for further discussion of this issue and
1850 # how it's resolved.
1852 test_expect_success
'7e-setup: transitive rename in rename/delete AND dirs in the way' '
1853 test_create_repo 7e &&
1864 git commit -m "O" &&
1877 git add x/d/f y/d/g &&
1879 git commit -m "A" &&
1889 test_expect_success
'7e-check: transitive rename in rename/delete AND dirs in the way' '
1895 test_must_fail git merge -s recursive B^0 >out &&
1896 test_i18ngrep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1898 git ls-files -s >out &&
1899 test_line_count = 5 out &&
1900 git ls-files -u >out &&
1901 test_line_count = 1 out &&
1902 git ls-files -o >out &&
1903 test_line_count = 2 out &&
1905 git rev-parse >actual \
1906 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
1907 git rev-parse >expect \
1908 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d &&
1909 test_cmp expect actual &&
1911 git hash-object y/d~B^0 >actual &&
1912 git rev-parse O:x/d >expect &&
1913 test_cmp expect actual
1917 ###########################################################################
1918 # SECTION 8: Suboptimal merges
1920 # As alluded to in the last section, the ruleset we have built up for
1921 # detecting directory renames unfortunately has some special cases where it
1922 # results in slightly suboptimal or non-intuitive behavior. This section
1923 # explores these cases.
1925 # To be fair, we already had non-intuitive or suboptimal behavior for most
1926 # of these cases in git before introducing implicit directory rename
1927 # detection, but it'd be nice if there was a modified ruleset out there
1928 # that handled these cases a bit better.
1929 ###########################################################################
1931 # Testcase 8a, Dual-directory rename, one into the others' way
1932 # Commit O. x/{a,b}, y/{c,d}
1933 # Commit A. x/{a,b,e}, y/{c,d,f}
1934 # Commit B. y/{a,b}, z/{c,d}
1936 # Possible Resolutions:
1937 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
1938 # Currently expected: y/{a,b,e,f}, z/{c,d}
1939 # Optimal: y/{a,b,e}, z/{c,d,f}
1941 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
1942 # better with directory rename detection than git did without, but the
1943 # simple rule from section 5 prevents me from handling this as optimally as
1944 # we potentially could.
1946 test_expect_success
'8a-setup: Dual-directory rename, one into the others way' '
1947 test_create_repo 8a &&
1959 git commit -m "O" &&
1970 git commit -m "A" &&
1980 test_expect_success
'8a-check: Dual-directory rename, one into the others way' '
1986 git merge -s recursive B^0 &&
1988 git ls-files -s >out &&
1989 test_line_count = 6 out &&
1990 git ls-files -u >out &&
1991 test_line_count = 0 out &&
1992 git ls-files -o >out &&
1993 test_line_count = 1 out &&
1995 git rev-parse >actual \
1996 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
1997 git rev-parse >expect \
1998 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
1999 test_cmp expect actual
2003 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2004 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2005 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2006 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2008 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2009 # Currently expected: <same>
2010 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2011 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2013 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2014 # y, both are named 'e'. Without directory rename detection, neither file
2015 # moves directories. Implement directory rename detection suboptimally, and
2016 # you get an add/add conflict, but both files were added in commit A, so this
2017 # is an add/add conflict where one side of history added both files --
2018 # something we can't represent in the index. Obviously, we'd prefer the last
2019 # resolution, but our previous rules are too coarse to allow it. Using both
2020 # the rules from section 4 and section 5 save us from the Scary resolution,
2021 # making us fall back to pre-directory-rename-detection behavior for both
2024 test_expect_success
'8b-setup: Dual-directory rename, one into the others way, with conflicting filenames' '
2025 test_create_repo 8b &&
2037 git commit -m "O" &&
2048 git commit -m "A" &&
2058 test_expect_success
'8b-check: Dual-directory rename, one into the others way, with conflicting filenames' '
2064 git merge -s recursive B^0 &&
2066 git ls-files -s >out &&
2067 test_line_count = 6 out &&
2068 git ls-files -u >out &&
2069 test_line_count = 0 out &&
2070 git ls-files -o >out &&
2071 test_line_count = 1 out &&
2073 git rev-parse >actual \
2074 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2075 git rev-parse >expect \
2076 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2077 test_cmp expect actual
2081 # Testcase 8c, rename+modify/delete
2082 # (Related to testcases 5b and 8d)
2083 # Commit O: z/{b,c,d}
2085 # Commit B: z/{b,c,d_modified,e}
2086 # Expected: y/{b,c,e}, CONFLICT(rename+modify/delete: x/d -> y/d or deleted)
2088 # Note: This testcase doesn't present any concerns for me...until you
2089 # compare it with testcases 5b and 8d. See notes in 8d for more
2092 test_expect_success
'8c-setup: rename+modify/delete' '
2093 test_create_repo 8c &&
2100 test_seq 1 10 >z/d &&
2103 git commit -m "O" &&
2113 git commit -m "A" &&
2117 test_chmod +x z/d &&
2125 test_expect_success
'8c-check: rename+modify/delete' '
2131 test_must_fail git merge -s recursive B^0 >out &&
2132 test_i18ngrep "CONFLICT (rename/delete).* z/d.*y/d" out &&
2134 git ls-files -s >out &&
2135 test_line_count = 4 out &&
2136 git ls-files -u >out &&
2137 test_line_count = 1 out &&
2138 git ls-files -o >out &&
2139 test_line_count = 1 out &&
2141 git rev-parse >actual \
2142 :0:y/b :0:y/c :0:y/e :3:y/d &&
2143 git rev-parse >expect \
2144 O:z/b O:z/c B:z/e B:z/d &&
2145 test_cmp expect actual &&
2147 test_must_fail git rev-parse :1:y/d &&
2148 test_must_fail git rev-parse :2:y/d &&
2149 git ls-files -s y/d | grep ^100755 &&
2150 test_path_is_file y/d
2154 # Testcase 8d, rename/delete...or not?
2155 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2156 # Also related to testcases 7d and 7e)
2157 # Commit O: z/{b,c,d}
2159 # Commit B: z/{b,c,d,e}
2160 # Expected: y/{b,c,e}
2162 # Note: It would also be somewhat reasonable to resolve this as
2163 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2164 # The logic being that the only difference between this testcase and 8c
2165 # is that there is no modification to d. That suggests that instead of a
2166 # rename/modify vs. delete conflict, we should just have a rename/delete
2167 # conflict, otherwise we are being inconsistent.
2169 # However...as far as consistency goes, we didn't report a conflict for
2170 # path d_1 in testcase 5b due to a different file being in the way. So,
2171 # we seem to be forced to have cases where users can change things
2172 # slightly and get what they may perceive as inconsistent results. It
2173 # would be nice to avoid that, but I'm not sure I see how.
2175 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2176 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2177 # delete) are both coming from commit A, which is illogical. Conflicts
2178 # during merging are supposed to be about opposite sides doing things
2181 test_expect_success
'8d-setup: rename/delete...or not?' '
2182 test_create_repo 8d &&
2189 test_seq 1 10 >z/d &&
2192 git commit -m "O" &&
2202 git commit -m "A" &&
2212 test_expect_success
'8d-check: rename/delete...or not?' '
2218 git merge -s recursive B^0 &&
2220 git ls-files -s >out &&
2221 test_line_count = 3 out &&
2223 git rev-parse >actual \
2224 HEAD:y/b HEAD:y/c HEAD:y/e &&
2225 git rev-parse >expect \
2226 O:z/b O:z/c B:z/e &&
2227 test_cmp expect actual
2231 # Testcase 8e, Both sides rename, one side adds to original directory
2234 # Commit B: w/{b,c}, z/d
2236 # Possible Resolutions:
2237 # w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2238 # CONFLICT(z/c -> y/c vs. w/c)
2239 # Currently expected: y/d, CONFLICT(z/b -> y/b vs. w/b),
2240 # CONFLICT(z/c -> y/c vs. w/c)
2243 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2244 # did NOT get renamed; the directory is still present; instead it is
2245 # considered to have just renamed a subset of paths in directory z
2246 # elsewhere. Therefore, the directory rename done in commit A to z/
2247 # applies to z/d and maps it to y/d.
2249 # It's possible that users would get confused about this, but what
2250 # should we do instead? Silently leaving at z/d seems just as bad or
2251 # maybe even worse. Perhaps we could print a big warning about z/d
2252 # and how we're moving to y/d in this case, but when I started thinking
2253 # about the ramifications of doing that, I didn't know how to rule out
2254 # that opening other weird edge and corner cases so I just punted.
2256 test_expect_success
'8e-setup: Both sides rename, one side adds to original directory' '
2257 test_create_repo 8e &&
2266 git commit -m "O" &&
2275 git commit -m "A" &&
2287 test_expect_success
'8e-check: Both sides rename, one side adds to original directory' '
2293 test_must_fail git merge -s recursive B^0 >out 2>err &&
2294 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2295 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2297 git ls-files -s >out &&
2298 test_line_count = 7 out &&
2299 git ls-files -u >out &&
2300 test_line_count = 6 out &&
2301 git ls-files -o >out &&
2302 test_line_count = 2 out &&
2304 git rev-parse >actual \
2305 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2306 git rev-parse >expect \
2307 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2308 test_cmp expect actual &&
2310 git hash-object >actual \
2312 git rev-parse >expect \
2313 O:z/b O:z/b O:z/c O:z/c &&
2314 test_cmp expect actual &&
2316 test_path_is_missing z/b &&
2317 test_path_is_missing z/c
2321 ###########################################################################
2322 # SECTION 9: Other testcases
2324 # This section consists of miscellaneous testcases I thought of during
2325 # the implementation which round out the testing.
2326 ###########################################################################
2328 # Testcase 9a, Inner renamed directory within outer renamed directory
2329 # (Related to testcase 1f)
2330 # Commit O: z/{b,c,d/{e,f,g}}
2331 # Commit A: y/{b,c}, x/w/{e,f,g}
2332 # Commit B: z/{b,c,d/{e,f,g,h},i}
2333 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2334 # NOTE: The only reason this one is interesting is because when a directory
2335 # is split into multiple other directories, we determine by the weight
2336 # of which one had the most paths going to it. A naive implementation
2337 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2339 test_expect_success
'9a-setup: Inner renamed directory within outer renamed directory' '
2340 test_create_repo 9a &&
2352 git commit -m "O" &&
2363 git commit -m "A" &&
2374 test_expect_success
'9a-check: Inner renamed directory within outer renamed directory' '
2380 git merge -s recursive B^0 &&
2382 git ls-files -s >out &&
2383 test_line_count = 7 out &&
2384 git ls-files -u >out &&
2385 test_line_count = 0 out &&
2386 git ls-files -o >out &&
2387 test_line_count = 1 out &&
2389 git rev-parse >actual \
2390 HEAD:y/b HEAD:y/c HEAD:y/i &&
2391 git rev-parse >expect \
2392 O:z/b O:z/c B:z/i &&
2393 test_cmp expect actual &&
2395 git rev-parse >actual \
2396 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2397 git rev-parse >expect \
2398 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2399 test_cmp expect actual
2403 # Testcase 9b, Transitive rename with content merge
2404 # (Related to testcase 1c)
2405 # Commit O: z/{b,c}, x/d_1
2406 # Commit A: y/{b,c}, x/d_2
2407 # Commit B: z/{b,c,d_3}
2408 # Expected: y/{b,c,d_merged}
2410 test_expect_success
'9b-setup: Transitive rename with content merge' '
2411 test_create_repo 9b &&
2419 test_seq 1 10 >x/d &&
2422 git commit -m "O" &&
2430 test_seq 1 11 >x/d &&
2433 git commit -m "A" &&
2436 test_seq 0 10 >x/d &&
2444 test_expect_success
'9b-check: Transitive rename with content merge' '
2450 git merge -s recursive B^0 &&
2452 git ls-files -s >out &&
2453 test_line_count = 3 out &&
2455 test_seq 0 11 >expected &&
2456 test_cmp expected y/d &&
2458 git rev-parse >actual \
2459 HEAD:y/b HEAD:y/c HEAD:y/d &&
2460 git rev-parse >expect \
2461 O:z/b O:z/c :0:expected &&
2462 test_cmp expect actual &&
2463 test_must_fail git rev-parse HEAD:x/d &&
2464 test_must_fail git rev-parse HEAD:z/d &&
2465 test_path_is_missing z/d &&
2467 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2468 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2469 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2473 # Testcase 9c, Doubly transitive rename?
2474 # (Related to testcase 1c, 7e, and 9d)
2475 # Commit O: z/{b,c}, x/{d,e}, w/f
2476 # Commit A: y/{b,c}, x/{d,e,f,g}
2477 # Commit B: z/{b,c,d,e}, w/f
2478 # Expected: y/{b,c,d,e}, x/{f,g}
2480 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2481 # x/f is clear. Let's look beyond that. Here's the logic:
2482 # Commit B renamed x/ -> z/
2483 # Commit A renamed z/ -> y/
2484 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2485 # transient rename. However, where does it end? We can chain these
2486 # indefinitely (see testcase 9d). What if there is a D/F conflict
2487 # at z/f/ or y/f/? Or just another file conflict at one of those
2488 # paths? In the case of an N-long chain of transient renamings,
2489 # where do we "abort" the rename at? Can the user make sense of
2490 # the resulting conflict and resolve it?
2492 # To avoid this confusion I use the simple rule that if the other side
2493 # of history did a directory rename to a path that your side renamed
2494 # away, then ignore that particular rename from the other side of
2495 # history for any implicit directory renames.
2497 test_expect_success
'9c-setup: Doubly transitive rename?' '
2498 test_create_repo 9c &&
2512 git commit -m "O" &&
2524 git commit -m "A" &&
2534 test_expect_success
'9c-check: Doubly transitive rename?' '
2540 git merge -s recursive B^0 >out &&
2541 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2543 git ls-files -s >out &&
2544 test_line_count = 6 out &&
2545 git ls-files -o >out &&
2546 test_line_count = 1 out &&
2548 git rev-parse >actual \
2549 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2550 git rev-parse >expect \
2551 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2552 test_cmp expect actual
2556 # Testcase 9d, N-fold transitive rename?
2557 # (Related to testcase 9c...and 1c and 7e)
2558 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2559 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2560 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2561 # Expected: <see NOTE first>
2563 # NOTE: z/ -> y/ (in commit A)
2564 # y/ -> x/ (in commit B)
2565 # x/ -> w/ (in commit A)
2566 # w/ -> v/ (in commit B)
2567 # v/ -> u/ (in commit A)
2568 # So, if we add a file to z, say z/t, where should it end up? In u?
2569 # What if there's another file or directory named 't' in one of the
2570 # intervening directories and/or in u itself? Also, shouldn't the
2571 # same logic that places 't' in u/ also move ALL other files to u/?
2572 # What if there are file or directory conflicts in any of them? If
2573 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2574 # like this, would the user have any hope of understanding any
2575 # conflicts or how their working tree ended up? I think not, so I'm
2576 # ruling out N-ary transitive renames for N>1.
2578 # Therefore our expected result is:
2579 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2580 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2581 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2582 # simple rules that are consistent with what we need for all the other
2583 # testcases and simplifies things for the user.
2585 test_expect_success
'9d-setup: N-way transitive rename?' '
2586 test_create_repo 9d &&
2590 mkdir z y x w v u &&
2597 git add z y x w v u &&
2599 git commit -m "O" &&
2610 git commit -m "A" &&
2622 test_expect_success
'9d-check: N-way transitive rename?' '
2628 git merge -s recursive B^0 >out &&
2629 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2630 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2631 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2632 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2634 git ls-files -s >out &&
2635 test_line_count = 7 out &&
2636 git ls-files -o >out &&
2637 test_line_count = 1 out &&
2639 git rev-parse >actual \
2641 HEAD:y/a HEAD:x/b HEAD:w/c \
2642 HEAD:u/d HEAD:u/e HEAD:u/f &&
2643 git rev-parse >expect \
2646 O:w/d O:v/e A:u/f &&
2647 test_cmp expect actual
2651 # Testcase 9e, N-to-1 whammo
2652 # (Related to testcase 9c...and 1c and 7e)
2653 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2654 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2655 # Commit B: combined/{a,b,d,e,g,h,j,k}
2656 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2657 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2659 test_expect_success
'9e-setup: N-to-1 whammo' '
2660 test_create_repo 9e &&
2664 mkdir dir1 dir2 dir3 dirN &&
2675 git commit -m "O" &&
2692 git commit -m "A" &&
2695 git mv dir1 combined &&
2696 git mv dir2/* combined/ &&
2697 git mv dir3/* combined/ &&
2698 git mv dirN/* combined/ &&
2704 test_expect_success C_LOCALE_OUTPUT
'9e-check: N-to-1 whammo' '
2710 test_must_fail git merge -s recursive B^0 >out &&
2711 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2712 grep -q dir1/yo error_line &&
2713 grep -q dir2/yo error_line &&
2714 grep -q dir3/yo error_line &&
2715 grep -q dirN/yo error_line &&
2717 git ls-files -s >out &&
2718 test_line_count = 16 out &&
2719 git ls-files -u >out &&
2720 test_line_count = 0 out &&
2721 git ls-files -o >out &&
2722 test_line_count = 2 out &&
2724 git rev-parse >actual \
2725 :0:combined/a :0:combined/b :0:combined/c \
2726 :0:combined/d :0:combined/e :0:combined/f \
2727 :0:combined/g :0:combined/h :0:combined/i \
2728 :0:combined/j :0:combined/k :0:combined/l &&
2729 git rev-parse >expect \
2730 O:dir1/a O:dir1/b A:dir1/c \
2731 O:dir2/d O:dir2/e A:dir2/f \
2732 O:dir3/g O:dir3/h A:dir3/i \
2733 O:dirN/j O:dirN/k A:dirN/l &&
2734 test_cmp expect actual &&
2736 git rev-parse >actual \
2737 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2738 git rev-parse >expect \
2739 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2740 test_cmp expect actual
2744 # Testcase 9f, Renamed directory that only contained immediate subdirs
2745 # (Related to testcases 1e & 9g)
2746 # Commit O: goal/{a,b}/$more_files
2747 # Commit A: priority/{a,b}/$more_files
2748 # Commit B: goal/{a,b}/$more_files, goal/c
2749 # Expected: priority/{a,b}/$more_files, priority/c
2751 test_expect_success
'9f-setup: Renamed directory that only contained immediate subdirs' '
2752 test_create_repo 9f &&
2758 echo foo >goal/a/foo &&
2759 echo bar >goal/b/bar &&
2760 echo baz >goal/b/baz &&
2763 git commit -m "O" &&
2770 git mv goal/ priority &&
2772 git commit -m "A" &&
2782 test_expect_success
'9f-check: Renamed directory that only contained immediate subdirs' '
2788 git merge -s recursive B^0 &&
2790 git ls-files -s >out &&
2791 test_line_count = 4 out &&
2793 git rev-parse >actual \
2794 HEAD:priority/a/foo \
2795 HEAD:priority/b/bar \
2796 HEAD:priority/b/baz \
2798 git rev-parse >expect \
2803 test_cmp expect actual &&
2804 test_must_fail git rev-parse HEAD:goal/c
2808 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2809 # (Related to testcases 1e & 9f)
2810 # Commit O: goal/{a,b}/$more_files
2811 # Commit A: priority/{alpha,bravo}/$more_files
2812 # Commit B: goal/{a,b}/$more_files, goal/c
2813 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2815 test_expect_success
'9g-setup: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2816 test_create_repo 9g &&
2822 echo foo >goal/a/foo &&
2823 echo bar >goal/b/bar &&
2824 echo baz >goal/b/baz &&
2827 git commit -m "O" &&
2835 git mv goal/a/ priority/alpha &&
2836 git mv goal/b/ priority/beta &&
2839 git commit -m "A" &&
2849 test_expect_failure
'9g-check: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2855 git merge -s recursive B^0 &&
2857 git ls-files -s >out &&
2858 test_line_count = 4 out &&
2860 git rev-parse >actual \
2861 HEAD:priority/alpha/foo \
2862 HEAD:priority/beta/bar \
2863 HEAD:priority/beta/baz \
2865 git rev-parse >expect \
2870 test_cmp expect actual &&
2871 test_must_fail git rev-parse HEAD:goal/c
2875 # Testcase 9h, Avoid implicit rename if involved as source on other side
2876 # (Extremely closely related to testcase 3a)
2877 # Commit O: z/{b,c,d_1}
2878 # Commit A: z/{b,c,d_2}
2879 # Commit B: y/{b,c}, x/d_1
2880 # Expected: y/{b,c}, x/d_2
2881 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2882 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
2883 test_expect_success
'9h-setup: Avoid dir rename on merely modified path' '
2884 test_create_repo 9h &&
2891 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2894 git commit -m "O" &&
2904 git commit -m "A" &&
2918 test_expect_failure
'9h-check: Avoid dir rename on merely modified path' '
2924 git merge -s recursive B^0 &&
2926 git ls-files -s >out &&
2927 test_line_count = 3 out &&
2929 git rev-parse >actual \
2930 HEAD:y/b HEAD:y/c HEAD:x/d &&
2931 git rev-parse >expect \
2932 O:z/b O:z/c A:z/d &&
2933 test_cmp expect actual
2937 ###########################################################################
2938 # Rules suggested by section 9:
2940 # If the other side of history did a directory rename to a path that your
2941 # side renamed away, then ignore that particular rename from the other
2942 # side of history for any implicit directory renames.
2943 ###########################################################################
2945 ###########################################################################
2946 # SECTION 10: Handling untracked files
2948 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
2949 # the operation if untracked or dirty files would be deleted or overwritten
2950 # by the merge. Unfortunately, unpack_trees() does not understand renames,
2951 # and if it doesn't abort, then it muddies up the working directory before
2952 # we even get to the point of detecting renames, so we need some special
2953 # handling, at least in the case of directory renames.
2954 ###########################################################################
2956 # Testcase 10a, Overwrite untracked: normal rename/delete
2957 # Commit O: z/{b,c_1}
2958 # Commit A: z/b + untracked z/c + untracked z/d
2959 # Commit B: z/{b,d_1}
2960 # Expected: Aborted Merge +
2961 # ERROR_MSG(untracked working tree files would be overwritten by merge)
2963 test_expect_success
'10a-setup: Overwrite untracked with normal rename/delete' '
2964 test_create_repo 10a &&
2973 git commit -m "O" &&
2982 git commit -m "A" &&
2991 test_expect_success
'10a-check: Overwrite untracked with normal rename/delete' '
2997 echo important >z/d &&
2999 test_must_fail git merge -s recursive B^0 >out 2>err &&
3000 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
3002 git ls-files -s >out &&
3003 test_line_count = 1 out &&
3004 git ls-files -o >out &&
3005 test_line_count = 4 out &&
3007 echo very >expect &&
3008 test_cmp expect z/c &&
3010 echo important >expect &&
3011 test_cmp expect z/d &&
3013 git rev-parse HEAD:z/b >actual &&
3014 git rev-parse O:z/b >expect &&
3015 test_cmp expect actual
3019 # Testcase 10b, Overwrite untracked: dir rename + delete
3020 # Commit O: z/{b,c_1}
3021 # Commit A: y/b + untracked y/{c,d,e}
3022 # Commit B: z/{b,d_1,e}
3023 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3024 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3025 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3027 test_expect_success
'10b-setup: Overwrite untracked with dir rename + delete' '
3028 test_create_repo 10b &&
3037 git commit -m "O" &&
3047 git commit -m "A" &&
3058 test_expect_success
'10b-check: Overwrite untracked with dir rename + delete' '
3064 echo important >y/d &&
3065 echo contents >y/e &&
3067 test_must_fail git merge -s recursive B^0 >out 2>err &&
3068 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3069 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3071 git ls-files -s >out &&
3072 test_line_count = 3 out &&
3073 git ls-files -u >out &&
3074 test_line_count = 2 out &&
3075 git ls-files -o >out &&
3076 test_line_count = 5 out &&
3078 git rev-parse >actual \
3079 :0:y/b :3:y/d :3:y/e &&
3080 git rev-parse >expect \
3081 O:z/b O:z/c B:z/e &&
3082 test_cmp expect actual &&
3084 echo very >expect &&
3085 test_cmp expect y/c &&
3087 echo important >expect &&
3088 test_cmp expect y/d &&
3090 echo contents >expect &&
3095 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3096 # Commit O: z/{a,b}, x/{c,d}
3097 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3098 # Commit B: z/{a,b,c}, x/d
3099 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3100 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3102 # ERROR_MSG(Refusing to lose untracked file at y/c)
3104 test_expect_success
'10c-setup: Overwrite untracked with dir rename/rename(1to2)' '
3105 test_create_repo 10c &&
3116 git commit -m "O" &&
3127 git commit -m "A" &&
3136 test_expect_success
'10c-check: Overwrite untracked with dir rename/rename(1to2)' '
3141 echo important >y/c &&
3143 test_must_fail git merge -s recursive B^0 >out 2>err &&
3144 test_i18ngrep "CONFLICT (rename/rename)" out &&
3145 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3147 git ls-files -s >out &&
3148 test_line_count = 6 out &&
3149 git ls-files -u >out &&
3150 test_line_count = 3 out &&
3151 git ls-files -o >out &&
3152 test_line_count = 3 out &&
3154 git rev-parse >actual \
3155 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3156 git rev-parse >expect \
3157 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3158 test_cmp expect actual &&
3160 git hash-object y/c~B^0 >actual &&
3161 git rev-parse O:x/c >expect &&
3162 test_cmp expect actual &&
3164 echo important >expect &&
3169 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3170 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3171 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3172 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3173 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~B^0,wham~HEAD}+
3174 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3175 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3177 test_expect_success
'10d-setup: Delete untracked with dir rename/rename(2to1)' '
3178 test_create_repo 10d &&
3191 git commit -m "O" &&
3198 git mv z/c x/wham &&
3201 git commit -m "A" &&
3204 git mv x/f z/wham &&
3211 test_expect_success
'10d-check: Delete untracked with dir rename/rename(2to1)' '
3216 echo important >y/wham &&
3218 test_must_fail git merge -s recursive B^0 >out 2>err &&
3219 test_i18ngrep "CONFLICT (rename/rename)" out &&
3220 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3222 git ls-files -s >out &&
3223 test_line_count = 6 out &&
3224 git ls-files -u >out &&
3225 test_line_count = 2 out &&
3226 git ls-files -o >out &&
3227 test_line_count = 4 out &&
3229 git rev-parse >actual \
3230 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3231 git rev-parse >expect \
3232 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3233 test_cmp expect actual &&
3235 test_must_fail git rev-parse :1:y/wham &&
3237 echo important >expect &&
3238 test_cmp expect y/wham &&
3240 git hash-object >actual \
3241 y/wham~B^0 y/wham~HEAD &&
3242 git rev-parse >expect \
3244 test_cmp expect actual
3248 # Testcase 10e, Does git complain about untracked file that's not in the way?
3250 # Commit A: y/{a,b} + untracked z/c
3251 # Commit B: z/{a,b,c}
3252 # Expected: y/{a,b,c} + untracked z/c
3254 test_expect_success
'10e-setup: Does git complain about untracked file that is not really in the way?' '
3255 test_create_repo 10e &&
3264 git commit -m "O" &&
3273 git commit -m "A" &&
3283 test_expect_failure
'10e-check: Does git complain about untracked file that is not really in the way?' '
3291 git merge -s recursive B^0 >out 2>err &&
3292 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3294 git ls-files -s >out &&
3295 test_line_count = 3 out &&
3296 git ls-files -u >out &&
3297 test_line_count = 0 out &&
3298 git ls-files -o >out &&
3299 test_line_count = 3 out &&
3301 git rev-parse >actual \
3302 :0:y/a :0:y/b :0:y/c &&
3303 git rev-parse >expect \
3304 O:z/a O:z/b B:z/c &&
3305 test_cmp expect actual &&
3307 echo random >expect &&
3312 ###########################################################################
3313 # SECTION 11: Handling dirty (not up-to-date) files
3315 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3316 # the operation if untracked or dirty files would be deleted or overwritten
3317 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3318 # and if it doesn't abort, then it muddies up the working directory before
3319 # we even get to the point of detecting renames, so we need some special
3320 # handling. This was true even of normal renames, but there are additional
3321 # codepaths that need special handling with directory renames. Add
3322 # testcases for both renamed-by-directory-rename-detection and standard
3324 ###########################################################################
3326 # Testcase 11a, Avoid losing dirty contents with simple rename
3327 # Commit O: z/{a,b_v1},
3328 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3329 # Commit B: z/{a,b_v2}
3330 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3331 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3332 # z/c~HEAD with contents of B:z/b_v2,
3333 # z/c with uncommitted mods on top of A:z/c_v1
3335 test_expect_success
'11a-setup: Avoid losing dirty contents with simple rename' '
3336 test_create_repo 11a &&
3342 test_seq 1 10 >z/b &&
3345 git commit -m "O" &&
3354 git commit -m "A" &&
3364 test_expect_success
'11a-check: Avoid losing dirty contents with simple rename' '
3371 test_must_fail git merge -s recursive B^0 >out 2>err &&
3372 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3374 test_seq 1 10 >expected &&
3375 echo stuff >>expected &&
3376 test_cmp expected z/c &&
3378 git ls-files -s >out &&
3379 test_line_count = 2 out &&
3380 git ls-files -u >out &&
3381 test_line_count = 1 out &&
3382 git ls-files -o >out &&
3383 test_line_count = 4 out &&
3385 git rev-parse >actual \
3387 git rev-parse >expect \
3389 test_cmp expect actual &&
3391 git hash-object z/c~HEAD >actual &&
3392 git rev-parse B:z/b >expect &&
3393 test_cmp expect actual
3397 # Testcase 11b, Avoid losing dirty file involved in directory rename
3398 # Commit O: z/a, x/{b,c_v1}
3399 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3400 # Commit B: y/a, x/{b,c_v2}
3401 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3402 # ERROR_MSG(Refusing to lose dirty file at z/c)
3405 test_expect_success
'11b-setup: Avoid losing dirty file involved in directory rename' '
3406 test_create_repo 11b &&
3413 test_seq 1 10 >x/c &&
3416 git commit -m "O" &&
3425 git commit -m "A" &&
3436 test_expect_success
'11b-check: Avoid losing dirty file involved in directory rename' '
3443 git merge -s recursive B^0 >out 2>err &&
3444 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3446 grep -q stuff z/c &&
3447 test_seq 1 10 >expected &&
3448 echo stuff >>expected &&
3449 test_cmp expected z/c &&
3451 git ls-files -s >out &&
3452 test_line_count = 3 out &&
3453 git ls-files -u >out &&
3454 test_line_count = 0 out &&
3455 git ls-files -m >out &&
3456 test_line_count = 0 out &&
3457 git ls-files -o >out &&
3458 test_line_count = 4 out &&
3460 git rev-parse >actual \
3461 :0:x/b :0:y/a :0:y/c &&
3462 git rev-parse >expect \
3463 O:x/b O:z/a B:x/c &&
3464 test_cmp expect actual &&
3466 git hash-object y/c >actual &&
3467 git rev-parse B:x/c >expect &&
3468 test_cmp expect actual
3472 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3473 # Commit O: y/a, x/{b,c_v1}
3474 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3475 # Commit B: y/{a,c/d}, x/{b,c_v2}
3476 # Expected: Abort_msg("following files would be overwritten by merge") +
3477 # y/c left untouched (still has uncommitted mods)
3479 test_expect_success
'11c-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3480 test_create_repo 11c &&
3487 test_seq 1 10 >x/c &&
3490 git commit -m "O" &&
3499 git commit -m "A" &&
3505 git add x/c y/c/d &&
3511 test_expect_success
'11c-check: Avoid losing not-uptodate with rename + D/F conflict' '
3518 test_must_fail git merge -s recursive B^0 >out 2>err &&
3519 test_i18ngrep "following files would be overwritten by merge" err &&
3521 grep -q stuff y/c &&
3522 test_seq 1 10 >expected &&
3523 echo stuff >>expected &&
3524 test_cmp expected y/c &&
3526 git ls-files -s >out &&
3527 test_line_count = 3 out &&
3528 git ls-files -u >out &&
3529 test_line_count = 0 out &&
3530 git ls-files -m >out &&
3531 test_line_count = 1 out &&
3532 git ls-files -o >out &&
3533 test_line_count = 3 out
3537 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3538 # Commit O: z/a, x/{b,c_v1}
3539 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3540 # Commit B: y/{a,c/d}, x/{b,c_v2}
3541 # Expected: D/F: y/c_v2 vs y/c/d) +
3542 # Warning_Msg("Refusing to lose dirty file at z/c) +
3543 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3545 test_expect_success
'11d-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3546 test_create_repo 11d &&
3553 test_seq 1 10 >x/c &&
3556 git commit -m "O" &&
3565 git commit -m "A" &&
3572 git add x/c y/c/d &&
3578 test_expect_success
'11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
3585 test_must_fail git merge -s recursive B^0 >out 2>err &&
3586 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3588 grep -q stuff z/c &&
3589 test_seq 1 10 >expected &&
3590 echo stuff >>expected &&
3591 test_cmp expected z/c
3593 git ls-files -s >out &&
3594 test_line_count = 4 out &&
3595 git ls-files -u >out &&
3596 test_line_count = 1 out &&
3597 git ls-files -o >out &&
3598 test_line_count = 5 out &&
3600 git rev-parse >actual \
3601 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3602 git rev-parse >expect \
3603 O:x/b O:z/a B:y/c/d B:x/c &&
3604 test_cmp expect actual &&
3606 git hash-object y/c~HEAD >actual &&
3607 git rev-parse B:x/c >expect &&
3608 test_cmp expect actual
3612 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3613 # Commit O: z/{a,b}, x/{c_1,d}
3614 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3615 # Commit B: z/{a,b,c_1}, x/d
3616 # Expected: Failed Merge; y/{a,b} + x/d +
3617 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3618 # ERROR_MSG(Refusing to lose dirty file at y/c)
3619 # y/c~B^0 has O:x/c_1 contents
3620 # y/c~HEAD has A:y/c_2 contents
3621 # y/c has dirty file from before merge
3623 test_expect_success
'11e-setup: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3624 test_create_repo 11e &&
3635 git commit -m "O" &&
3643 echo different >y/c &&
3648 git commit -m "A" &&
3657 test_expect_success
'11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3664 test_must_fail git merge -s recursive B^0 >out 2>err &&
3665 test_i18ngrep "CONFLICT (rename/rename)" out &&
3666 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3668 git ls-files -s >out &&
3669 test_line_count = 7 out &&
3670 git ls-files -u >out &&
3671 test_line_count = 4 out &&
3672 git ls-files -o >out &&
3673 test_line_count = 4 out &&
3675 echo different >expected &&
3676 echo mods >>expected &&
3677 test_cmp expected y/c &&
3679 git rev-parse >actual \
3680 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3681 git rev-parse >expect \
3682 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3683 test_cmp expect actual &&
3685 git hash-object >actual \
3687 git rev-parse >expect \
3689 test_cmp expect actual
3693 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3694 # Commit O: z/{a,b}, x/{c_1,d_2}
3695 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3696 # Commit B: z/{a,b,wham_2}, x/c_1
3697 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~B^0,wham~B^HEAD} +
3698 # y/wham with dirty changes from before merge +
3699 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3700 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3702 test_expect_success
'11f-setup: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3703 test_create_repo 11f &&
3710 test_seq 1 10 >x/c &&
3714 git commit -m "O" &&
3722 git mv x/c y/wham &&
3724 git commit -m "A" &&
3727 git mv x/d z/wham &&
3733 test_expect_success
'11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3738 echo important >>y/wham &&
3740 test_must_fail git merge -s recursive B^0 >out 2>err &&
3741 test_i18ngrep "CONFLICT (rename/rename)" out &&
3742 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3744 git ls-files -s >out &&
3745 test_line_count = 4 out &&
3746 git ls-files -u >out &&
3747 test_line_count = 2 out &&
3748 git ls-files -o >out &&
3749 test_line_count = 4 out &&
3751 test_seq 1 10 >expected &&
3752 echo important >>expected &&
3753 test_cmp expected y/wham &&
3755 test_must_fail git rev-parse :1:y/wham &&
3756 git hash-object >actual \
3757 y/wham~B^0 y/wham~HEAD &&
3758 git rev-parse >expect \
3760 test_cmp expect actual &&
3762 git rev-parse >actual \
3763 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3764 git rev-parse >expect \
3765 O:z/a O:z/b O:x/c O:x/d &&
3766 test_cmp expect actual
3770 ###########################################################################
3771 # SECTION 12: Everything else
3773 # Tests suggested by others. Tests added after implementation completed
3774 # and submitted. Grab bag.
3775 ###########################################################################
3777 # Testcase 12a, Moving one directory hierarchy into another
3778 # (Related to testcase 9a)
3779 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3780 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3781 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3782 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3784 test_expect_success
'12a-setup: Moving one directory hierarchy into another' '
3785 test_create_repo 12a &&
3789 mkdir -p node1 node2 &&
3790 echo leaf1 >node1/leaf1 &&
3791 echo leaf2 >node1/leaf2 &&
3792 echo leaf3 >node2/leaf3 &&
3793 echo leaf4 >node2/leaf4 &&
3794 git add node1 node2 &&
3796 git commit -m "O" &&
3803 git mv node2/ node1/ &&
3805 git commit -m "A" &&
3808 echo leaf5 >node1/leaf5 &&
3809 echo leaf6 >node2/leaf6 &&
3810 git add node1 node2 &&
3816 test_expect_success
'12a-check: Moving one directory hierarchy into another' '
3822 git merge -s recursive B^0 &&
3824 git ls-files -s >out &&
3825 test_line_count = 6 out &&
3827 git rev-parse >actual \
3828 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3829 HEAD:node1/node2/leaf3 \
3830 HEAD:node1/node2/leaf4 \
3831 HEAD:node1/node2/leaf6 &&
3832 git rev-parse >expect \
3833 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3837 test_cmp expect actual
3841 # Testcase 12b, Moving two directory hierarchies into each other
3842 # (Related to testcases 1c and 12c)
3843 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3844 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3845 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3846 # Expected: node1/node2/node1/{leaf1, leaf2},
3847 # node2/node1/node2/{leaf3, leaf4}
3848 # NOTE: Without directory renames, we would expect
3849 # node2/node1/{leaf1, leaf2},
3850 # node1/node2/{leaf3, leaf4}
3851 # with directory rename detection, we note that
3852 # commit A renames node2/ -> node1/node2/
3853 # commit B renames node1/ -> node2/node1/
3854 # therefore, applying those directory renames to the initial result
3855 # (making all four paths experience a transitive renaming), yields
3856 # the expected result.
3858 # You may ask, is it weird to have two directories rename each other?
3859 # To which, I can do no more than shrug my shoulders and say that
3860 # even simple rules give weird results when given weird inputs.
3862 test_expect_success
'12b-setup: Moving one directory hierarchy into another' '
3863 test_create_repo 12b &&
3867 mkdir -p node1 node2 &&
3868 echo leaf1 >node1/leaf1 &&
3869 echo leaf2 >node1/leaf2 &&
3870 echo leaf3 >node2/leaf3 &&
3871 echo leaf4 >node2/leaf4 &&
3872 git add node1 node2 &&
3874 git commit -m "O" &&
3881 git mv node2/ node1/ &&
3883 git commit -m "A" &&
3886 git mv node1/ node2/ &&
3892 test_expect_failure
'12b-check: Moving one directory hierarchy into another' '
3898 git merge -s recursive B^0 &&
3900 git ls-files -s >out &&
3901 test_line_count = 4 out &&
3903 git rev-parse >actual \
3904 HEAD:node1/node2/node1/leaf1 \
3905 HEAD:node1/node2/node1/leaf2 \
3906 HEAD:node2/node1/node2/leaf3 \
3907 HEAD:node2/node1/node2/leaf4 &&
3908 git rev-parse >expect \
3913 test_cmp expect actual
3917 # Testcase 12c, Moving two directory hierarchies into each other w/ content merge
3918 # (Related to testcase 12b)
3919 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
3920 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
3921 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
3922 # Expected: Content merge conflicts for each of:
3923 # node1/node2/node1/{leaf1, leaf2},
3924 # node2/node1/node2/{leaf3, leaf4}
3925 # NOTE: This is *exactly* like 12c, except that every path is modified on
3926 # each side of the merge.
3928 test_expect_success
'12c-setup: Moving one directory hierarchy into another w/ content merge' '
3929 test_create_repo 12c &&
3933 mkdir -p node1 node2 &&
3934 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
3935 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
3936 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
3937 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
3938 git add node1 node2 &&
3940 git commit -m "O" &&
3947 git mv node2/ node1/ &&
3948 for i in `git ls-files`; do echo side A >>$i; done &&
3951 git commit -m "A" &&
3954 git mv node1/ node2/ &&
3955 for i in `git ls-files`; do echo side B >>$i; done &&
3962 test_expect_failure
'12c-check: Moving one directory hierarchy into another w/ content merge' '
3968 test_must_fail git merge -s recursive B^0 &&
3970 git ls-files -u >out &&
3971 test_line_count = 12 out &&
3973 git rev-parse >actual \
3974 :1:node1/node2/node1/leaf1 \
3975 :1:node1/node2/node1/leaf2 \
3976 :1:node2/node1/node2/leaf3 \
3977 :1:node2/node1/node2/leaf4 \
3978 :2:node1/node2/node1/leaf1 \
3979 :2:node1/node2/node1/leaf2 \
3980 :2:node2/node1/node2/leaf3 \
3981 :2:node2/node1/node2/leaf4 \
3982 :3:node1/node2/node1/leaf1 \
3983 :3:node1/node2/node1/leaf2 \
3984 :3:node2/node1/node2/leaf3 \
3985 :3:node2/node1/node2/leaf4 &&
3986 git rev-parse >expect \
3993 A:node1/node2/leaf3 \
3994 A:node1/node2/leaf4 \
3995 B:node2/node1/leaf1 \
3996 B:node2/node1/leaf2 \
3999 test_cmp expect actual