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, modify/delete or rename+modify/delete?
2082 # (Related to testcases 5b, 8d, and 9h)
2083 # Commit O: z/{b,c,d}
2085 # Commit B: z/{b,c,d_modified,e}
2086 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2088 # Note: It could easily be argued that the correct resolution here is
2089 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2090 # and that the modifed version of d should be present in y/ after
2091 # the merge, just marked as conflicted. Indeed, I previously did
2092 # argue that. But applying directory renames to the side of
2093 # history where a file is merely modified results in spurious
2094 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2097 test_expect_success
'8c-setup: modify/delete or rename+modify/delete?' '
2098 test_create_repo 8c &&
2105 test_seq 1 10 >z/d &&
2108 git commit -m "O" &&
2118 git commit -m "A" &&
2122 test_chmod +x z/d &&
2130 test_expect_success
'8c-check: modify/delete or rename+modify/delete' '
2136 test_must_fail git merge -s recursive B^0 >out &&
2137 test_i18ngrep "CONFLICT (modify/delete).* z/d" out &&
2139 git ls-files -s >out &&
2140 test_line_count = 5 out &&
2141 git ls-files -u >out &&
2142 test_line_count = 2 out &&
2143 git ls-files -o >out &&
2144 test_line_count = 1 out &&
2146 git rev-parse >actual \
2147 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2148 git rev-parse >expect \
2149 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2150 test_cmp expect actual &&
2152 test_must_fail git rev-parse :2:z/d &&
2153 git ls-files -s z/d | grep ^100755 &&
2154 test_path_is_file z/d &&
2155 test_path_is_missing y/d
2159 # Testcase 8d, rename/delete...or not?
2160 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2161 # Also related to testcases 7d and 7e)
2162 # Commit O: z/{b,c,d}
2164 # Commit B: z/{b,c,d,e}
2165 # Expected: y/{b,c,e}
2167 # Note: It would also be somewhat reasonable to resolve this as
2168 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2170 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2171 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2172 # delete) are both coming from commit A, which is illogical. Conflicts
2173 # during merging are supposed to be about opposite sides doing things
2176 test_expect_success
'8d-setup: rename/delete...or not?' '
2177 test_create_repo 8d &&
2184 test_seq 1 10 >z/d &&
2187 git commit -m "O" &&
2197 git commit -m "A" &&
2207 test_expect_success
'8d-check: rename/delete...or not?' '
2213 git merge -s recursive B^0 &&
2215 git ls-files -s >out &&
2216 test_line_count = 3 out &&
2218 git rev-parse >actual \
2219 HEAD:y/b HEAD:y/c HEAD:y/e &&
2220 git rev-parse >expect \
2221 O:z/b O:z/c B:z/e &&
2222 test_cmp expect actual
2226 # Testcase 8e, Both sides rename, one side adds to original directory
2229 # Commit B: w/{b,c}, z/d
2231 # Possible Resolutions:
2232 # w/o dir-rename detection: z/d, CONFLICT(z/b -> y/b vs. w/b),
2233 # CONFLICT(z/c -> y/c vs. w/c)
2234 # Currently expected: y/d, CONFLICT(z/b -> y/b vs. w/b),
2235 # CONFLICT(z/c -> y/c vs. w/c)
2238 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2239 # did NOT get renamed; the directory is still present; instead it is
2240 # considered to have just renamed a subset of paths in directory z
2241 # elsewhere. Therefore, the directory rename done in commit A to z/
2242 # applies to z/d and maps it to y/d.
2244 # It's possible that users would get confused about this, but what
2245 # should we do instead? Silently leaving at z/d seems just as bad or
2246 # maybe even worse. Perhaps we could print a big warning about z/d
2247 # and how we're moving to y/d in this case, but when I started thinking
2248 # about the ramifications of doing that, I didn't know how to rule out
2249 # that opening other weird edge and corner cases so I just punted.
2251 test_expect_success
'8e-setup: Both sides rename, one side adds to original directory' '
2252 test_create_repo 8e &&
2261 git commit -m "O" &&
2270 git commit -m "A" &&
2282 test_expect_success
'8e-check: Both sides rename, one side adds to original directory' '
2288 test_must_fail git merge -s recursive B^0 >out 2>err &&
2289 test_i18ngrep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2290 test_i18ngrep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2292 git ls-files -s >out &&
2293 test_line_count = 7 out &&
2294 git ls-files -u >out &&
2295 test_line_count = 6 out &&
2296 git ls-files -o >out &&
2297 test_line_count = 2 out &&
2299 git rev-parse >actual \
2300 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2301 git rev-parse >expect \
2302 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2303 test_cmp expect actual &&
2305 git hash-object >actual \
2307 git rev-parse >expect \
2308 O:z/b O:z/b O:z/c O:z/c &&
2309 test_cmp expect actual &&
2311 test_path_is_missing z/b &&
2312 test_path_is_missing z/c
2316 ###########################################################################
2317 # SECTION 9: Other testcases
2319 # This section consists of miscellaneous testcases I thought of during
2320 # the implementation which round out the testing.
2321 ###########################################################################
2323 # Testcase 9a, Inner renamed directory within outer renamed directory
2324 # (Related to testcase 1f)
2325 # Commit O: z/{b,c,d/{e,f,g}}
2326 # Commit A: y/{b,c}, x/w/{e,f,g}
2327 # Commit B: z/{b,c,d/{e,f,g,h},i}
2328 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2329 # NOTE: The only reason this one is interesting is because when a directory
2330 # is split into multiple other directories, we determine by the weight
2331 # of which one had the most paths going to it. A naive implementation
2332 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2334 test_expect_success
'9a-setup: Inner renamed directory within outer renamed directory' '
2335 test_create_repo 9a &&
2347 git commit -m "O" &&
2358 git commit -m "A" &&
2369 test_expect_success
'9a-check: Inner renamed directory within outer renamed directory' '
2375 git merge -s recursive B^0 &&
2377 git ls-files -s >out &&
2378 test_line_count = 7 out &&
2379 git ls-files -u >out &&
2380 test_line_count = 0 out &&
2381 git ls-files -o >out &&
2382 test_line_count = 1 out &&
2384 git rev-parse >actual \
2385 HEAD:y/b HEAD:y/c HEAD:y/i &&
2386 git rev-parse >expect \
2387 O:z/b O:z/c B:z/i &&
2388 test_cmp expect actual &&
2390 git rev-parse >actual \
2391 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2392 git rev-parse >expect \
2393 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2394 test_cmp expect actual
2398 # Testcase 9b, Transitive rename with content merge
2399 # (Related to testcase 1c)
2400 # Commit O: z/{b,c}, x/d_1
2401 # Commit A: y/{b,c}, x/d_2
2402 # Commit B: z/{b,c,d_3}
2403 # Expected: y/{b,c,d_merged}
2405 test_expect_success
'9b-setup: Transitive rename with content merge' '
2406 test_create_repo 9b &&
2414 test_seq 1 10 >x/d &&
2417 git commit -m "O" &&
2425 test_seq 1 11 >x/d &&
2428 git commit -m "A" &&
2431 test_seq 0 10 >x/d &&
2439 test_expect_success
'9b-check: Transitive rename with content merge' '
2445 git merge -s recursive B^0 &&
2447 git ls-files -s >out &&
2448 test_line_count = 3 out &&
2450 test_seq 0 11 >expected &&
2451 test_cmp expected y/d &&
2453 git rev-parse >actual \
2454 HEAD:y/b HEAD:y/c HEAD:y/d &&
2455 git rev-parse >expect \
2456 O:z/b O:z/c :0:expected &&
2457 test_cmp expect actual &&
2458 test_must_fail git rev-parse HEAD:x/d &&
2459 test_must_fail git rev-parse HEAD:z/d &&
2460 test_path_is_missing z/d &&
2462 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2463 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2464 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2468 # Testcase 9c, Doubly transitive rename?
2469 # (Related to testcase 1c, 7e, and 9d)
2470 # Commit O: z/{b,c}, x/{d,e}, w/f
2471 # Commit A: y/{b,c}, x/{d,e,f,g}
2472 # Commit B: z/{b,c,d,e}, w/f
2473 # Expected: y/{b,c,d,e}, x/{f,g}
2475 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2476 # x/f is clear. Let's look beyond that. Here's the logic:
2477 # Commit B renamed x/ -> z/
2478 # Commit A renamed z/ -> y/
2479 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2480 # transient rename. However, where does it end? We can chain these
2481 # indefinitely (see testcase 9d). What if there is a D/F conflict
2482 # at z/f/ or y/f/? Or just another file conflict at one of those
2483 # paths? In the case of an N-long chain of transient renamings,
2484 # where do we "abort" the rename at? Can the user make sense of
2485 # the resulting conflict and resolve it?
2487 # To avoid this confusion I use the simple rule that if the other side
2488 # of history did a directory rename to a path that your side renamed
2489 # away, then ignore that particular rename from the other side of
2490 # history for any implicit directory renames.
2492 test_expect_success
'9c-setup: Doubly transitive rename?' '
2493 test_create_repo 9c &&
2507 git commit -m "O" &&
2519 git commit -m "A" &&
2529 test_expect_success
'9c-check: Doubly transitive rename?' '
2535 git merge -s recursive B^0 >out &&
2536 test_i18ngrep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2538 git ls-files -s >out &&
2539 test_line_count = 6 out &&
2540 git ls-files -o >out &&
2541 test_line_count = 1 out &&
2543 git rev-parse >actual \
2544 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2545 git rev-parse >expect \
2546 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2547 test_cmp expect actual
2551 # Testcase 9d, N-fold transitive rename?
2552 # (Related to testcase 9c...and 1c and 7e)
2553 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2554 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2555 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2556 # Expected: <see NOTE first>
2558 # NOTE: z/ -> y/ (in commit A)
2559 # y/ -> x/ (in commit B)
2560 # x/ -> w/ (in commit A)
2561 # w/ -> v/ (in commit B)
2562 # v/ -> u/ (in commit A)
2563 # So, if we add a file to z, say z/t, where should it end up? In u?
2564 # What if there's another file or directory named 't' in one of the
2565 # intervening directories and/or in u itself? Also, shouldn't the
2566 # same logic that places 't' in u/ also move ALL other files to u/?
2567 # What if there are file or directory conflicts in any of them? If
2568 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2569 # like this, would the user have any hope of understanding any
2570 # conflicts or how their working tree ended up? I think not, so I'm
2571 # ruling out N-ary transitive renames for N>1.
2573 # Therefore our expected result is:
2574 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2575 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2576 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2577 # simple rules that are consistent with what we need for all the other
2578 # testcases and simplifies things for the user.
2580 test_expect_success
'9d-setup: N-way transitive rename?' '
2581 test_create_repo 9d &&
2585 mkdir z y x w v u &&
2592 git add z y x w v u &&
2594 git commit -m "O" &&
2605 git commit -m "A" &&
2617 test_expect_success
'9d-check: N-way transitive rename?' '
2623 git merge -s recursive B^0 >out &&
2624 test_i18ngrep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2625 test_i18ngrep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2626 test_i18ngrep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2627 test_i18ngrep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2629 git ls-files -s >out &&
2630 test_line_count = 7 out &&
2631 git ls-files -o >out &&
2632 test_line_count = 1 out &&
2634 git rev-parse >actual \
2636 HEAD:y/a HEAD:x/b HEAD:w/c \
2637 HEAD:u/d HEAD:u/e HEAD:u/f &&
2638 git rev-parse >expect \
2641 O:w/d O:v/e A:u/f &&
2642 test_cmp expect actual
2646 # Testcase 9e, N-to-1 whammo
2647 # (Related to testcase 9c...and 1c and 7e)
2648 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2649 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2650 # Commit B: combined/{a,b,d,e,g,h,j,k}
2651 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2652 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2654 test_expect_success
'9e-setup: N-to-1 whammo' '
2655 test_create_repo 9e &&
2659 mkdir dir1 dir2 dir3 dirN &&
2670 git commit -m "O" &&
2687 git commit -m "A" &&
2690 git mv dir1 combined &&
2691 git mv dir2/* combined/ &&
2692 git mv dir3/* combined/ &&
2693 git mv dirN/* combined/ &&
2699 test_expect_success C_LOCALE_OUTPUT
'9e-check: N-to-1 whammo' '
2705 test_must_fail git merge -s recursive B^0 >out &&
2706 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2707 grep -q dir1/yo error_line &&
2708 grep -q dir2/yo error_line &&
2709 grep -q dir3/yo error_line &&
2710 grep -q dirN/yo error_line &&
2712 git ls-files -s >out &&
2713 test_line_count = 16 out &&
2714 git ls-files -u >out &&
2715 test_line_count = 0 out &&
2716 git ls-files -o >out &&
2717 test_line_count = 2 out &&
2719 git rev-parse >actual \
2720 :0:combined/a :0:combined/b :0:combined/c \
2721 :0:combined/d :0:combined/e :0:combined/f \
2722 :0:combined/g :0:combined/h :0:combined/i \
2723 :0:combined/j :0:combined/k :0:combined/l &&
2724 git rev-parse >expect \
2725 O:dir1/a O:dir1/b A:dir1/c \
2726 O:dir2/d O:dir2/e A:dir2/f \
2727 O:dir3/g O:dir3/h A:dir3/i \
2728 O:dirN/j O:dirN/k A:dirN/l &&
2729 test_cmp expect actual &&
2731 git rev-parse >actual \
2732 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2733 git rev-parse >expect \
2734 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2735 test_cmp expect actual
2739 # Testcase 9f, Renamed directory that only contained immediate subdirs
2740 # (Related to testcases 1e & 9g)
2741 # Commit O: goal/{a,b}/$more_files
2742 # Commit A: priority/{a,b}/$more_files
2743 # Commit B: goal/{a,b}/$more_files, goal/c
2744 # Expected: priority/{a,b}/$more_files, priority/c
2746 test_expect_success
'9f-setup: Renamed directory that only contained immediate subdirs' '
2747 test_create_repo 9f &&
2753 echo foo >goal/a/foo &&
2754 echo bar >goal/b/bar &&
2755 echo baz >goal/b/baz &&
2758 git commit -m "O" &&
2765 git mv goal/ priority &&
2767 git commit -m "A" &&
2777 test_expect_success
'9f-check: Renamed directory that only contained immediate subdirs' '
2783 git merge -s recursive B^0 &&
2785 git ls-files -s >out &&
2786 test_line_count = 4 out &&
2788 git rev-parse >actual \
2789 HEAD:priority/a/foo \
2790 HEAD:priority/b/bar \
2791 HEAD:priority/b/baz \
2793 git rev-parse >expect \
2798 test_cmp expect actual &&
2799 test_must_fail git rev-parse HEAD:goal/c
2803 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
2804 # (Related to testcases 1e & 9f)
2805 # Commit O: goal/{a,b}/$more_files
2806 # Commit A: priority/{alpha,bravo}/$more_files
2807 # Commit B: goal/{a,b}/$more_files, goal/c
2808 # Expected: priority/{alpha,bravo}/$more_files, priority/c
2810 test_expect_success
'9g-setup: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2811 test_create_repo 9g &&
2817 echo foo >goal/a/foo &&
2818 echo bar >goal/b/bar &&
2819 echo baz >goal/b/baz &&
2822 git commit -m "O" &&
2830 git mv goal/a/ priority/alpha &&
2831 git mv goal/b/ priority/beta &&
2834 git commit -m "A" &&
2844 test_expect_failure
'9g-check: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
2850 git merge -s recursive B^0 &&
2852 git ls-files -s >out &&
2853 test_line_count = 4 out &&
2855 git rev-parse >actual \
2856 HEAD:priority/alpha/foo \
2857 HEAD:priority/beta/bar \
2858 HEAD:priority/beta/baz \
2860 git rev-parse >expect \
2865 test_cmp expect actual &&
2866 test_must_fail git rev-parse HEAD:goal/c
2870 # Testcase 9h, Avoid implicit rename if involved as source on other side
2871 # (Extremely closely related to testcase 3a)
2872 # Commit O: z/{b,c,d_1}
2873 # Commit A: z/{b,c,d_2}
2874 # Commit B: y/{b,c}, x/d_1
2875 # Expected: y/{b,c}, x/d_2
2876 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
2877 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
2878 test_expect_success
'9h-setup: Avoid dir rename on merely modified path' '
2879 test_create_repo 9h &&
2886 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
2889 git commit -m "O" &&
2899 git commit -m "A" &&
2913 test_expect_success
'9h-check: Avoid dir rename on merely modified path' '
2919 git merge -s recursive B^0 &&
2921 git ls-files -s >out &&
2922 test_line_count = 3 out &&
2924 git rev-parse >actual \
2925 HEAD:y/b HEAD:y/c HEAD:x/d &&
2926 git rev-parse >expect \
2927 O:z/b O:z/c A:z/d &&
2928 test_cmp expect actual
2932 ###########################################################################
2933 # Rules suggested by section 9:
2935 # If the other side of history did a directory rename to a path that your
2936 # side renamed away, then ignore that particular rename from the other
2937 # side of history for any implicit directory renames.
2938 ###########################################################################
2940 ###########################################################################
2941 # SECTION 10: Handling untracked files
2943 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
2944 # the operation if untracked or dirty files would be deleted or overwritten
2945 # by the merge. Unfortunately, unpack_trees() does not understand renames,
2946 # and if it doesn't abort, then it muddies up the working directory before
2947 # we even get to the point of detecting renames, so we need some special
2948 # handling, at least in the case of directory renames.
2949 ###########################################################################
2951 # Testcase 10a, Overwrite untracked: normal rename/delete
2952 # Commit O: z/{b,c_1}
2953 # Commit A: z/b + untracked z/c + untracked z/d
2954 # Commit B: z/{b,d_1}
2955 # Expected: Aborted Merge +
2956 # ERROR_MSG(untracked working tree files would be overwritten by merge)
2958 test_expect_success
'10a-setup: Overwrite untracked with normal rename/delete' '
2959 test_create_repo 10a &&
2968 git commit -m "O" &&
2977 git commit -m "A" &&
2986 test_expect_success
'10a-check: Overwrite untracked with normal rename/delete' '
2992 echo important >z/d &&
2994 test_must_fail git merge -s recursive B^0 >out 2>err &&
2995 test_i18ngrep "The following untracked working tree files would be overwritten by merge" err &&
2997 git ls-files -s >out &&
2998 test_line_count = 1 out &&
2999 git ls-files -o >out &&
3000 test_line_count = 4 out &&
3002 echo very >expect &&
3003 test_cmp expect z/c &&
3005 echo important >expect &&
3006 test_cmp expect z/d &&
3008 git rev-parse HEAD:z/b >actual &&
3009 git rev-parse O:z/b >expect &&
3010 test_cmp expect actual
3014 # Testcase 10b, Overwrite untracked: dir rename + delete
3015 # Commit O: z/{b,c_1}
3016 # Commit A: y/b + untracked y/{c,d,e}
3017 # Commit B: z/{b,d_1,e}
3018 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3019 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3020 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3022 test_expect_success
'10b-setup: Overwrite untracked with dir rename + delete' '
3023 test_create_repo 10b &&
3032 git commit -m "O" &&
3042 git commit -m "A" &&
3053 test_expect_success
'10b-check: Overwrite untracked with dir rename + delete' '
3059 echo important >y/d &&
3060 echo contents >y/e &&
3062 test_must_fail git merge -s recursive B^0 >out 2>err &&
3063 test_i18ngrep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3064 test_i18ngrep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3066 git ls-files -s >out &&
3067 test_line_count = 3 out &&
3068 git ls-files -u >out &&
3069 test_line_count = 2 out &&
3070 git ls-files -o >out &&
3071 test_line_count = 5 out &&
3073 git rev-parse >actual \
3074 :0:y/b :3:y/d :3:y/e &&
3075 git rev-parse >expect \
3076 O:z/b O:z/c B:z/e &&
3077 test_cmp expect actual &&
3079 echo very >expect &&
3080 test_cmp expect y/c &&
3082 echo important >expect &&
3083 test_cmp expect y/d &&
3085 echo contents >expect &&
3090 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3091 # Commit O: z/{a,b}, x/{c,d}
3092 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3093 # Commit B: z/{a,b,c}, x/d
3094 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3095 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3097 # ERROR_MSG(Refusing to lose untracked file at y/c)
3099 test_expect_success
'10c-setup: Overwrite untracked with dir rename/rename(1to2)' '
3100 test_create_repo 10c &&
3111 git commit -m "O" &&
3122 git commit -m "A" &&
3131 test_expect_success
'10c-check: Overwrite untracked with dir rename/rename(1to2)' '
3136 echo important >y/c &&
3138 test_must_fail git merge -s recursive B^0 >out 2>err &&
3139 test_i18ngrep "CONFLICT (rename/rename)" out &&
3140 test_i18ngrep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3142 git ls-files -s >out &&
3143 test_line_count = 6 out &&
3144 git ls-files -u >out &&
3145 test_line_count = 3 out &&
3146 git ls-files -o >out &&
3147 test_line_count = 3 out &&
3149 git rev-parse >actual \
3150 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3151 git rev-parse >expect \
3152 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3153 test_cmp expect actual &&
3155 git hash-object y/c~B^0 >actual &&
3156 git rev-parse O:x/c >expect &&
3157 test_cmp expect actual &&
3159 echo important >expect &&
3164 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3165 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3166 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3167 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3168 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~B^0,wham~HEAD}+
3169 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3170 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3172 test_expect_success
'10d-setup: Delete untracked with dir rename/rename(2to1)' '
3173 test_create_repo 10d &&
3186 git commit -m "O" &&
3193 git mv z/c x/wham &&
3196 git commit -m "A" &&
3199 git mv x/f z/wham &&
3206 test_expect_success
'10d-check: Delete untracked with dir rename/rename(2to1)' '
3211 echo important >y/wham &&
3213 test_must_fail git merge -s recursive B^0 >out 2>err &&
3214 test_i18ngrep "CONFLICT (rename/rename)" out &&
3215 test_i18ngrep "Refusing to lose untracked file at y/wham" out &&
3217 git ls-files -s >out &&
3218 test_line_count = 6 out &&
3219 git ls-files -u >out &&
3220 test_line_count = 2 out &&
3221 git ls-files -o >out &&
3222 test_line_count = 4 out &&
3224 git rev-parse >actual \
3225 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3226 git rev-parse >expect \
3227 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3228 test_cmp expect actual &&
3230 test_must_fail git rev-parse :1:y/wham &&
3232 echo important >expect &&
3233 test_cmp expect y/wham &&
3235 git hash-object >actual \
3236 y/wham~B^0 y/wham~HEAD &&
3237 git rev-parse >expect \
3239 test_cmp expect actual
3243 # Testcase 10e, Does git complain about untracked file that's not in the way?
3245 # Commit A: y/{a,b} + untracked z/c
3246 # Commit B: z/{a,b,c}
3247 # Expected: y/{a,b,c} + untracked z/c
3249 test_expect_success
'10e-setup: Does git complain about untracked file that is not really in the way?' '
3250 test_create_repo 10e &&
3259 git commit -m "O" &&
3268 git commit -m "A" &&
3278 test_expect_failure
'10e-check: Does git complain about untracked file that is not really in the way?' '
3286 git merge -s recursive B^0 >out 2>err &&
3287 test_i18ngrep ! "following untracked working tree files would be overwritten by merge" err &&
3289 git ls-files -s >out &&
3290 test_line_count = 3 out &&
3291 git ls-files -u >out &&
3292 test_line_count = 0 out &&
3293 git ls-files -o >out &&
3294 test_line_count = 3 out &&
3296 git rev-parse >actual \
3297 :0:y/a :0:y/b :0:y/c &&
3298 git rev-parse >expect \
3299 O:z/a O:z/b B:z/c &&
3300 test_cmp expect actual &&
3302 echo random >expect &&
3307 ###########################################################################
3308 # SECTION 11: Handling dirty (not up-to-date) files
3310 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3311 # the operation if untracked or dirty files would be deleted or overwritten
3312 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3313 # and if it doesn't abort, then it muddies up the working directory before
3314 # we even get to the point of detecting renames, so we need some special
3315 # handling. This was true even of normal renames, but there are additional
3316 # codepaths that need special handling with directory renames. Add
3317 # testcases for both renamed-by-directory-rename-detection and standard
3319 ###########################################################################
3321 # Testcase 11a, Avoid losing dirty contents with simple rename
3322 # Commit O: z/{a,b_v1},
3323 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3324 # Commit B: z/{a,b_v2}
3325 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3326 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3327 # z/c~HEAD with contents of B:z/b_v2,
3328 # z/c with uncommitted mods on top of A:z/c_v1
3330 test_expect_success
'11a-setup: Avoid losing dirty contents with simple rename' '
3331 test_create_repo 11a &&
3337 test_seq 1 10 >z/b &&
3340 git commit -m "O" &&
3349 git commit -m "A" &&
3359 test_expect_success
'11a-check: Avoid losing dirty contents with simple rename' '
3366 test_must_fail git merge -s recursive B^0 >out 2>err &&
3367 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3369 test_seq 1 10 >expected &&
3370 echo stuff >>expected &&
3371 test_cmp expected z/c &&
3373 git ls-files -s >out &&
3374 test_line_count = 2 out &&
3375 git ls-files -u >out &&
3376 test_line_count = 1 out &&
3377 git ls-files -o >out &&
3378 test_line_count = 4 out &&
3380 git rev-parse >actual \
3382 git rev-parse >expect \
3384 test_cmp expect actual &&
3386 git hash-object z/c~HEAD >actual &&
3387 git rev-parse B:z/b >expect &&
3388 test_cmp expect actual
3392 # Testcase 11b, Avoid losing dirty file involved in directory rename
3393 # Commit O: z/a, x/{b,c_v1}
3394 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3395 # Commit B: y/a, x/{b,c_v2}
3396 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3397 # ERROR_MSG(Refusing to lose dirty file at z/c)
3400 test_expect_success
'11b-setup: Avoid losing dirty file involved in directory rename' '
3401 test_create_repo 11b &&
3408 test_seq 1 10 >x/c &&
3411 git commit -m "O" &&
3420 git commit -m "A" &&
3431 test_expect_success
'11b-check: Avoid losing dirty file involved in directory rename' '
3438 git merge -s recursive B^0 >out 2>err &&
3439 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3441 grep -q stuff z/c &&
3442 test_seq 1 10 >expected &&
3443 echo stuff >>expected &&
3444 test_cmp expected z/c &&
3446 git ls-files -s >out &&
3447 test_line_count = 3 out &&
3448 git ls-files -u >out &&
3449 test_line_count = 0 out &&
3450 git ls-files -m >out &&
3451 test_line_count = 0 out &&
3452 git ls-files -o >out &&
3453 test_line_count = 4 out &&
3455 git rev-parse >actual \
3456 :0:x/b :0:y/a :0:y/c &&
3457 git rev-parse >expect \
3458 O:x/b O:z/a B:x/c &&
3459 test_cmp expect actual &&
3461 git hash-object y/c >actual &&
3462 git rev-parse B:x/c >expect &&
3463 test_cmp expect actual
3467 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3468 # Commit O: y/a, x/{b,c_v1}
3469 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3470 # Commit B: y/{a,c/d}, x/{b,c_v2}
3471 # Expected: Abort_msg("following files would be overwritten by merge") +
3472 # y/c left untouched (still has uncommitted mods)
3474 test_expect_success
'11c-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3475 test_create_repo 11c &&
3482 test_seq 1 10 >x/c &&
3485 git commit -m "O" &&
3494 git commit -m "A" &&
3500 git add x/c y/c/d &&
3506 test_expect_success
'11c-check: Avoid losing not-uptodate with rename + D/F conflict' '
3513 test_must_fail git merge -s recursive B^0 >out 2>err &&
3514 test_i18ngrep "following files would be overwritten by merge" err &&
3516 grep -q stuff y/c &&
3517 test_seq 1 10 >expected &&
3518 echo stuff >>expected &&
3519 test_cmp expected y/c &&
3521 git ls-files -s >out &&
3522 test_line_count = 3 out &&
3523 git ls-files -u >out &&
3524 test_line_count = 0 out &&
3525 git ls-files -m >out &&
3526 test_line_count = 1 out &&
3527 git ls-files -o >out &&
3528 test_line_count = 3 out
3532 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3533 # Commit O: z/a, x/{b,c_v1}
3534 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3535 # Commit B: y/{a,c/d}, x/{b,c_v2}
3536 # Expected: D/F: y/c_v2 vs y/c/d) +
3537 # Warning_Msg("Refusing to lose dirty file at z/c) +
3538 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3540 test_expect_success
'11d-setup: Avoid losing not-uptodate with rename + D/F conflict' '
3541 test_create_repo 11d &&
3548 test_seq 1 10 >x/c &&
3551 git commit -m "O" &&
3560 git commit -m "A" &&
3567 git add x/c y/c/d &&
3573 test_expect_success
'11d-check: Avoid losing not-uptodate with rename + D/F conflict' '
3580 test_must_fail git merge -s recursive B^0 >out 2>err &&
3581 test_i18ngrep "Refusing to lose dirty file at z/c" out &&
3583 grep -q stuff z/c &&
3584 test_seq 1 10 >expected &&
3585 echo stuff >>expected &&
3586 test_cmp expected z/c
3588 git ls-files -s >out &&
3589 test_line_count = 4 out &&
3590 git ls-files -u >out &&
3591 test_line_count = 1 out &&
3592 git ls-files -o >out &&
3593 test_line_count = 5 out &&
3595 git rev-parse >actual \
3596 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3597 git rev-parse >expect \
3598 O:x/b O:z/a B:y/c/d B:x/c &&
3599 test_cmp expect actual &&
3601 git hash-object y/c~HEAD >actual &&
3602 git rev-parse B:x/c >expect &&
3603 test_cmp expect actual
3607 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3608 # Commit O: z/{a,b}, x/{c_1,d}
3609 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3610 # Commit B: z/{a,b,c_1}, x/d
3611 # Expected: Failed Merge; y/{a,b} + x/d +
3612 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3613 # ERROR_MSG(Refusing to lose dirty file at y/c)
3614 # y/c~B^0 has O:x/c_1 contents
3615 # y/c~HEAD has A:y/c_2 contents
3616 # y/c has dirty file from before merge
3618 test_expect_success
'11e-setup: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3619 test_create_repo 11e &&
3630 git commit -m "O" &&
3638 echo different >y/c &&
3643 git commit -m "A" &&
3652 test_expect_success
'11e-check: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
3659 test_must_fail git merge -s recursive B^0 >out 2>err &&
3660 test_i18ngrep "CONFLICT (rename/rename)" out &&
3661 test_i18ngrep "Refusing to lose dirty file at y/c" out &&
3663 git ls-files -s >out &&
3664 test_line_count = 7 out &&
3665 git ls-files -u >out &&
3666 test_line_count = 4 out &&
3667 git ls-files -o >out &&
3668 test_line_count = 4 out &&
3670 echo different >expected &&
3671 echo mods >>expected &&
3672 test_cmp expected y/c &&
3674 git rev-parse >actual \
3675 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
3676 git rev-parse >expect \
3677 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
3678 test_cmp expect actual &&
3680 git hash-object >actual \
3682 git rev-parse >expect \
3684 test_cmp expect actual
3688 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
3689 # Commit O: z/{a,b}, x/{c_1,d_2}
3690 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
3691 # Commit B: z/{a,b,wham_2}, x/c_1
3692 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~B^0,wham~B^HEAD} +
3693 # y/wham with dirty changes from before merge +
3694 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
3695 # ERROR_MSG(Refusing to lose dirty file at y/wham)
3697 test_expect_success
'11f-setup: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3698 test_create_repo 11f &&
3705 test_seq 1 10 >x/c &&
3709 git commit -m "O" &&
3717 git mv x/c y/wham &&
3719 git commit -m "A" &&
3722 git mv x/d z/wham &&
3728 test_expect_success
'11f-check: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
3733 echo important >>y/wham &&
3735 test_must_fail git merge -s recursive B^0 >out 2>err &&
3736 test_i18ngrep "CONFLICT (rename/rename)" out &&
3737 test_i18ngrep "Refusing to lose dirty file at y/wham" out &&
3739 git ls-files -s >out &&
3740 test_line_count = 4 out &&
3741 git ls-files -u >out &&
3742 test_line_count = 2 out &&
3743 git ls-files -o >out &&
3744 test_line_count = 4 out &&
3746 test_seq 1 10 >expected &&
3747 echo important >>expected &&
3748 test_cmp expected y/wham &&
3750 test_must_fail git rev-parse :1:y/wham &&
3751 git hash-object >actual \
3752 y/wham~B^0 y/wham~HEAD &&
3753 git rev-parse >expect \
3755 test_cmp expect actual &&
3757 git rev-parse >actual \
3758 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
3759 git rev-parse >expect \
3760 O:z/a O:z/b O:x/c O:x/d &&
3761 test_cmp expect actual
3765 ###########################################################################
3766 # SECTION 12: Everything else
3768 # Tests suggested by others. Tests added after implementation completed
3769 # and submitted. Grab bag.
3770 ###########################################################################
3772 # Testcase 12a, Moving one directory hierarchy into another
3773 # (Related to testcase 9a)
3774 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
3775 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
3776 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
3777 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
3779 test_expect_success
'12a-setup: Moving one directory hierarchy into another' '
3780 test_create_repo 12a &&
3784 mkdir -p node1 node2 &&
3785 echo leaf1 >node1/leaf1 &&
3786 echo leaf2 >node1/leaf2 &&
3787 echo leaf3 >node2/leaf3 &&
3788 echo leaf4 >node2/leaf4 &&
3789 git add node1 node2 &&
3791 git commit -m "O" &&
3798 git mv node2/ node1/ &&
3800 git commit -m "A" &&
3803 echo leaf5 >node1/leaf5 &&
3804 echo leaf6 >node2/leaf6 &&
3805 git add node1 node2 &&
3811 test_expect_success
'12a-check: Moving one directory hierarchy into another' '
3817 git merge -s recursive B^0 &&
3819 git ls-files -s >out &&
3820 test_line_count = 6 out &&
3822 git rev-parse >actual \
3823 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
3824 HEAD:node1/node2/leaf3 \
3825 HEAD:node1/node2/leaf4 \
3826 HEAD:node1/node2/leaf6 &&
3827 git rev-parse >expect \
3828 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
3832 test_cmp expect actual
3836 # Testcase 12b, Moving two directory hierarchies into each other
3837 # (Related to testcases 1c and 12c)
3838 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
3839 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
3840 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
3841 # Expected: node1/node2/node1/{leaf1, leaf2},
3842 # node2/node1/node2/{leaf3, leaf4}
3843 # NOTE: Without directory renames, we would expect
3844 # node2/node1/{leaf1, leaf2},
3845 # node1/node2/{leaf3, leaf4}
3846 # with directory rename detection, we note that
3847 # commit A renames node2/ -> node1/node2/
3848 # commit B renames node1/ -> node2/node1/
3849 # therefore, applying those directory renames to the initial result
3850 # (making all four paths experience a transitive renaming), yields
3851 # the expected result.
3853 # You may ask, is it weird to have two directories rename each other?
3854 # To which, I can do no more than shrug my shoulders and say that
3855 # even simple rules give weird results when given weird inputs.
3857 test_expect_success
'12b-setup: Moving one directory hierarchy into another' '
3858 test_create_repo 12b &&
3862 mkdir -p node1 node2 &&
3863 echo leaf1 >node1/leaf1 &&
3864 echo leaf2 >node1/leaf2 &&
3865 echo leaf3 >node2/leaf3 &&
3866 echo leaf4 >node2/leaf4 &&
3867 git add node1 node2 &&
3869 git commit -m "O" &&
3876 git mv node2/ node1/ &&
3878 git commit -m "A" &&
3881 git mv node1/ node2/ &&
3887 test_expect_success
'12b-check: Moving one directory hierarchy into another' '
3893 git merge -s recursive B^0 &&
3895 git ls-files -s >out &&
3896 test_line_count = 4 out &&
3898 git rev-parse >actual \
3899 HEAD:node1/node2/node1/leaf1 \
3900 HEAD:node1/node2/node1/leaf2 \
3901 HEAD:node2/node1/node2/leaf3 \
3902 HEAD:node2/node1/node2/leaf4 &&
3903 git rev-parse >expect \
3908 test_cmp expect actual
3912 # Testcase 12c, Moving two directory hierarchies into each other w/ content merge
3913 # (Related to testcase 12b)
3914 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
3915 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
3916 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
3917 # Expected: Content merge conflicts for each of:
3918 # node1/node2/node1/{leaf1, leaf2},
3919 # node2/node1/node2/{leaf3, leaf4}
3920 # NOTE: This is *exactly* like 12c, except that every path is modified on
3921 # each side of the merge.
3923 test_expect_success
'12c-setup: Moving one directory hierarchy into another w/ content merge' '
3924 test_create_repo 12c &&
3928 mkdir -p node1 node2 &&
3929 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
3930 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
3931 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
3932 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
3933 git add node1 node2 &&
3935 git commit -m "O" &&
3942 git mv node2/ node1/ &&
3943 for i in `git ls-files`; do echo side A >>$i; done &&
3946 git commit -m "A" &&
3949 git mv node1/ node2/ &&
3950 for i in `git ls-files`; do echo side B >>$i; done &&
3957 test_expect_success
'12c-check: Moving one directory hierarchy into another w/ content merge' '
3963 test_must_fail git merge -s recursive B^0 &&
3965 git ls-files -u >out &&
3966 test_line_count = 12 out &&
3968 git rev-parse >actual \
3969 :1:node1/node2/node1/leaf1 \
3970 :1:node1/node2/node1/leaf2 \
3971 :1:node2/node1/node2/leaf3 \
3972 :1:node2/node1/node2/leaf4 \
3973 :2:node1/node2/node1/leaf1 \
3974 :2:node1/node2/node1/leaf2 \
3975 :2:node2/node1/node2/leaf3 \
3976 :2:node2/node1/node2/leaf4 \
3977 :3:node1/node2/node1/leaf1 \
3978 :3:node1/node2/node1/leaf2 \
3979 :3:node2/node1/node2/leaf3 \
3980 :3:node2/node1/node2/leaf4 &&
3981 git rev-parse >expect \
3988 A:node1/node2/leaf3 \
3989 A:node1/node2/leaf4 \
3990 B:node2/node1/leaf1 \
3991 B:node2/node1/leaf2 \
3994 test_cmp expect actual