Git 2.47-rc0
[git.git] / t / t6423-merge-rename-directories.sh
blob4aaaf38be684fdf566234cde82840dee35ea724a
1 #!/bin/sh
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:
10 # A
11 # o
12 # / \
13 # O o ?
14 # \ /
15 # o
16 # B
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.
22 # Notation:
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.)
28 TEST_PASSES_SANITIZE_LEAK=true
29 . ./test-lib.sh
30 . "$TEST_DIRECTORY"/lib-merge.sh
33 ###########################################################################
34 # SECTION 1: Basic cases we should be able to handle
35 ###########################################################################
37 # Testcase 1a, Basic directory rename.
38 # Commit O: z/{b,c}
39 # Commit A: y/{b,c}
40 # Commit B: z/{b,c,d,e/f}
41 # Expected: y/{b,c,d,e/f}
43 test_setup_1a () {
44 git init 1a &&
46 cd 1a &&
48 mkdir z &&
49 echo b >z/b &&
50 echo c >z/c &&
51 git add z &&
52 test_tick &&
53 git commit -m "O" &&
55 git branch O &&
56 git branch A &&
57 git branch B &&
59 git checkout A &&
60 git mv z y &&
61 test_tick &&
62 git commit -m "A" &&
64 git checkout B &&
65 echo d >z/d &&
66 mkdir z/e &&
67 echo f >z/e/f &&
68 git add z/d z/e/f &&
69 test_tick &&
70 git commit -m "B"
74 test_expect_success '1a: Simple directory rename detection' '
75 test_setup_1a &&
77 cd 1a &&
79 git checkout A^0 &&
81 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
83 git ls-files -s >out &&
84 test_line_count = 4 out &&
86 git rev-parse >actual \
87 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e/f &&
88 git rev-parse >expect \
89 O:z/b O:z/c B:z/d B:z/e/f &&
90 test_cmp expect actual &&
92 git hash-object y/d >actual &&
93 git rev-parse B:z/d >expect &&
94 test_cmp expect actual &&
96 test_must_fail git rev-parse HEAD:z/d &&
97 test_must_fail git rev-parse HEAD:z/e/f &&
98 test_path_is_missing z/d &&
99 test_path_is_missing z/e/f
103 # Testcase 1b, Merge a directory with another
104 # Commit O: z/{b,c}, y/d
105 # Commit A: z/{b,c,e}, y/d
106 # Commit B: y/{b,c,d}
107 # Expected: y/{b,c,d,e}
109 test_setup_1b () {
110 git init 1b &&
112 cd 1b &&
114 mkdir z &&
115 echo b >z/b &&
116 echo c >z/c &&
117 mkdir y &&
118 echo d >y/d &&
119 git add z y &&
120 test_tick &&
121 git commit -m "O" &&
123 git branch O &&
124 git branch A &&
125 git branch B &&
127 git checkout A &&
128 echo e >z/e &&
129 git add z/e &&
130 test_tick &&
131 git commit -m "A" &&
133 git checkout B &&
134 git mv z/b y &&
135 git mv z/c y &&
136 rmdir z &&
137 test_tick &&
138 git commit -m "B"
142 test_expect_success '1b: Merge a directory with another' '
143 test_setup_1b &&
145 cd 1b &&
147 git checkout A^0 &&
149 git -c merge.directoryRenames=true merge -s recursive B^0 &&
151 git ls-files -s >out &&
152 test_line_count = 4 out &&
154 git rev-parse >actual \
155 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e &&
156 git rev-parse >expect \
157 O:z/b O:z/c O:y/d A:z/e &&
158 test_cmp expect actual &&
159 test_must_fail git rev-parse HEAD:z/e
163 # Testcase 1c, Transitive renaming
164 # (Related to testcases 3a and 6d -- when should a transitive rename apply?)
165 # (Related to testcases 9c and 9d -- can transitivity repeat?)
166 # (Related to testcase 12b -- joint-transitivity?)
167 # Commit O: z/{b,c}, x/d
168 # Commit A: y/{b,c}, x/d
169 # Commit B: z/{b,c,d}
170 # Expected: y/{b,c,d} (because x/d -> z/d -> y/d)
172 test_setup_1c () {
173 git init 1c &&
175 cd 1c &&
177 mkdir z &&
178 echo b >z/b &&
179 echo c >z/c &&
180 mkdir x &&
181 echo d >x/d &&
182 git add z x &&
183 test_tick &&
184 git commit -m "O" &&
186 git branch O &&
187 git branch A &&
188 git branch B &&
190 git checkout A &&
191 git mv z y &&
192 test_tick &&
193 git commit -m "A" &&
195 git checkout B &&
196 git mv x/d z/d &&
197 test_tick &&
198 git commit -m "B"
202 test_expect_success '1c: Transitive renaming' '
203 test_setup_1c &&
205 cd 1c &&
207 git checkout A^0 &&
209 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
211 git ls-files -s >out &&
212 test_line_count = 3 out &&
214 git rev-parse >actual \
215 HEAD:y/b HEAD:y/c HEAD:y/d &&
216 git rev-parse >expect \
217 O:z/b O:z/c O:x/d &&
218 test_cmp expect actual &&
219 test_must_fail git rev-parse HEAD:x/d &&
220 test_must_fail git rev-parse HEAD:z/d &&
221 test_path_is_missing z/d
225 # Testcase 1d, Directory renames (merging two directories into one new one)
226 # cause a rename/rename(2to1) conflict
227 # (Related to testcases 1c and 7b)
228 # Commit O. z/{b,c}, y/{d,e}
229 # Commit A. x/{b,c}, y/{d,e,m,wham_1}
230 # Commit B. z/{b,c,n,wham_2}, x/{d,e}
231 # Expected: x/{b,c,d,e,m,n}, CONFLICT:(y/wham_1 & z/wham_2 -> x/wham)
232 # Note: y/m & z/n should definitely move into x. By the same token, both
233 # y/wham_1 & z/wham_2 should too...giving us a conflict.
235 test_setup_1d () {
236 git init 1d &&
238 cd 1d &&
240 mkdir z &&
241 echo b >z/b &&
242 echo c >z/c &&
243 mkdir y &&
244 echo d >y/d &&
245 echo e >y/e &&
246 git add z y &&
247 test_tick &&
248 git commit -m "O" &&
250 git branch O &&
251 git branch A &&
252 git branch B &&
254 git checkout A &&
255 git mv z x &&
256 echo m >y/m &&
257 echo wham1 >y/wham &&
258 git add y &&
259 test_tick &&
260 git commit -m "A" &&
262 git checkout B &&
263 git mv y x &&
264 echo n >z/n &&
265 echo wham2 >z/wham &&
266 git add z &&
267 test_tick &&
268 git commit -m "B"
272 test_expect_success '1d: Directory renames cause a rename/rename(2to1) conflict' '
273 test_setup_1d &&
275 cd 1d &&
277 git checkout A^0 &&
279 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
280 test_grep "CONFLICT (\(.*\)/\1)" out &&
282 git ls-files -s >out &&
283 test_line_count = 8 out &&
284 git ls-files -u >out &&
285 test_line_count = 2 out &&
286 git ls-files -o >out &&
287 test_line_count = 1 out &&
289 git rev-parse >actual \
290 :0:x/b :0:x/c :0:x/d :0:x/e :0:x/m :0:x/n &&
291 git rev-parse >expect \
292 O:z/b O:z/c O:y/d O:y/e A:y/m B:z/n &&
293 test_cmp expect actual &&
295 test_must_fail git rev-parse :0:x/wham &&
296 git rev-parse >actual \
297 :2:x/wham :3:x/wham &&
298 git rev-parse >expect \
299 A:y/wham B:z/wham &&
300 test_cmp expect actual &&
302 # Test that the two-way merge in x/wham is as expected
303 git cat-file -p :2:x/wham >expect &&
304 git cat-file -p :3:x/wham >other &&
305 >empty &&
306 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
307 then
308 test_must_fail git merge-file \
309 -L "HEAD:y/wham" \
310 -L "" \
311 -L "B^0:z/wham" \
312 expect empty other
313 else
314 test_must_fail git merge-file \
315 -L "HEAD" \
316 -L "" \
317 -L "B^0" \
318 expect empty other
319 fi &&
320 test_cmp expect x/wham
324 # Testcase 1e, Renamed directory, with all filenames being renamed too
325 # (Related to testcases 9f & 9g)
326 # Commit O: z/{oldb,oldc}
327 # Commit A: y/{newb,newc}
328 # Commit B: z/{oldb,oldc,d}
329 # Expected: y/{newb,newc,d}
331 test_setup_1e () {
332 git init 1e &&
334 cd 1e &&
336 mkdir z &&
337 echo b >z/oldb &&
338 echo c >z/oldc &&
339 git add z &&
340 test_tick &&
341 git commit -m "O" &&
343 git branch O &&
344 git branch A &&
345 git branch B &&
347 git checkout A &&
348 mkdir y &&
349 git mv z/oldb y/newb &&
350 git mv z/oldc y/newc &&
351 test_tick &&
352 git commit -m "A" &&
354 git checkout B &&
355 echo d >z/d &&
356 git add z/d &&
357 test_tick &&
358 git commit -m "B"
362 test_expect_success '1e: Renamed directory, with all files being renamed too' '
363 test_setup_1e &&
365 cd 1e &&
367 git checkout A^0 &&
369 git -c merge.directoryRenames=true merge -s recursive B^0 &&
371 git ls-files -s >out &&
372 test_line_count = 3 out &&
374 git rev-parse >actual \
375 HEAD:y/newb HEAD:y/newc HEAD:y/d &&
376 git rev-parse >expect \
377 O:z/oldb O:z/oldc B:z/d &&
378 test_cmp expect actual &&
379 test_must_fail git rev-parse HEAD:z/d
383 # Testcase 1f, Split a directory into two other directories
384 # (Related to testcases 3a, all of section 2, and all of section 4)
385 # Commit O: z/{b,c,d,e,f}
386 # Commit A: z/{b,c,d,e,f,g}
387 # Commit B: y/{b,c}, x/{d,e,f}
388 # Expected: y/{b,c}, x/{d,e,f,g}
390 test_setup_1f () {
391 git init 1f &&
393 cd 1f &&
395 mkdir z &&
396 echo b >z/b &&
397 echo c >z/c &&
398 echo d >z/d &&
399 echo e >z/e &&
400 echo f >z/f &&
401 git add z &&
402 test_tick &&
403 git commit -m "O" &&
405 git branch O &&
406 git branch A &&
407 git branch B &&
409 git checkout A &&
410 echo g >z/g &&
411 git add z/g &&
412 test_tick &&
413 git commit -m "A" &&
415 git checkout B &&
416 mkdir y &&
417 mkdir x &&
418 git mv z/b y/ &&
419 git mv z/c y/ &&
420 git mv z/d x/ &&
421 git mv z/e x/ &&
422 git mv z/f x/ &&
423 rmdir z &&
424 test_tick &&
425 git commit -m "B"
429 test_expect_success '1f: Split a directory into two other directories' '
430 test_setup_1f &&
432 cd 1f &&
434 git checkout A^0 &&
436 git -c merge.directoryRenames=true merge -s recursive B^0 &&
438 git ls-files -s >out &&
439 test_line_count = 6 out &&
441 git rev-parse >actual \
442 HEAD:y/b HEAD:y/c HEAD:x/d HEAD:x/e HEAD:x/f HEAD:x/g &&
443 git rev-parse >expect \
444 O:z/b O:z/c O:z/d O:z/e O:z/f A:z/g &&
445 test_cmp expect actual &&
446 test_path_is_missing z/g &&
447 test_must_fail git rev-parse HEAD:z/g
451 ###########################################################################
452 # Rules suggested by testcases in section 1:
454 # We should still detect the directory rename even if it wasn't just
455 # the directory renamed, but the files within it. (see 1b)
457 # If renames split a directory into two or more others, the directory
458 # with the most renames, "wins" (see 1f). However, see the testcases
459 # in section 2, plus testcases 3a and 4a.
460 ###########################################################################
463 ###########################################################################
464 # SECTION 2: Split into multiple directories, with equal number of paths
466 # Explore the splitting-a-directory rules a bit; what happens in the
467 # edge cases?
469 # Note that there is a closely related case of a directory not being
470 # split on either side of history, but being renamed differently on
471 # each side. See testcase 8e for that.
472 ###########################################################################
474 # Testcase 2a, Directory split into two on one side, with equal numbers of paths
475 # Commit O: z/{b,c}
476 # Commit A: y/b, w/c
477 # Commit B: z/{b,c,d}
478 # Expected: y/b, w/c, z/d, with warning about z/ -> (y/ vs. w/) conflict
479 test_setup_2a () {
480 git init 2a &&
482 cd 2a &&
484 mkdir z &&
485 echo b >z/b &&
486 echo c >z/c &&
487 git add z &&
488 test_tick &&
489 git commit -m "O" &&
491 git branch O &&
492 git branch A &&
493 git branch B &&
495 git checkout A &&
496 mkdir y &&
497 mkdir w &&
498 git mv z/b y/ &&
499 git mv z/c w/ &&
500 test_tick &&
501 git commit -m "A" &&
503 git checkout B &&
504 echo d >z/d &&
505 git add z/d &&
506 test_tick &&
507 git commit -m "B"
511 test_expect_success '2a: Directory split into two on one side, with equal numbers of paths' '
512 test_setup_2a &&
514 cd 2a &&
516 git checkout A^0 &&
518 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
519 test_grep "CONFLICT.*directory rename split" out &&
521 git ls-files -s >out &&
522 test_line_count = 3 out &&
523 git ls-files -u >out &&
524 test_line_count = 0 out &&
525 git ls-files -o >out &&
526 test_line_count = 1 out &&
528 git rev-parse >actual \
529 :0:y/b :0:w/c :0:z/d &&
530 git rev-parse >expect \
531 O:z/b O:z/c B:z/d &&
532 test_cmp expect actual
536 # Testcase 2b, Directory split into two on one side, with equal numbers of paths
537 # Commit O: z/{b,c}
538 # Commit A: y/b, w/c
539 # Commit B: z/{b,c}, x/d
540 # Expected: y/b, w/c, x/d; No warning about z/ -> (y/ vs. w/) conflict
541 test_setup_2b () {
542 git init 2b &&
544 cd 2b &&
546 mkdir z &&
547 echo b >z/b &&
548 echo c >z/c &&
549 git add z &&
550 test_tick &&
551 git commit -m "O" &&
553 git branch O &&
554 git branch A &&
555 git branch B &&
557 git checkout A &&
558 mkdir y &&
559 mkdir w &&
560 git mv z/b y/ &&
561 git mv z/c w/ &&
562 test_tick &&
563 git commit -m "A" &&
565 git checkout B &&
566 mkdir x &&
567 echo d >x/d &&
568 git add x/d &&
569 test_tick &&
570 git commit -m "B"
574 test_expect_success '2b: Directory split into two on one side, with equal numbers of paths' '
575 test_setup_2b &&
577 cd 2b &&
579 git checkout A^0 &&
581 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
583 git ls-files -s >out &&
584 test_line_count = 3 out &&
585 git ls-files -u >out &&
586 test_line_count = 0 out &&
587 git ls-files -o >out &&
588 test_line_count = 1 out &&
590 git rev-parse >actual \
591 :0:y/b :0:w/c :0:x/d &&
592 git rev-parse >expect \
593 O:z/b O:z/c B:x/d &&
594 test_cmp expect actual &&
595 test_grep ! "CONFLICT.*directory rename split" out
599 ###########################################################################
600 # Rules suggested by section 2:
602 # None; the rule was already covered in section 1. These testcases are
603 # here just to make sure the conflict resolution and necessary warning
604 # messages are handled correctly.
605 ###########################################################################
608 ###########################################################################
609 # SECTION 3: Path in question is the source path for some rename already
611 # Combining cases from Section 1 and trying to handle them could lead to
612 # directory renaming detection being over-applied. So, this section
613 # provides some good testcases to check that the implementation doesn't go
614 # too far.
615 ###########################################################################
617 # Testcase 3a, Avoid implicit rename if involved as source on other side
618 # (Related to testcases 1c, 1f, and 9h)
619 # Commit O: z/{b,c,d}
620 # Commit A: z/{b,c,d} (no change)
621 # Commit B: y/{b,c}, x/d
622 # Expected: y/{b,c}, x/d
623 test_setup_3a () {
624 git init 3a &&
626 cd 3a &&
628 mkdir z &&
629 echo b >z/b &&
630 echo c >z/c &&
631 echo d >z/d &&
632 git add z &&
633 test_tick &&
634 git commit -m "O" &&
636 git branch O &&
637 git branch A &&
638 git branch B &&
640 git checkout A &&
641 test_tick &&
642 git commit --allow-empty -m "A" &&
644 git checkout B &&
645 mkdir y &&
646 mkdir x &&
647 git mv z/b y/ &&
648 git mv z/c y/ &&
649 git mv z/d x/ &&
650 rmdir z &&
651 test_tick &&
652 git commit -m "B"
656 test_expect_success '3a: Avoid implicit rename if involved as source on other side' '
657 test_setup_3a &&
659 cd 3a &&
661 git checkout A^0 &&
663 git -c merge.directoryRenames=true merge -s recursive B^0 &&
665 git ls-files -s >out &&
666 test_line_count = 3 out &&
668 git rev-parse >actual \
669 HEAD:y/b HEAD:y/c HEAD:x/d &&
670 git rev-parse >expect \
671 O:z/b O:z/c O:z/d &&
672 test_cmp expect actual
676 # Testcase 3b, Avoid implicit rename if involved as source on other side
677 # (Related to testcases 5c and 7c, also kind of 1e and 1f)
678 # Commit O: z/{b,c,d}
679 # Commit A: y/{b,c}, x/d
680 # Commit B: z/{b,c}, w/d
681 # Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
682 # NOTE: We're particularly checking that since z/d is already involved as
683 # a source in a file rename on the same side of history, that we don't
684 # get it involved in directory rename detection. If it were, we might
685 # end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
686 # rename/rename/rename(1to3) conflict, which is just weird.
687 test_setup_3b () {
688 git init 3b &&
690 cd 3b &&
692 mkdir z &&
693 echo b >z/b &&
694 echo c >z/c &&
695 echo d >z/d &&
696 git add z &&
697 test_tick &&
698 git commit -m "O" &&
700 git branch O &&
701 git branch A &&
702 git branch B &&
704 git checkout A &&
705 mkdir y &&
706 mkdir x &&
707 git mv z/b y/ &&
708 git mv z/c y/ &&
709 git mv z/d x/ &&
710 rmdir z &&
711 test_tick &&
712 git commit -m "A" &&
714 git checkout B &&
715 mkdir w &&
716 git mv z/d w/ &&
717 test_tick &&
718 git commit -m "B"
722 test_expect_success '3b: Avoid implicit rename if involved as source on current side' '
723 test_setup_3b &&
725 cd 3b &&
727 git checkout A^0 &&
729 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
730 test_grep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
731 test_grep ! CONFLICT.*rename/rename.*y/d out &&
733 git ls-files -s >out &&
734 test_line_count = 5 out &&
735 git ls-files -u >out &&
736 test_line_count = 3 out &&
737 git ls-files -o >out &&
738 test_line_count = 1 out &&
740 git rev-parse >actual \
741 :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
742 git rev-parse >expect \
743 O:z/b O:z/c O:z/d O:z/d O:z/d &&
744 test_cmp expect actual &&
746 test_path_is_missing z/d &&
747 git hash-object >actual \
748 x/d w/d &&
749 git rev-parse >expect \
750 O:z/d O:z/d &&
751 test_cmp expect actual
755 ###########################################################################
756 # Rules suggested by section 3:
758 # Avoid directory-rename-detection for a path, if that path is the source
759 # of a rename on either side of a merge.
760 ###########################################################################
763 ###########################################################################
764 # SECTION 4: Partially renamed directory; still exists on both sides of merge
766 # What if we were to attempt to do directory rename detection when someone
767 # "mostly" moved a directory but still left some files around, or,
768 # equivalently, fully renamed a directory in one commit and then recreated
769 # that directory in a later commit adding some new files and then tried to
770 # merge?
772 # It's hard to divine user intent in these cases, because you can make an
773 # argument that, depending on the intermediate history of the side being
774 # merged, that some users will want files in that directory to
775 # automatically be detected and renamed, while users with a different
776 # intermediate history wouldn't want that rename to happen.
778 # I think that it is best to simply not have directory rename detection
779 # apply to such cases. My reasoning for this is four-fold: (1) it's
780 # easiest for users in general to figure out what happened if we don't
781 # apply directory rename detection in any such case, (2) it's an easy rule
782 # to explain ["We don't do directory rename detection if the directory
783 # still exists on both sides of the merge"], (3) we can get some hairy
784 # edge/corner cases that would be really confusing and possibly not even
785 # representable in the index if we were to even try, and [related to 3] (4)
786 # attempting to resolve this issue of divining user intent by examining
787 # intermediate history goes against the spirit of three-way merges and is a
788 # path towards crazy corner cases that are far more complex than what we're
789 # already dealing with.
791 # Note that the wording of the rule ("We don't do directory rename
792 # detection if the directory still exists on both sides of the merge.")
793 # also excludes "renaming" of a directory into a subdirectory of itself
794 # (e.g. /some/dir/* -> /some/dir/subdir/*). It may be possible to carve
795 # out an exception for "renaming"-beneath-itself cases without opening
796 # weird edge/corner cases for other partial directory renames, but for now
797 # we are keeping the rule simple.
799 # This section contains a test for a partially-renamed-directory case.
800 ###########################################################################
802 # Testcase 4a, Directory split, with original directory still present
803 # (Related to testcase 1f)
804 # Commit O: z/{b,c,d,e}
805 # Commit A: y/{b,c,d}, z/e
806 # Commit B: z/{b,c,d,e,f}
807 # Expected: y/{b,c,d}, z/{e,f}
808 # NOTE: Even though most files from z moved to y, we don't want f to follow.
810 test_setup_4a () {
811 git init 4a &&
813 cd 4a &&
815 mkdir z &&
816 echo b >z/b &&
817 echo c >z/c &&
818 echo d >z/d &&
819 echo e >z/e &&
820 git add z &&
821 test_tick &&
822 git commit -m "O" &&
824 git branch O &&
825 git branch A &&
826 git branch B &&
828 git checkout A &&
829 mkdir y &&
830 git mv z/b y/ &&
831 git mv z/c y/ &&
832 git mv z/d y/ &&
833 test_tick &&
834 git commit -m "A" &&
836 git checkout B &&
837 echo f >z/f &&
838 git add z/f &&
839 test_tick &&
840 git commit -m "B"
844 test_expect_success '4a: Directory split, with original directory still present' '
845 test_setup_4a &&
847 cd 4a &&
849 git checkout A^0 &&
851 git -c merge.directoryRenames=true merge -s recursive B^0 &&
853 git ls-files -s >out &&
854 test_line_count = 5 out &&
855 git ls-files -u >out &&
856 test_line_count = 0 out &&
857 git ls-files -o >out &&
858 test_line_count = 1 out &&
860 git rev-parse >actual \
861 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/e HEAD:z/f &&
862 git rev-parse >expect \
863 O:z/b O:z/c O:z/d O:z/e B:z/f &&
864 test_cmp expect actual
868 ###########################################################################
869 # Rules suggested by section 4:
871 # Directory-rename-detection should be turned off for any directories (as
872 # a source for renames) that exist on both sides of the merge. (The "as
873 # a source for renames" clarification is due to cases like 1c where
874 # the target directory exists on both sides and we do want the rename
875 # detection.) But, sadly, see testcase 8b.
876 ###########################################################################
879 ###########################################################################
880 # SECTION 5: Files/directories in the way of subset of to-be-renamed paths
882 # Implicitly renaming files due to a detected directory rename could run
883 # into problems if there are files or directories in the way of the paths
884 # we want to rename. Explore such cases in this section.
885 ###########################################################################
887 # Testcase 5a, Merge directories, other side adds files to original and target
888 # Commit O: z/{b,c}, y/d
889 # Commit A: z/{b,c,e_1,f}, y/{d,e_2}
890 # Commit B: y/{b,c,d}
891 # Expected: z/e_1, y/{b,c,d,e_2,f} + CONFLICT warning
892 # NOTE: While directory rename detection is active here causing z/f to
893 # become y/f, we did not apply this for z/e_1 because that would
894 # give us an add/add conflict for y/e_1 vs y/e_2. This problem with
895 # this add/add, is that both versions of y/e are from the same side
896 # of history, giving us no way to represent this conflict in the
897 # index.
899 test_setup_5a () {
900 git init 5a &&
902 cd 5a &&
904 mkdir z &&
905 echo b >z/b &&
906 echo c >z/c &&
907 mkdir y &&
908 echo d >y/d &&
909 git add z y &&
910 test_tick &&
911 git commit -m "O" &&
913 git branch O &&
914 git branch A &&
915 git branch B &&
917 git checkout A &&
918 echo e1 >z/e &&
919 echo f >z/f &&
920 echo e2 >y/e &&
921 git add z/e z/f y/e &&
922 test_tick &&
923 git commit -m "A" &&
925 git checkout B &&
926 git mv z/b y/ &&
927 git mv z/c y/ &&
928 rmdir z &&
929 test_tick &&
930 git commit -m "B"
934 test_expect_success '5a: Merge directories, other side adds files to original and target' '
935 test_setup_5a &&
937 cd 5a &&
939 git checkout A^0 &&
941 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
942 test_grep "CONFLICT.*implicit dir rename" out &&
944 git ls-files -s >out &&
945 test_line_count = 6 out &&
946 git ls-files -u >out &&
947 test_line_count = 0 out &&
948 git ls-files -o >out &&
949 test_line_count = 1 out &&
951 git rev-parse >actual \
952 :0:y/b :0:y/c :0:y/d :0:y/e :0:z/e :0:y/f &&
953 git rev-parse >expect \
954 O:z/b O:z/c O:y/d A:y/e A:z/e A:z/f &&
955 test_cmp expect actual
959 # Testcase 5b, Rename/delete in order to get add/add/add conflict
960 # (Related to testcase 8d; these may appear slightly inconsistent to users;
961 # Also related to testcases 7d and 7e)
962 # Commit O: z/{b,c,d_1}
963 # Commit A: y/{b,c,d_2}
964 # Commit B: z/{b,c,d_1,e}, y/d_3
965 # Expected: y/{b,c,e}, CONFLICT(add/add: y/d_2 vs. y/d_3)
966 # NOTE: If z/d_1 in commit B were to be involved in dir rename detection, as
967 # we normally would since z/ is being renamed to y/, then this would be
968 # a rename/delete (z/d_1 -> y/d_1 vs. deleted) AND an add/add/add
969 # conflict of y/d_1 vs. y/d_2 vs. y/d_3. Add/add/add is not
970 # representable in the index, so the existence of y/d_3 needs to
971 # cause us to bail on directory rename detection for that path, falling
972 # back to git behavior without the directory rename detection.
974 test_setup_5b () {
975 git init 5b &&
977 cd 5b &&
979 mkdir z &&
980 echo b >z/b &&
981 echo c >z/c &&
982 echo d1 >z/d &&
983 git add z &&
984 test_tick &&
985 git commit -m "O" &&
987 git branch O &&
988 git branch A &&
989 git branch B &&
991 git checkout A &&
992 git rm z/d &&
993 git mv z y &&
994 echo d2 >y/d &&
995 git add y/d &&
996 test_tick &&
997 git commit -m "A" &&
999 git checkout B &&
1000 mkdir y &&
1001 echo d3 >y/d &&
1002 echo e >z/e &&
1003 git add y/d z/e &&
1004 test_tick &&
1005 git commit -m "B"
1009 test_expect_success '5b: Rename/delete in order to get add/add/add conflict' '
1010 test_setup_5b &&
1012 cd 5b &&
1014 git checkout A^0 &&
1016 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1017 test_grep "CONFLICT (add/add).* y/d" out &&
1019 git ls-files -s >out &&
1020 test_line_count = 5 out &&
1021 git ls-files -u >out &&
1022 test_line_count = 2 out &&
1023 git ls-files -o >out &&
1024 test_line_count = 1 out &&
1026 git rev-parse >actual \
1027 :0:y/b :0:y/c :0:y/e :2:y/d :3:y/d &&
1028 git rev-parse >expect \
1029 O:z/b O:z/c B:z/e A:y/d B:y/d &&
1030 test_cmp expect actual &&
1032 test_must_fail git rev-parse :1:y/d &&
1033 test_path_is_file y/d
1037 # Testcase 5c, Transitive rename would cause rename/rename/rename/add/add/add
1038 # (Directory rename detection would result in transitive rename vs.
1039 # rename/rename(1to2) and turn it into a rename/rename(1to3). Further,
1040 # rename paths conflict with separate adds on the other side)
1041 # (Related to testcases 3b and 7c)
1042 # Commit O: z/{b,c}, x/d_1
1043 # Commit A: y/{b,c,d_2}, w/d_1
1044 # Commit B: z/{b,c,d_1,e}, w/d_3, y/d_4
1045 # Expected: A mess, but only a rename/rename(1to2)/add/add mess. Use the
1046 # presence of y/d_4 in B to avoid doing transitive rename of
1047 # x/d_1 -> z/d_1 -> y/d_1, so that the only paths we have at
1048 # y/d are y/d_2 and y/d_4. We still do the move from z/e to y/e,
1049 # though, because it doesn't have anything in the way.
1051 test_setup_5c () {
1052 git init 5c &&
1054 cd 5c &&
1056 mkdir z &&
1057 echo b >z/b &&
1058 echo c >z/c &&
1059 mkdir x &&
1060 echo d1 >x/d &&
1061 git add z x &&
1062 test_tick &&
1063 git commit -m "O" &&
1065 git branch O &&
1066 git branch A &&
1067 git branch B &&
1069 git checkout A &&
1070 git mv z y &&
1071 echo d2 >y/d &&
1072 git add y/d &&
1073 git mv x w &&
1074 test_tick &&
1075 git commit -m "A" &&
1077 git checkout B &&
1078 git mv x/d z/ &&
1079 mkdir w &&
1080 mkdir y &&
1081 echo d3 >w/d &&
1082 echo d4 >y/d &&
1083 echo e >z/e &&
1084 git add w/ y/ z/e &&
1085 test_tick &&
1086 git commit -m "B"
1090 test_expect_success '5c: Transitive rename would cause rename/rename/rename/add/add/add' '
1091 test_setup_5c &&
1093 cd 5c &&
1095 git checkout A^0 &&
1097 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1098 test_grep "CONFLICT (rename/rename).*x/d.*w/d.*z/d" out &&
1099 test_grep "CONFLICT (add/add).* y/d" out &&
1101 git ls-files -s >out &&
1102 test_line_count = 9 out &&
1103 git ls-files -u >out &&
1104 test_line_count = 6 out &&
1105 git ls-files -o >out &&
1106 test_line_count = 1 out &&
1108 git rev-parse >actual \
1109 :0:y/b :0:y/c :0:y/e &&
1110 git rev-parse >expect \
1111 O:z/b O:z/c B:z/e &&
1112 test_cmp expect actual &&
1114 test_must_fail git rev-parse :1:y/d &&
1115 git rev-parse >actual \
1116 :2:w/d :3:w/d :1:x/d :2:y/d :3:y/d :3:z/d &&
1117 git rev-parse >expect \
1118 O:x/d B:w/d O:x/d A:y/d B:y/d O:x/d &&
1119 test_cmp expect actual &&
1121 git hash-object >actual \
1122 z/d &&
1123 git rev-parse >expect \
1124 O:x/d &&
1125 test_cmp expect actual &&
1126 test_path_is_missing x/d &&
1127 test_path_is_file y/d &&
1128 grep -q "<<<<" y/d # conflict markers should be present
1132 # Testcase 5d, Directory/file/file conflict due to directory rename
1133 # Commit O: z/{b,c}
1134 # Commit A: y/{b,c,d_1}
1135 # Commit B: z/{b,c,d_2,f}, y/d/e
1136 # Expected: y/{b,c,d/e,f}, z/d_2, CONFLICT(file/directory), y/d_1~HEAD
1137 # Note: The fact that y/d/ exists in B makes us bail on directory rename
1138 # detection for z/d_2, but that doesn't prevent us from applying the
1139 # directory rename detection for z/f -> y/f.
1141 test_setup_5d () {
1142 git init 5d &&
1144 cd 5d &&
1146 mkdir z &&
1147 echo b >z/b &&
1148 echo c >z/c &&
1149 git add z &&
1150 test_tick &&
1151 git commit -m "O" &&
1153 git branch O &&
1154 git branch A &&
1155 git branch B &&
1157 git checkout A &&
1158 git mv z y &&
1159 echo d1 >y/d &&
1160 git add y/d &&
1161 test_tick &&
1162 git commit -m "A" &&
1164 git checkout B &&
1165 mkdir -p y/d &&
1166 echo e >y/d/e &&
1167 echo d2 >z/d &&
1168 echo f >z/f &&
1169 git add y/d/e z/d z/f &&
1170 test_tick &&
1171 git commit -m "B"
1175 test_expect_success '5d: Directory/file/file conflict due to directory rename' '
1176 test_setup_5d &&
1178 cd 5d &&
1180 git checkout A^0 &&
1182 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1183 test_grep "CONFLICT (file/directory).*y/d" out &&
1185 git ls-files -s >out &&
1186 test_line_count = 6 out &&
1187 git ls-files -u >out &&
1188 test_line_count = 1 out &&
1189 git ls-files -o >out &&
1190 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1191 then
1192 test_line_count = 1 out &&
1194 git rev-parse >actual \
1195 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d~HEAD :0:y/d/e
1196 else
1197 test_line_count = 2 out &&
1199 git rev-parse >actual \
1200 :0:y/b :0:y/c :0:z/d :0:y/f :2:y/d :0:y/d/e
1201 fi &&
1202 git rev-parse >expect \
1203 O:z/b O:z/c B:z/d B:z/f A:y/d B:y/d/e &&
1204 test_cmp expect actual &&
1206 git hash-object y/d~HEAD >actual &&
1207 git rev-parse A:y/d >expect &&
1208 test_cmp expect actual
1212 ###########################################################################
1213 # Rules suggested by section 5:
1215 # If a subset of to-be-renamed files have a file or directory in the way,
1216 # "turn off" the directory rename for those specific sub-paths, falling
1217 # back to old handling. But, sadly, see testcases 8a and 8b.
1218 ###########################################################################
1221 ###########################################################################
1222 # SECTION 6: Same side of the merge was the one that did the rename
1224 # It may sound obvious that you only want to apply implicit directory
1225 # renames to directories if the _other_ side of history did the renaming.
1226 # If you did make an implementation that didn't explicitly enforce this
1227 # rule, the majority of cases that would fall under this section would
1228 # also be solved by following the rules from the above sections. But
1229 # there are still a few that stick out, so this section covers them just
1230 # to make sure we also get them right.
1231 ###########################################################################
1233 # Testcase 6a, Tricky rename/delete
1234 # Commit O: z/{b,c,d}
1235 # Commit A: z/b
1236 # Commit B: y/{b,c}, z/d
1237 # Expected: y/b, CONFLICT(rename/delete, z/c -> y/c vs. NULL)
1238 # Note: We're just checking here that the rename of z/b and z/c to put
1239 # them under y/ doesn't accidentally catch z/d and make it look like
1240 # it is also involved in a rename/delete conflict.
1242 test_setup_6a () {
1243 git init 6a &&
1245 cd 6a &&
1247 mkdir z &&
1248 echo b >z/b &&
1249 echo c >z/c &&
1250 echo d >z/d &&
1251 git add z &&
1252 test_tick &&
1253 git commit -m "O" &&
1255 git branch O &&
1256 git branch A &&
1257 git branch B &&
1259 git checkout A &&
1260 git rm z/c &&
1261 git rm z/d &&
1262 test_tick &&
1263 git commit -m "A" &&
1265 git checkout B &&
1266 mkdir y &&
1267 git mv z/b y/ &&
1268 git mv z/c y/ &&
1269 test_tick &&
1270 git commit -m "B"
1274 test_expect_success '6a: Tricky rename/delete' '
1275 test_setup_6a &&
1277 cd 6a &&
1279 git checkout A^0 &&
1281 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1282 test_grep "CONFLICT (rename/delete).*z/c.*y/c" out &&
1284 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1285 then
1286 git ls-files -s >out &&
1287 test_line_count = 3 out &&
1288 git ls-files -u >out &&
1289 test_line_count = 2 out &&
1290 git ls-files -o >out &&
1291 test_line_count = 1 out &&
1293 git rev-parse >actual \
1294 :0:y/b :1:y/c :3:y/c &&
1295 git rev-parse >expect \
1296 O:z/b O:z/c O:z/c
1297 else
1298 git ls-files -s >out &&
1299 test_line_count = 2 out &&
1300 git ls-files -u >out &&
1301 test_line_count = 1 out &&
1302 git ls-files -o >out &&
1303 test_line_count = 1 out &&
1305 git rev-parse >actual \
1306 :0:y/b :3:y/c &&
1307 git rev-parse >expect \
1308 O:z/b O:z/c
1309 fi &&
1310 test_cmp expect actual
1314 # Testcase 6b1, Same rename done on both sides
1315 # (Related to testcase 6b2 and 8e)
1316 # Commit O: z/{b,c,d,e}
1317 # Commit A: y/{b,c,d}, x/e
1318 # Commit B: y/{b,c,d}, z/{e,f}
1319 # Expected: y/{b,c,d,f}, x/e
1320 # Note: Directory rename detection says A renamed z/ -> y/ (3 paths renamed
1321 # to y/ and only 1 renamed to x/), therefore the new file 'z/f' in B
1322 # should be moved to 'y/f'.
1324 # This is a bit of an edge case where any behavior might surprise users,
1325 # whether that is treating A as renaming z/ -> y/, treating A as renaming
1326 # z/ -> x/, or treating A as not doing any directory rename. However, I
1327 # think this answer is the least confusing and most consistent with the
1328 # rules elsewhere.
1330 # A note about z/ -> x/, since it may not be clear how that could come
1331 # about: If we were to ignore files renamed by both sides
1332 # (i.e. z/{b,c,d}), as directory rename detection did in git-2.18 thru
1333 # at least git-2.28, then we would note there are no renames from z/ to
1334 # y/ and one rename from z/ to x/ and thus come to the conclusion that
1335 # A renamed z/ -> x/. This seems more confusing for end users than a
1336 # rename of z/ to y/, it makes directory rename detection behavior
1337 # harder for them to predict. As such, we modified the rule, changed
1338 # the behavior on testcases 6b2 and 8e, and introduced this 6b1 testcase.
1340 test_setup_6b1 () {
1341 git init 6b1 &&
1343 cd 6b1 &&
1345 mkdir z &&
1346 echo b >z/b &&
1347 echo c >z/c &&
1348 echo d >z/d &&
1349 echo e >z/e &&
1350 git add z &&
1351 test_tick &&
1352 git commit -m "O" &&
1354 git branch O &&
1355 git branch A &&
1356 git branch B &&
1358 git checkout A &&
1359 git mv z y &&
1360 mkdir x &&
1361 git mv y/e x/e &&
1362 test_tick &&
1363 git commit -m "A" &&
1365 git checkout B &&
1366 git mv z y &&
1367 mkdir z &&
1368 git mv y/e z/e &&
1369 echo f >z/f &&
1370 git add z/f &&
1371 test_tick &&
1372 git commit -m "B"
1376 test_expect_merge_algorithm failure success '6b1: Same renames done on both sides, plus another rename' '
1377 test_setup_6b1 &&
1379 cd 6b1 &&
1381 git checkout A^0 &&
1383 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1385 git ls-files -s >out &&
1386 test_line_count = 5 out &&
1387 git ls-files -u >out &&
1388 test_line_count = 0 out &&
1389 git ls-files -o >out &&
1390 test_line_count = 1 out &&
1392 git rev-parse >actual \
1393 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:x/e HEAD:y/f &&
1394 git rev-parse >expect \
1395 O:z/b O:z/c O:z/d O:z/e B:z/f &&
1396 test_cmp expect actual
1400 # Testcase 6b2, Same rename done on both sides
1401 # (Related to testcases 6c and 8e)
1402 # Commit O: z/{b,c}
1403 # Commit A: y/{b,c}
1404 # Commit B: y/{b,c}, z/d
1405 # Expected: y/{b,c,d}
1406 # Alternate: y/{b,c}, z/d
1407 # Note: Directory rename detection says A renamed z/ -> y/, therefore the new
1408 # file 'z/d' in B should be moved to 'y/d'.
1410 # We could potentially ignore the renames of z/{b,c} on side A since
1411 # those were renamed on both sides. However, it's a bit of a corner
1412 # case because what if there was also a z/e that side A moved to x/e
1413 # and side B left alone? If we used the "ignore renames done on both
1414 # sides" logic, then we'd compute that A renamed z/ -> x/, and move
1415 # z/d to x/d. That seems more surprising and uglier than allowing
1416 # the z/ -> y/ rename.
1418 test_setup_6b2 () {
1419 git init 6b2 &&
1421 cd 6b2 &&
1423 mkdir z &&
1424 echo b >z/b &&
1425 echo c >z/c &&
1426 git add z &&
1427 test_tick &&
1428 git commit -m "O" &&
1430 git branch O &&
1431 git branch A &&
1432 git branch B &&
1434 git checkout A &&
1435 git mv z y &&
1436 test_tick &&
1437 git commit -m "A" &&
1439 git checkout B &&
1440 git mv z y &&
1441 mkdir z &&
1442 echo d >z/d &&
1443 git add z/d &&
1444 test_tick &&
1445 git commit -m "B"
1449 test_expect_merge_algorithm failure success '6b2: Same rename done on both sides' '
1450 test_setup_6b2 &&
1452 cd 6b2 &&
1454 git checkout A^0 &&
1456 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1458 git ls-files -s >out &&
1459 test_line_count = 3 out &&
1460 git ls-files -u >out &&
1461 test_line_count = 0 out &&
1462 git ls-files -o >out &&
1463 test_line_count = 1 out &&
1465 git rev-parse >actual \
1466 HEAD:y/b HEAD:y/c HEAD:y/d &&
1467 git rev-parse >expect \
1468 O:z/b O:z/c B:z/d &&
1469 test_cmp expect actual
1473 # Testcase 6c, Rename only done on same side
1474 # (Related to testcases 6b1, 6b2, and 8e)
1475 # Commit O: z/{b,c}
1476 # Commit A: z/{b,c} (no change)
1477 # Commit B: y/{b,c}, z/d
1478 # Expected: y/{b,c}, z/d
1479 # NOTE: Seems obvious, but just checking that the implementation doesn't
1480 # "accidentally detect a rename" and give us y/{b,c,d}.
1482 test_setup_6c () {
1483 git init 6c &&
1485 cd 6c &&
1487 mkdir z &&
1488 echo b >z/b &&
1489 echo c >z/c &&
1490 git add z &&
1491 test_tick &&
1492 git commit -m "O" &&
1494 git branch O &&
1495 git branch A &&
1496 git branch B &&
1498 git checkout A &&
1499 test_tick &&
1500 git commit --allow-empty -m "A" &&
1502 git checkout B &&
1503 git mv z y &&
1504 mkdir z &&
1505 echo d >z/d &&
1506 git add z/d &&
1507 test_tick &&
1508 git commit -m "B"
1512 test_expect_success '6c: Rename only done on same side' '
1513 test_setup_6c &&
1515 cd 6c &&
1517 git checkout A^0 &&
1519 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1521 git ls-files -s >out &&
1522 test_line_count = 3 out &&
1523 git ls-files -u >out &&
1524 test_line_count = 0 out &&
1525 git ls-files -o >out &&
1526 test_line_count = 1 out &&
1528 git rev-parse >actual \
1529 HEAD:y/b HEAD:y/c HEAD:z/d &&
1530 git rev-parse >expect \
1531 O:z/b O:z/c B:z/d &&
1532 test_cmp expect actual
1536 # Testcase 6d, We don't always want transitive renaming
1537 # (Related to testcase 1c)
1538 # Commit O: z/{b,c}, x/d
1539 # Commit A: z/{b,c}, x/d (no change)
1540 # Commit B: y/{b,c}, z/d
1541 # Expected: y/{b,c}, z/d
1542 # NOTE: Again, this seems obvious but just checking that the implementation
1543 # doesn't "accidentally detect a rename" and give us y/{b,c,d}.
1545 test_setup_6d () {
1546 git init 6d &&
1548 cd 6d &&
1550 mkdir z &&
1551 echo b >z/b &&
1552 echo c >z/c &&
1553 mkdir x &&
1554 echo d >x/d &&
1555 git add z x &&
1556 test_tick &&
1557 git commit -m "O" &&
1559 git branch O &&
1560 git branch A &&
1561 git branch B &&
1563 git checkout A &&
1564 test_tick &&
1565 git commit --allow-empty -m "A" &&
1567 git checkout B &&
1568 git mv z y &&
1569 git mv x z &&
1570 test_tick &&
1571 git commit -m "B"
1575 test_expect_success '6d: We do not always want transitive renaming' '
1576 test_setup_6d &&
1578 cd 6d &&
1580 git checkout A^0 &&
1582 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1584 git ls-files -s >out &&
1585 test_line_count = 3 out &&
1586 git ls-files -u >out &&
1587 test_line_count = 0 out &&
1588 git ls-files -o >out &&
1589 test_line_count = 1 out &&
1591 git rev-parse >actual \
1592 HEAD:y/b HEAD:y/c HEAD:z/d &&
1593 git rev-parse >expect \
1594 O:z/b O:z/c O:x/d &&
1595 test_cmp expect actual
1599 # Testcase 6e, Add/add from one-side
1600 # Commit O: z/{b,c}
1601 # Commit A: z/{b,c} (no change)
1602 # Commit B: y/{b,c,d_1}, z/d_2
1603 # Expected: y/{b,c,d_1}, z/d_2
1604 # NOTE: Again, this seems obvious but just checking that the implementation
1605 # doesn't "accidentally detect a rename" and give us y/{b,c} +
1606 # add/add conflict on y/d_1 vs y/d_2.
1608 test_setup_6e () {
1609 git init 6e &&
1611 cd 6e &&
1613 mkdir z &&
1614 echo b >z/b &&
1615 echo c >z/c &&
1616 git add z &&
1617 test_tick &&
1618 git commit -m "O" &&
1620 git branch O &&
1621 git branch A &&
1622 git branch B &&
1624 git checkout A &&
1625 test_tick &&
1626 git commit --allow-empty -m "A" &&
1628 git checkout B &&
1629 git mv z y &&
1630 echo d1 > y/d &&
1631 mkdir z &&
1632 echo d2 > z/d &&
1633 git add y/d z/d &&
1634 test_tick &&
1635 git commit -m "B"
1639 test_expect_success '6e: Add/add from one side' '
1640 test_setup_6e &&
1642 cd 6e &&
1644 git checkout A^0 &&
1646 git -c merge.directoryRenames=true merge -s recursive B^0 &&
1648 git ls-files -s >out &&
1649 test_line_count = 4 out &&
1650 git ls-files -u >out &&
1651 test_line_count = 0 out &&
1652 git ls-files -o >out &&
1653 test_line_count = 1 out &&
1655 git rev-parse >actual \
1656 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:z/d &&
1657 git rev-parse >expect \
1658 O:z/b O:z/c B:y/d B:z/d &&
1659 test_cmp expect actual
1663 ###########################################################################
1664 # Rules suggested by section 6:
1666 # Only apply implicit directory renames to directories if the other
1667 # side of history is the one doing the renaming.
1668 ###########################################################################
1671 ###########################################################################
1672 # SECTION 7: More involved Edge/Corner cases
1674 # The ruleset we have generated in the above sections seems to provide
1675 # well-defined merges. But can we find edge/corner cases that either (a)
1676 # are harder for users to understand, or (b) have a resolution that is
1677 # non-intuitive or suboptimal?
1679 # The testcases in this section dive into cases that I've tried to craft in
1680 # a way to find some that might be surprising to users or difficult for
1681 # them to understand (the next section will look at non-intuitive or
1682 # suboptimal merge results). Some of the testcases are similar to ones
1683 # from past sections, but have been simplified to try to highlight error
1684 # messages using a "modified" path (due to the directory rename). Are
1685 # users okay with these?
1687 # In my opinion, testcases that are difficult to understand from this
1688 # section is due to difficulty in the testcase rather than the directory
1689 # renaming (similar to how t6042 and t6036 have difficult resolutions due
1690 # to the problem setup itself being complex). And I don't think the
1691 # error messages are a problem.
1693 # On the other hand, the testcases in section 8 worry me slightly more...
1694 ###########################################################################
1696 # Testcase 7a, rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file
1697 # Commit O: z/{b,c}
1698 # Commit A: y/{b,c}
1699 # Commit B: w/b, x/c, z/d
1700 # Expected: y/d, CONFLICT(rename/rename for both z/b and z/c)
1701 # NOTE: There's a rename of z/ here, y/ has more renames, so z/d -> y/d.
1703 test_setup_7a () {
1704 git init 7a &&
1706 cd 7a &&
1708 mkdir z &&
1709 echo b >z/b &&
1710 echo c >z/c &&
1711 git add z &&
1712 test_tick &&
1713 git commit -m "O" &&
1715 git branch O &&
1716 git branch A &&
1717 git branch B &&
1719 git checkout A &&
1720 git mv z y &&
1721 test_tick &&
1722 git commit -m "A" &&
1724 git checkout B &&
1725 mkdir w &&
1726 mkdir x &&
1727 git mv z/b w/ &&
1728 git mv z/c x/ &&
1729 echo d > z/d &&
1730 git add z/d &&
1731 test_tick &&
1732 git commit -m "B"
1736 test_expect_success '7a: rename-dir vs. rename-dir (NOT split evenly) PLUS add-other-file' '
1737 test_setup_7a &&
1739 cd 7a &&
1741 git checkout A^0 &&
1743 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1744 test_grep "CONFLICT (rename/rename).*z/b.*y/b.*w/b" out &&
1745 test_grep "CONFLICT (rename/rename).*z/c.*y/c.*x/c" out &&
1747 git ls-files -s >out &&
1748 test_line_count = 7 out &&
1749 git ls-files -u >out &&
1750 test_line_count = 6 out &&
1751 git ls-files -o >out &&
1752 test_line_count = 1 out &&
1754 git rev-parse >actual \
1755 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:x/c :0:y/d &&
1756 git rev-parse >expect \
1757 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
1758 test_cmp expect actual &&
1760 git hash-object >actual \
1761 y/b w/b y/c x/c &&
1762 git rev-parse >expect \
1763 O:z/b O:z/b O:z/c O:z/c &&
1764 test_cmp expect actual
1768 # Testcase 7b, rename/rename(2to1), but only due to transitive rename
1769 # (Related to testcase 1d)
1770 # Commit O: z/{b,c}, x/d_1, w/d_2
1771 # Commit A: y/{b,c,d_2}, x/d_1
1772 # Commit B: z/{b,c,d_1}, w/d_2
1773 # Expected: y/{b,c}, CONFLICT(rename/rename(2to1): x/d_1, w/d_2 -> y_d)
1775 test_setup_7b () {
1776 git init 7b &&
1778 cd 7b &&
1780 mkdir z &&
1781 mkdir x &&
1782 mkdir w &&
1783 echo b >z/b &&
1784 echo c >z/c &&
1785 echo d1 > x/d &&
1786 echo d2 > w/d &&
1787 git add z x w &&
1788 test_tick &&
1789 git commit -m "O" &&
1791 git branch O &&
1792 git branch A &&
1793 git branch B &&
1795 git checkout A &&
1796 git mv z y &&
1797 git mv w/d y/ &&
1798 test_tick &&
1799 git commit -m "A" &&
1801 git checkout B &&
1802 git mv x/d z/ &&
1803 rmdir x &&
1804 test_tick &&
1805 git commit -m "B"
1809 test_expect_success '7b: rename/rename(2to1), but only due to transitive rename' '
1810 test_setup_7b &&
1812 cd 7b &&
1814 git checkout A^0 &&
1816 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1817 test_grep "CONFLICT (\(.*\)/\1)" out &&
1819 git ls-files -s >out &&
1820 test_line_count = 4 out &&
1821 git ls-files -u >out &&
1822 test_line_count = 2 out &&
1823 git ls-files -o >out &&
1824 test_line_count = 1 out &&
1826 git rev-parse >actual \
1827 :0:y/b :0:y/c :2:y/d :3:y/d &&
1828 git rev-parse >expect \
1829 O:z/b O:z/c O:w/d O:x/d &&
1830 test_cmp expect actual &&
1832 # Test that the two-way merge in y/d is as expected
1833 git cat-file -p :2:y/d >expect &&
1834 git cat-file -p :3:y/d >other &&
1835 >empty &&
1836 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1837 then
1838 test_must_fail git merge-file \
1839 -L "HEAD:y/d" \
1840 -L "" \
1841 -L "B^0:z/d" \
1842 expect empty other
1843 else
1844 test_must_fail git merge-file \
1845 -L "HEAD" \
1846 -L "" \
1847 -L "B^0" \
1848 expect empty other
1849 fi &&
1850 test_cmp expect y/d
1854 # Testcase 7c, rename/rename(1to...2or3); transitive rename may add complexity
1855 # (Related to testcases 3b and 5c)
1856 # Commit O: z/{b,c}, x/d
1857 # Commit A: y/{b,c}, w/d
1858 # Commit B: z/{b,c,d}
1859 # Expected: y/{b,c}, CONFLICT(x/d -> w/d vs. y/d)
1860 # NOTE: z/ was renamed to y/ so we do want to report
1861 # neither CONFLICT(x/d -> w/d vs. z/d)
1862 # nor CONFLiCT x/d -> w/d vs. y/d vs. z/d)
1864 test_setup_7c () {
1865 git init 7c &&
1867 cd 7c &&
1869 mkdir z &&
1870 echo b >z/b &&
1871 echo c >z/c &&
1872 mkdir x &&
1873 echo d >x/d &&
1874 git add z x &&
1875 test_tick &&
1876 git commit -m "O" &&
1878 git branch O &&
1879 git branch A &&
1880 git branch B &&
1882 git checkout A &&
1883 git mv z y &&
1884 git mv x w &&
1885 test_tick &&
1886 git commit -m "A" &&
1888 git checkout B &&
1889 git mv x/d z/ &&
1890 rmdir x &&
1891 test_tick &&
1892 git commit -m "B"
1896 test_expect_success '7c: rename/rename(1to...2or3); transitive rename may add complexity' '
1897 test_setup_7c &&
1899 cd 7c &&
1901 git checkout A^0 &&
1903 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1904 test_grep "CONFLICT (rename/rename).*x/d.*w/d.*y/d" out &&
1906 git ls-files -s >out &&
1907 test_line_count = 5 out &&
1908 git ls-files -u >out &&
1909 test_line_count = 3 out &&
1910 git ls-files -o >out &&
1911 test_line_count = 1 out &&
1913 git rev-parse >actual \
1914 :0:y/b :0:y/c :1:x/d :2:w/d :3:y/d &&
1915 git rev-parse >expect \
1916 O:z/b O:z/c O:x/d O:x/d O:x/d &&
1917 test_cmp expect actual
1921 # Testcase 7d, transitive rename involved in rename/delete; how is it reported?
1922 # (Related somewhat to testcases 5b and 8d)
1923 # Commit O: z/{b,c}, x/d
1924 # Commit A: y/{b,c}
1925 # Commit B: z/{b,c,d}
1926 # Expected: y/{b,c}, CONFLICT(delete x/d vs rename to y/d)
1927 # NOTE: z->y so NOT CONFLICT(delete x/d vs rename to z/d)
1929 test_setup_7d () {
1930 git init 7d &&
1932 cd 7d &&
1934 mkdir z &&
1935 echo b >z/b &&
1936 echo c >z/c &&
1937 mkdir x &&
1938 echo d >x/d &&
1939 git add z x &&
1940 test_tick &&
1941 git commit -m "O" &&
1943 git branch O &&
1944 git branch A &&
1945 git branch B &&
1947 git checkout A &&
1948 git mv z y &&
1949 git rm -rf x &&
1950 test_tick &&
1951 git commit -m "A" &&
1953 git checkout B &&
1954 git mv x/d z/ &&
1955 rmdir x &&
1956 test_tick &&
1957 git commit -m "B"
1961 test_expect_success '7d: transitive rename involved in rename/delete; how is it reported?' '
1962 test_setup_7d &&
1964 cd 7d &&
1966 git checkout A^0 &&
1968 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
1969 test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
1971 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
1972 then
1973 git ls-files -s >out &&
1974 test_line_count = 4 out &&
1975 git ls-files -u >out &&
1976 test_line_count = 2 out &&
1977 git ls-files -o >out &&
1978 test_line_count = 1 out &&
1980 git rev-parse >actual \
1981 :0:y/b :0:y/c :1:y/d :3:y/d &&
1982 git rev-parse >expect \
1983 O:z/b O:z/c O:x/d O:x/d
1984 else
1985 git ls-files -s >out &&
1986 test_line_count = 3 out &&
1987 git ls-files -u >out &&
1988 test_line_count = 1 out &&
1989 git ls-files -o >out &&
1990 test_line_count = 1 out &&
1992 git rev-parse >actual \
1993 :0:y/b :0:y/c :3:y/d &&
1994 git rev-parse >expect \
1995 O:z/b O:z/c O:x/d
1996 fi &&
1997 test_cmp expect actual
2001 # Testcase 7e, transitive rename in rename/delete AND dirs in the way
2002 # (Very similar to 'both rename source and destination involved in D/F conflict' from t6022-merge-rename.sh)
2003 # (Also related to testcases 9c and 9d)
2004 # Commit O: z/{b,c}, x/d_1
2005 # Commit A: y/{b,c,d/g}, x/d/f
2006 # Commit B: z/{b,c,d_1}
2007 # Expected: rename/delete(x/d_1->y/d_1 vs. None) + D/F conflict on y/d
2008 # y/{b,c,d/g}, y/d_1~B^0, x/d/f
2010 # NOTE: The main path of interest here is d_1 and where it ends up, but
2011 # this is actually a case that has two potential directory renames
2012 # involved and D/F conflict(s), so it makes sense to walk through
2013 # each step.
2015 # Commit A renames z/ -> y/. Thus everything that B adds to z/
2016 # should be instead moved to y/. This gives us the D/F conflict on
2017 # y/d because x/d_1 -> z/d_1 -> y/d_1 conflicts with y/d/g.
2019 # Further, commit B renames x/ -> z/, thus everything A adds to x/
2020 # should instead be moved to z/...BUT we removed z/ and renamed it
2021 # to y/, so maybe everything should move not from x/ to z/, but
2022 # from x/ to z/ to y/. Doing so might make sense from the logic so
2023 # far, but note that commit A had both an x/ and a y/; it did the
2024 # renaming of z/ to y/ and created x/d/f and it clearly made these
2025 # things separate, so it doesn't make much sense to push these
2026 # together. Doing so is what I'd call a doubly transitive rename;
2027 # see testcases 9c and 9d for further discussion of this issue and
2028 # how it's resolved.
2030 test_setup_7e () {
2031 git init 7e &&
2033 cd 7e &&
2035 mkdir z &&
2036 echo b >z/b &&
2037 echo c >z/c &&
2038 mkdir x &&
2039 echo d1 >x/d &&
2040 git add z x &&
2041 test_tick &&
2042 git commit -m "O" &&
2044 git branch O &&
2045 git branch A &&
2046 git branch B &&
2048 git checkout A &&
2049 git mv z y &&
2050 git rm x/d &&
2051 mkdir -p x/d &&
2052 mkdir -p y/d &&
2053 echo f >x/d/f &&
2054 echo g >y/d/g &&
2055 git add x/d/f y/d/g &&
2056 test_tick &&
2057 git commit -m "A" &&
2059 git checkout B &&
2060 git mv x/d z/ &&
2061 rmdir x &&
2062 test_tick &&
2063 git commit -m "B"
2067 test_expect_success '7e: transitive rename in rename/delete AND dirs in the way' '
2068 test_setup_7e &&
2070 cd 7e &&
2072 git checkout A^0 &&
2074 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2075 test_grep "CONFLICT (rename/delete).*x/d.*y/d" out &&
2077 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
2078 then
2079 git ls-files -s >out &&
2080 test_line_count = 6 out &&
2081 git ls-files -u >out &&
2082 test_line_count = 2 out &&
2083 git ls-files -o >out &&
2084 test_line_count = 1 out &&
2086 git rev-parse >actual \
2087 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :1:y/d~B^0 :3:y/d~B^0 &&
2088 git rev-parse >expect \
2089 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d O:x/d
2090 else
2091 git ls-files -s >out &&
2092 test_line_count = 5 out &&
2093 git ls-files -u >out &&
2094 test_line_count = 1 out &&
2095 git ls-files -o >out &&
2096 test_line_count = 2 out &&
2098 git rev-parse >actual \
2099 :0:x/d/f :0:y/d/g :0:y/b :0:y/c :3:y/d &&
2100 git rev-parse >expect \
2101 A:x/d/f A:y/d/g O:z/b O:z/c O:x/d
2102 fi &&
2103 test_cmp expect actual &&
2105 git hash-object y/d~B^0 >actual &&
2106 git rev-parse O:x/d >expect &&
2107 test_cmp expect actual
2111 ###########################################################################
2112 # SECTION 8: Suboptimal merges
2114 # As alluded to in the last section, the ruleset we have built up for
2115 # detecting directory renames unfortunately has some special cases where it
2116 # results in slightly suboptimal or non-intuitive behavior. This section
2117 # explores these cases.
2119 # To be fair, we already had non-intuitive or suboptimal behavior for most
2120 # of these cases in git before introducing implicit directory rename
2121 # detection, but it'd be nice if there was a modified ruleset out there
2122 # that handled these cases a bit better.
2123 ###########################################################################
2125 # Testcase 8a, Dual-directory rename, one into the others' way
2126 # Commit O. x/{a,b}, y/{c,d}
2127 # Commit A. x/{a,b,e}, y/{c,d,f}
2128 # Commit B. y/{a,b}, z/{c,d}
2130 # Possible Resolutions:
2131 # w/o dir-rename detection: y/{a,b,f}, z/{c,d}, x/e
2132 # Currently expected: y/{a,b,e,f}, z/{c,d}
2133 # Optimal: y/{a,b,e}, z/{c,d,f}
2135 # Note: Both x and y got renamed and it'd be nice to detect both, and we do
2136 # better with directory rename detection than git did without, but the
2137 # simple rule from section 5 prevents me from handling this as optimally as
2138 # we potentially could.
2140 test_setup_8a () {
2141 git init 8a &&
2143 cd 8a &&
2145 mkdir x &&
2146 mkdir y &&
2147 echo a >x/a &&
2148 echo b >x/b &&
2149 echo c >y/c &&
2150 echo d >y/d &&
2151 git add x y &&
2152 test_tick &&
2153 git commit -m "O" &&
2155 git branch O &&
2156 git branch A &&
2157 git branch B &&
2159 git checkout A &&
2160 echo e >x/e &&
2161 echo f >y/f &&
2162 git add x/e y/f &&
2163 test_tick &&
2164 git commit -m "A" &&
2166 git checkout B &&
2167 git mv y z &&
2168 git mv x y &&
2169 test_tick &&
2170 git commit -m "B"
2174 test_expect_success '8a: Dual-directory rename, one into the others way' '
2175 test_setup_8a &&
2177 cd 8a &&
2179 git checkout A^0 &&
2181 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2183 git ls-files -s >out &&
2184 test_line_count = 6 out &&
2185 git ls-files -u >out &&
2186 test_line_count = 0 out &&
2187 git ls-files -o >out &&
2188 test_line_count = 1 out &&
2190 git rev-parse >actual \
2191 HEAD:y/a HEAD:y/b HEAD:y/e HEAD:y/f HEAD:z/c HEAD:z/d &&
2192 git rev-parse >expect \
2193 O:x/a O:x/b A:x/e A:y/f O:y/c O:y/d &&
2194 test_cmp expect actual
2198 # Testcase 8b, Dual-directory rename, one into the others' way, with conflicting filenames
2199 # Commit O. x/{a_1,b_1}, y/{a_2,b_2}
2200 # Commit A. x/{a_1,b_1,e_1}, y/{a_2,b_2,e_2}
2201 # Commit B. y/{a_1,b_1}, z/{a_2,b_2}
2203 # w/o dir-rename detection: y/{a_1,b_1,e_2}, z/{a_2,b_2}, x/e_1
2204 # Currently expected: <same>
2205 # Scary: y/{a_1,b_1}, z/{a_2,b_2}, CONFLICT(add/add, e_1 vs. e_2)
2206 # Optimal: y/{a_1,b_1,e_1}, z/{a_2,b_2,e_2}
2208 # Note: Very similar to 8a, except instead of 'e' and 'f' in directories x and
2209 # y, both are named 'e'. Without directory rename detection, neither file
2210 # moves directories. Implement directory rename detection suboptimally, and
2211 # you get an add/add conflict, but both files were added in commit A, so this
2212 # is an add/add conflict where one side of history added both files --
2213 # something we can't represent in the index. Obviously, we'd prefer the last
2214 # resolution, but our previous rules are too coarse to allow it. Using both
2215 # the rules from section 4 and section 5 save us from the Scary resolution,
2216 # making us fall back to pre-directory-rename-detection behavior for both
2217 # e_1 and e_2.
2219 test_setup_8b () {
2220 git init 8b &&
2222 cd 8b &&
2224 mkdir x &&
2225 mkdir y &&
2226 echo a1 >x/a &&
2227 echo b1 >x/b &&
2228 echo a2 >y/a &&
2229 echo b2 >y/b &&
2230 git add x y &&
2231 test_tick &&
2232 git commit -m "O" &&
2234 git branch O &&
2235 git branch A &&
2236 git branch B &&
2238 git checkout A &&
2239 echo e1 >x/e &&
2240 echo e2 >y/e &&
2241 git add x/e y/e &&
2242 test_tick &&
2243 git commit -m "A" &&
2245 git checkout B &&
2246 git mv y z &&
2247 git mv x y &&
2248 test_tick &&
2249 git commit -m "B"
2253 test_expect_success '8b: Dual-directory rename, one into the others way, with conflicting filenames' '
2254 test_setup_8b &&
2256 cd 8b &&
2258 git checkout A^0 &&
2260 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2262 git ls-files -s >out &&
2263 test_line_count = 6 out &&
2264 git ls-files -u >out &&
2265 test_line_count = 0 out &&
2266 git ls-files -o >out &&
2267 test_line_count = 1 out &&
2269 git rev-parse >actual \
2270 HEAD:y/a HEAD:y/b HEAD:z/a HEAD:z/b HEAD:x/e HEAD:y/e &&
2271 git rev-parse >expect \
2272 O:x/a O:x/b O:y/a O:y/b A:x/e A:y/e &&
2273 test_cmp expect actual
2277 # Testcase 8c, modify/delete or rename+modify/delete?
2278 # (Related to testcases 5b, 8d, and 9h)
2279 # Commit O: z/{b,c,d}
2280 # Commit A: y/{b,c}
2281 # Commit B: z/{b,c,d_modified,e}
2282 # Expected: y/{b,c,e}, CONFLICT(modify/delete: on z/d)
2284 # Note: It could easily be argued that the correct resolution here is
2285 # y/{b,c,e}, CONFLICT(rename/delete: z/d -> y/d vs deleted)
2286 # and that the modified version of d should be present in y/ after
2287 # the merge, just marked as conflicted. Indeed, I previously did
2288 # argue that. But applying directory renames to the side of
2289 # history where a file is merely modified results in spurious
2290 # rename/rename(1to2) conflicts -- see testcase 9h. See also
2291 # notes in 8d.
2293 test_setup_8c () {
2294 git init 8c &&
2296 cd 8c &&
2298 mkdir z &&
2299 echo b >z/b &&
2300 echo c >z/c &&
2301 test_seq 1 10 >z/d &&
2302 git add z &&
2303 test_tick &&
2304 git commit -m "O" &&
2306 git branch O &&
2307 git branch A &&
2308 git branch B &&
2310 git checkout A &&
2311 git rm z/d &&
2312 git mv z y &&
2313 test_tick &&
2314 git commit -m "A" &&
2316 git checkout B &&
2317 echo 11 >z/d &&
2318 test_chmod +x z/d &&
2319 echo e >z/e &&
2320 git add z/d z/e &&
2321 test_tick &&
2322 git commit -m "B"
2326 test_expect_success '8c: modify/delete or rename+modify/delete' '
2327 test_setup_8c &&
2329 cd 8c &&
2331 git checkout A^0 &&
2333 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2334 test_grep "CONFLICT (modify/delete).* z/d" out &&
2336 git ls-files -s >out &&
2337 test_line_count = 5 out &&
2338 git ls-files -u >out &&
2339 test_line_count = 2 out &&
2340 git ls-files -o >out &&
2341 test_line_count = 1 out &&
2343 git rev-parse >actual \
2344 :0:y/b :0:y/c :0:y/e :1:z/d :3:z/d &&
2345 git rev-parse >expect \
2346 O:z/b O:z/c B:z/e O:z/d B:z/d &&
2347 test_cmp expect actual &&
2349 test_must_fail git rev-parse :2:z/d &&
2350 git ls-files -s z/d | grep ^100755 &&
2351 test_path_is_file z/d &&
2352 test_path_is_missing y/d
2356 # Testcase 8d, rename/delete...or not?
2357 # (Related to testcase 5b; these may appear slightly inconsistent to users;
2358 # Also related to testcases 7d and 7e)
2359 # Commit O: z/{b,c,d}
2360 # Commit A: y/{b,c}
2361 # Commit B: z/{b,c,d,e}
2362 # Expected: y/{b,c,e}
2364 # Note: It would also be somewhat reasonable to resolve this as
2365 # y/{b,c,e}, CONFLICT(rename/delete: x/d -> y/d or deleted)
2367 # In this case, I'm leaning towards: commit A was the one that deleted z/d
2368 # and it did the rename of z to y, so the two "conflicts" (rename vs.
2369 # delete) are both coming from commit A, which is illogical. Conflicts
2370 # during merging are supposed to be about opposite sides doing things
2371 # differently.
2373 test_setup_8d () {
2374 git init 8d &&
2376 cd 8d &&
2378 mkdir z &&
2379 echo b >z/b &&
2380 echo c >z/c &&
2381 test_seq 1 10 >z/d &&
2382 git add z &&
2383 test_tick &&
2384 git commit -m "O" &&
2386 git branch O &&
2387 git branch A &&
2388 git branch B &&
2390 git checkout A &&
2391 git rm z/d &&
2392 git mv z y &&
2393 test_tick &&
2394 git commit -m "A" &&
2396 git checkout B &&
2397 echo e >z/e &&
2398 git add z/e &&
2399 test_tick &&
2400 git commit -m "B"
2404 test_expect_success '8d: rename/delete...or not?' '
2405 test_setup_8d &&
2407 cd 8d &&
2409 git checkout A^0 &&
2411 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2413 git ls-files -s >out &&
2414 test_line_count = 3 out &&
2416 git rev-parse >actual \
2417 HEAD:y/b HEAD:y/c HEAD:y/e &&
2418 git rev-parse >expect \
2419 O:z/b O:z/c B:z/e &&
2420 test_cmp expect actual
2424 # Testcase 8e, Both sides rename, one side adds to original directory
2425 # Commit O: z/{b,c}
2426 # Commit A: y/{b,c}
2427 # Commit B: w/{b,c}, z/d
2429 # Possible Resolutions:
2430 # if z not considered renamed: z/d, CONFLICT(z/b -> y/b vs. w/b),
2431 # CONFLICT(z/c -> y/c vs. w/c)
2432 # if z->y rename considered: y/d, CONFLICT(z/b -> y/b vs. w/b),
2433 # CONFLICT(z/c -> y/c vs. w/c)
2434 # Optimal: ??
2436 # Notes: In commit A, directory z got renamed to y. In commit B, directory z
2437 # did NOT get renamed; the directory is still present; instead it is
2438 # considered to have just renamed a subset of paths in directory z
2439 # elsewhere. This is much like testcase 6b2 (where commit B moves all
2440 # the original paths out of z/ but opted to keep d within z/).
2442 # It was not clear in the past what should be done with this testcase;
2443 # in fact, I noted that I "just picked one" previously. However,
2444 # following the new logic for testcase 6b2, we should take the rename
2445 # and move z/d to y/d.
2447 # 6b1, 6b2, and this case are definitely somewhat fuzzy in terms of
2448 # whether they are optimal for end users, but (a) the default for
2449 # directory rename detection is to mark these all as conflicts
2450 # anyway, (b) it feels like this is less prone to higher order corner
2451 # case confusion, and (c) the current algorithm requires less global
2452 # knowledge (i.e. less coupling in the algorithm between renames done
2453 # on both sides) which thus means users are better able to predict
2454 # the behavior, and predict it without computing as many details.
2456 test_setup_8e () {
2457 git init 8e &&
2459 cd 8e &&
2461 mkdir z &&
2462 echo b >z/b &&
2463 echo c >z/c &&
2464 git add z &&
2465 test_tick &&
2466 git commit -m "O" &&
2468 git branch O &&
2469 git branch A &&
2470 git branch B &&
2472 git checkout A &&
2473 git mv z y &&
2474 test_tick &&
2475 git commit -m "A" &&
2477 git checkout B &&
2478 git mv z w &&
2479 mkdir z &&
2480 echo d >z/d &&
2481 git add z/d &&
2482 test_tick &&
2483 git commit -m "B"
2487 test_expect_success '8e: Both sides rename, one side adds to original directory' '
2488 test_setup_8e &&
2490 cd 8e &&
2492 git checkout A^0 &&
2494 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
2495 test_grep CONFLICT.*rename/rename.*z/c.*y/c.*w/c out &&
2496 test_grep CONFLICT.*rename/rename.*z/b.*y/b.*w/b out &&
2498 git ls-files -s >out &&
2499 test_line_count = 7 out &&
2500 git ls-files -u >out &&
2501 test_line_count = 6 out &&
2502 git ls-files -o >out &&
2503 test_line_count = 2 out &&
2505 git rev-parse >actual \
2506 :1:z/b :2:y/b :3:w/b :1:z/c :2:y/c :3:w/c :0:y/d &&
2507 git rev-parse >expect \
2508 O:z/b O:z/b O:z/b O:z/c O:z/c O:z/c B:z/d &&
2509 test_cmp expect actual &&
2511 git hash-object >actual \
2512 y/b w/b y/c w/c &&
2513 git rev-parse >expect \
2514 O:z/b O:z/b O:z/c O:z/c &&
2515 test_cmp expect actual &&
2517 test_path_is_missing z/b &&
2518 test_path_is_missing z/c
2522 ###########################################################################
2523 # SECTION 9: Other testcases
2525 # This section consists of miscellaneous testcases I thought of during
2526 # the implementation which round out the testing.
2527 ###########################################################################
2529 # Testcase 9a, Inner renamed directory within outer renamed directory
2530 # (Related to testcase 1f)
2531 # Commit O: z/{b,c,d/{e,f,g}}
2532 # Commit A: y/{b,c}, x/w/{e,f,g}
2533 # Commit B: z/{b,c,d/{e,f,g,h},i}
2534 # Expected: y/{b,c,i}, x/w/{e,f,g,h}
2535 # NOTE: The only reason this one is interesting is because when a directory
2536 # is split into multiple other directories, we determine by the weight
2537 # of which one had the most paths going to it. A naive implementation
2538 # of that could take the new file in commit B at z/i to x/w/i or x/i.
2540 test_setup_9a () {
2541 git init 9a &&
2543 cd 9a &&
2545 mkdir -p z/d &&
2546 echo b >z/b &&
2547 echo c >z/c &&
2548 echo e >z/d/e &&
2549 echo f >z/d/f &&
2550 echo g >z/d/g &&
2551 git add z &&
2552 test_tick &&
2553 git commit -m "O" &&
2555 git branch O &&
2556 git branch A &&
2557 git branch B &&
2559 git checkout A &&
2560 mkdir x &&
2561 git mv z/d x/w &&
2562 git mv z y &&
2563 test_tick &&
2564 git commit -m "A" &&
2566 git checkout B &&
2567 echo h >z/d/h &&
2568 echo i >z/i &&
2569 git add z &&
2570 test_tick &&
2571 git commit -m "B"
2575 test_expect_success '9a: Inner renamed directory within outer renamed directory' '
2576 test_setup_9a &&
2578 cd 9a &&
2580 git checkout A^0 &&
2582 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2584 git ls-files -s >out &&
2585 test_line_count = 7 out &&
2586 git ls-files -u >out &&
2587 test_line_count = 0 out &&
2588 git ls-files -o >out &&
2589 test_line_count = 1 out &&
2591 git rev-parse >actual \
2592 HEAD:y/b HEAD:y/c HEAD:y/i &&
2593 git rev-parse >expect \
2594 O:z/b O:z/c B:z/i &&
2595 test_cmp expect actual &&
2597 git rev-parse >actual \
2598 HEAD:x/w/e HEAD:x/w/f HEAD:x/w/g HEAD:x/w/h &&
2599 git rev-parse >expect \
2600 O:z/d/e O:z/d/f O:z/d/g B:z/d/h &&
2601 test_cmp expect actual
2605 # Testcase 9b, Transitive rename with content merge
2606 # (Related to testcase 1c)
2607 # Commit O: z/{b,c}, x/d_1
2608 # Commit A: y/{b,c}, x/d_2
2609 # Commit B: z/{b,c,d_3}
2610 # Expected: y/{b,c,d_merged}
2612 test_setup_9b () {
2613 git init 9b &&
2615 cd 9b &&
2617 mkdir z &&
2618 echo b >z/b &&
2619 echo c >z/c &&
2620 mkdir x &&
2621 test_seq 1 10 >x/d &&
2622 git add z x &&
2623 test_tick &&
2624 git commit -m "O" &&
2626 git branch O &&
2627 git branch A &&
2628 git branch B &&
2630 git checkout A &&
2631 git mv z y &&
2632 test_seq 1 11 >x/d &&
2633 git add x/d &&
2634 test_tick &&
2635 git commit -m "A" &&
2637 git checkout B &&
2638 test_seq 0 10 >x/d &&
2639 git mv x/d z/d &&
2640 git add z/d &&
2641 test_tick &&
2642 git commit -m "B"
2646 test_expect_success '9b: Transitive rename with content merge' '
2647 test_setup_9b &&
2649 cd 9b &&
2651 git checkout A^0 &&
2653 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2655 git ls-files -s >out &&
2656 test_line_count = 3 out &&
2658 test_seq 0 11 >expected &&
2659 test_cmp expected y/d &&
2660 git add expected &&
2661 git rev-parse >actual \
2662 HEAD:y/b HEAD:y/c HEAD:y/d &&
2663 git rev-parse >expect \
2664 O:z/b O:z/c :0:expected &&
2665 test_cmp expect actual &&
2666 test_must_fail git rev-parse HEAD:x/d &&
2667 test_must_fail git rev-parse HEAD:z/d &&
2668 test_path_is_missing z/d &&
2670 test $(git rev-parse HEAD:y/d) != $(git rev-parse O:x/d) &&
2671 test $(git rev-parse HEAD:y/d) != $(git rev-parse A:x/d) &&
2672 test $(git rev-parse HEAD:y/d) != $(git rev-parse B:z/d)
2676 # Testcase 9c, Doubly transitive rename?
2677 # (Related to testcase 1c, 7e, and 9d)
2678 # Commit O: z/{b,c}, x/{d,e}, w/f
2679 # Commit A: y/{b,c}, x/{d,e,f,g}
2680 # Commit B: z/{b,c,d,e}, w/f
2681 # Expected: y/{b,c,d,e}, x/{f,g}
2683 # NOTE: x/f and x/g may be slightly confusing here. The rename from w/f to
2684 # x/f is clear. Let's look beyond that. Here's the logic:
2685 # Commit B renamed x/ -> z/
2686 # Commit A renamed z/ -> y/
2687 # So, we could possibly further rename x/f to z/f to y/f, a doubly
2688 # transient rename. However, where does it end? We can chain these
2689 # indefinitely (see testcase 9d). What if there is a D/F conflict
2690 # at z/f/ or y/f/? Or just another file conflict at one of those
2691 # paths? In the case of an N-long chain of transient renamings,
2692 # where do we "abort" the rename at? Can the user make sense of
2693 # the resulting conflict and resolve it?
2695 # To avoid this confusion I use the simple rule that if the other side
2696 # of history did a directory rename to a path that your side renamed
2697 # away, then ignore that particular rename from the other side of
2698 # history for any implicit directory renames.
2700 test_setup_9c () {
2701 git init 9c &&
2703 cd 9c &&
2705 mkdir z &&
2706 echo b >z/b &&
2707 echo c >z/c &&
2708 mkdir x &&
2709 echo d >x/d &&
2710 echo e >x/e &&
2711 mkdir w &&
2712 echo f >w/f &&
2713 git add z x w &&
2714 test_tick &&
2715 git commit -m "O" &&
2717 git branch O &&
2718 git branch A &&
2719 git branch B &&
2721 git checkout A &&
2722 git mv z y &&
2723 git mv w/f x/ &&
2724 echo g >x/g &&
2725 git add x/g &&
2726 test_tick &&
2727 git commit -m "A" &&
2729 git checkout B &&
2730 git mv x/d z/d &&
2731 git mv x/e z/e &&
2732 test_tick &&
2733 git commit -m "B"
2737 test_expect_success '9c: Doubly transitive rename?' '
2738 test_setup_9c &&
2740 cd 9c &&
2742 git checkout A^0 &&
2744 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2745 test_grep "WARNING: Avoiding applying x -> z rename to x/f" out &&
2747 git ls-files -s >out &&
2748 test_line_count = 6 out &&
2749 git ls-files -o >out &&
2750 test_line_count = 1 out &&
2752 git rev-parse >actual \
2753 HEAD:y/b HEAD:y/c HEAD:y/d HEAD:y/e HEAD:x/f HEAD:x/g &&
2754 git rev-parse >expect \
2755 O:z/b O:z/c O:x/d O:x/e O:w/f A:x/g &&
2756 test_cmp expect actual
2760 # Testcase 9d, N-fold transitive rename?
2761 # (Related to testcase 9c...and 1c and 7e)
2762 # Commit O: z/a, y/b, x/c, w/d, v/e, u/f
2763 # Commit A: y/{a,b}, w/{c,d}, u/{e,f}
2764 # Commit B: z/{a,t}, x/{b,c}, v/{d,e}, u/f
2765 # Expected: <see NOTE first>
2767 # NOTE: z/ -> y/ (in commit A)
2768 # y/ -> x/ (in commit B)
2769 # x/ -> w/ (in commit A)
2770 # w/ -> v/ (in commit B)
2771 # v/ -> u/ (in commit A)
2772 # So, if we add a file to z, say z/t, where should it end up? In u?
2773 # What if there's another file or directory named 't' in one of the
2774 # intervening directories and/or in u itself? Also, shouldn't the
2775 # same logic that places 't' in u/ also move ALL other files to u/?
2776 # What if there are file or directory conflicts in any of them? If
2777 # we attempted to do N-way (N-fold? N-ary? N-uple?) transitive renames
2778 # like this, would the user have any hope of understanding any
2779 # conflicts or how their working tree ended up? I think not, so I'm
2780 # ruling out N-ary transitive renames for N>1.
2782 # Therefore our expected result is:
2783 # z/t, y/a, x/b, w/c, u/d, u/e, u/f
2784 # The reason that v/d DOES get transitively renamed to u/d is that u/ isn't
2785 # renamed somewhere. A slightly sub-optimal result, but it uses fairly
2786 # simple rules that are consistent with what we need for all the other
2787 # testcases and simplifies things for the user.
2789 test_setup_9d () {
2790 git init 9d &&
2792 cd 9d &&
2794 mkdir z y x w v u &&
2795 echo a >z/a &&
2796 echo b >y/b &&
2797 echo c >x/c &&
2798 echo d >w/d &&
2799 echo e >v/e &&
2800 echo f >u/f &&
2801 git add z y x w v u &&
2802 test_tick &&
2803 git commit -m "O" &&
2805 git branch O &&
2806 git branch A &&
2807 git branch B &&
2809 git checkout A &&
2810 git mv z/a y/ &&
2811 git mv x/c w/ &&
2812 git mv v/e u/ &&
2813 test_tick &&
2814 git commit -m "A" &&
2816 git checkout B &&
2817 echo t >z/t &&
2818 git mv y/b x/ &&
2819 git mv w/d v/ &&
2820 git add z/t &&
2821 test_tick &&
2822 git commit -m "B"
2826 test_expect_success '9d: N-way transitive rename?' '
2827 test_setup_9d &&
2829 cd 9d &&
2831 git checkout A^0 &&
2833 git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2834 test_grep "WARNING: Avoiding applying z -> y rename to z/t" out &&
2835 test_grep "WARNING: Avoiding applying y -> x rename to y/a" out &&
2836 test_grep "WARNING: Avoiding applying x -> w rename to x/b" out &&
2837 test_grep "WARNING: Avoiding applying w -> v rename to w/c" out &&
2839 git ls-files -s >out &&
2840 test_line_count = 7 out &&
2841 git ls-files -o >out &&
2842 test_line_count = 1 out &&
2844 git rev-parse >actual \
2845 HEAD:z/t \
2846 HEAD:y/a HEAD:x/b HEAD:w/c \
2847 HEAD:u/d HEAD:u/e HEAD:u/f &&
2848 git rev-parse >expect \
2849 B:z/t \
2850 O:z/a O:y/b O:x/c \
2851 O:w/d O:v/e A:u/f &&
2852 test_cmp expect actual
2856 # Testcase 9e, N-to-1 whammo
2857 # (Related to testcase 9c...and 1c and 7e)
2858 # Commit O: dir1/{a,b}, dir2/{d,e}, dir3/{g,h}, dirN/{j,k}
2859 # Commit A: dir1/{a,b,c,yo}, dir2/{d,e,f,yo}, dir3/{g,h,i,yo}, dirN/{j,k,l,yo}
2860 # Commit B: combined/{a,b,d,e,g,h,j,k}
2861 # Expected: combined/{a,b,c,d,e,f,g,h,i,j,k,l}, CONFLICT(Nto1) warnings,
2862 # dir1/yo, dir2/yo, dir3/yo, dirN/yo
2864 test_setup_9e () {
2865 git init 9e &&
2867 cd 9e &&
2869 mkdir dir1 dir2 dir3 dirN &&
2870 echo a >dir1/a &&
2871 echo b >dir1/b &&
2872 echo d >dir2/d &&
2873 echo e >dir2/e &&
2874 echo g >dir3/g &&
2875 echo h >dir3/h &&
2876 echo j >dirN/j &&
2877 echo k >dirN/k &&
2878 git add dir* &&
2879 test_tick &&
2880 git commit -m "O" &&
2882 git branch O &&
2883 git branch A &&
2884 git branch B &&
2886 git checkout A &&
2887 echo c >dir1/c &&
2888 echo yo >dir1/yo &&
2889 echo f >dir2/f &&
2890 echo yo >dir2/yo &&
2891 echo i >dir3/i &&
2892 echo yo >dir3/yo &&
2893 echo l >dirN/l &&
2894 echo yo >dirN/yo &&
2895 git add dir* &&
2896 test_tick &&
2897 git commit -m "A" &&
2899 git checkout B &&
2900 git mv dir1 combined &&
2901 git mv dir2/* combined/ &&
2902 git mv dir3/* combined/ &&
2903 git mv dirN/* combined/ &&
2904 test_tick &&
2905 git commit -m "B"
2909 test_expect_success '9e: N-to-1 whammo' '
2910 test_setup_9e &&
2912 cd 9e &&
2914 git checkout A^0 &&
2916 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out &&
2917 grep "CONFLICT (implicit dir rename): Cannot map more than one path to combined/yo" out >error_line &&
2918 grep -q dir1/yo error_line &&
2919 grep -q dir2/yo error_line &&
2920 grep -q dir3/yo error_line &&
2921 grep -q dirN/yo error_line &&
2923 git ls-files -s >out &&
2924 test_line_count = 16 out &&
2925 git ls-files -u >out &&
2926 test_line_count = 0 out &&
2927 git ls-files -o >out &&
2928 test_line_count = 2 out &&
2930 git rev-parse >actual \
2931 :0:combined/a :0:combined/b :0:combined/c \
2932 :0:combined/d :0:combined/e :0:combined/f \
2933 :0:combined/g :0:combined/h :0:combined/i \
2934 :0:combined/j :0:combined/k :0:combined/l &&
2935 git rev-parse >expect \
2936 O:dir1/a O:dir1/b A:dir1/c \
2937 O:dir2/d O:dir2/e A:dir2/f \
2938 O:dir3/g O:dir3/h A:dir3/i \
2939 O:dirN/j O:dirN/k A:dirN/l &&
2940 test_cmp expect actual &&
2942 git rev-parse >actual \
2943 :0:dir1/yo :0:dir2/yo :0:dir3/yo :0:dirN/yo &&
2944 git rev-parse >expect \
2945 A:dir1/yo A:dir2/yo A:dir3/yo A:dirN/yo &&
2946 test_cmp expect actual
2950 # Testcase 9f, Renamed directory that only contained immediate subdirs
2951 # (Related to testcases 1e & 9g)
2952 # Commit O: goal/{a,b}/$more_files
2953 # Commit A: priority/{a,b}/$more_files
2954 # Commit B: goal/{a,b}/$more_files, goal/c
2955 # Expected: priority/{a,b}/$more_files, priority/c
2957 test_setup_9f () {
2958 git init 9f &&
2960 cd 9f &&
2962 mkdir -p goal/a &&
2963 mkdir -p goal/b &&
2964 echo foo >goal/a/foo &&
2965 echo bar >goal/b/bar &&
2966 echo baz >goal/b/baz &&
2967 git add goal &&
2968 test_tick &&
2969 git commit -m "O" &&
2971 git branch O &&
2972 git branch A &&
2973 git branch B &&
2975 git checkout A &&
2976 git mv goal/ priority &&
2977 test_tick &&
2978 git commit -m "A" &&
2980 git checkout B &&
2981 echo c >goal/c &&
2982 git add goal/c &&
2983 test_tick &&
2984 git commit -m "B"
2988 test_expect_success '9f: Renamed directory that only contained immediate subdirs' '
2989 test_setup_9f &&
2991 cd 9f &&
2993 git checkout A^0 &&
2995 git -c merge.directoryRenames=true merge -s recursive B^0 &&
2997 git ls-files -s >out &&
2998 test_line_count = 4 out &&
3000 git rev-parse >actual \
3001 HEAD:priority/a/foo \
3002 HEAD:priority/b/bar \
3003 HEAD:priority/b/baz \
3004 HEAD:priority/c &&
3005 git rev-parse >expect \
3006 O:goal/a/foo \
3007 O:goal/b/bar \
3008 O:goal/b/baz \
3009 B:goal/c &&
3010 test_cmp expect actual &&
3011 test_must_fail git rev-parse HEAD:goal/c
3015 # Testcase 9g, Renamed directory that only contained immediate subdirs, immediate subdirs renamed
3016 # (Related to testcases 1e & 9f)
3017 # Commit O: goal/{a,b}/$more_files
3018 # Commit A: priority/{alpha,bravo}/$more_files
3019 # Commit B: goal/{a,b}/$more_files, goal/c
3020 # Expected: priority/{alpha,bravo}/$more_files, priority/c
3021 # We currently fail this test because the directory renames we detect are
3022 # goal/a/ -> priority/alpha/
3023 # goal/b/ -> priority/bravo/
3024 # We do not detect
3025 # goal/ -> priority/
3026 # because of no files found within goal/, and the fact that "a" != "alpha"
3027 # and "b" != "bravo". But I'm not sure it's really a failure given that
3028 # viewpoint...
3030 test_setup_9g () {
3031 git init 9g &&
3033 cd 9g &&
3035 mkdir -p goal/a &&
3036 mkdir -p goal/b &&
3037 echo foo >goal/a/foo &&
3038 echo bar >goal/b/bar &&
3039 echo baz >goal/b/baz &&
3040 git add goal &&
3041 test_tick &&
3042 git commit -m "O" &&
3044 git branch O &&
3045 git branch A &&
3046 git branch B &&
3048 git checkout A &&
3049 mkdir priority &&
3050 git mv goal/a/ priority/alpha &&
3051 git mv goal/b/ priority/beta &&
3052 rmdir goal/ &&
3053 test_tick &&
3054 git commit -m "A" &&
3056 git checkout B &&
3057 echo c >goal/c &&
3058 git add goal/c &&
3059 test_tick &&
3060 git commit -m "B"
3064 test_expect_failure '9g: Renamed directory that only contained immediate subdirs, immediate subdirs renamed' '
3065 test_setup_9g &&
3067 cd 9g &&
3069 git checkout A^0 &&
3071 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3073 git ls-files -s >out &&
3074 test_line_count = 4 out &&
3076 git rev-parse >actual \
3077 HEAD:priority/alpha/foo \
3078 HEAD:priority/beta/bar \
3079 HEAD:priority/beta/baz \
3080 HEAD:priority/c &&
3081 git rev-parse >expect \
3082 O:goal/a/foo \
3083 O:goal/b/bar \
3084 O:goal/b/baz \
3085 B:goal/c &&
3086 test_cmp expect actual &&
3087 test_must_fail git rev-parse HEAD:goal/c
3091 # Testcase 9h, Avoid implicit rename if involved as source on other side
3092 # (Extremely closely related to testcase 3a)
3093 # Commit O: z/{b,c,d_1}
3094 # Commit A: z/{b,c,d_2}
3095 # Commit B: y/{b,c}, x/d_1
3096 # Expected: y/{b,c}, x/d_2
3097 # NOTE: If we applied the z/ -> y/ rename to z/d, then we'd end up with
3098 # a rename/rename(1to2) conflict (z/d -> y/d vs. x/d)
3099 test_setup_9h () {
3100 git init 9h &&
3102 cd 9h &&
3104 mkdir z &&
3105 echo b >z/b &&
3106 echo c >z/c &&
3107 printf "1\n2\n3\n4\n5\n6\n7\n8\nd\n" >z/d &&
3108 git add z &&
3109 test_tick &&
3110 git commit -m "O" &&
3112 git branch O &&
3113 git branch A &&
3114 git branch B &&
3116 git checkout A &&
3117 test_tick &&
3118 echo more >>z/d &&
3119 git add z/d &&
3120 git commit -m "A" &&
3122 git checkout B &&
3123 mkdir y &&
3124 mkdir x &&
3125 git mv z/b y/ &&
3126 git mv z/c y/ &&
3127 git mv z/d x/ &&
3128 rmdir z &&
3129 test_tick &&
3130 git commit -m "B"
3134 test_expect_success '9h: Avoid dir rename on merely modified path' '
3135 test_setup_9h &&
3137 cd 9h &&
3139 git checkout A^0 &&
3141 git -c merge.directoryRenames=true merge -s recursive B^0 &&
3143 git ls-files -s >out &&
3144 test_line_count = 3 out &&
3146 git rev-parse >actual \
3147 HEAD:y/b HEAD:y/c HEAD:x/d &&
3148 git rev-parse >expect \
3149 O:z/b O:z/c A:z/d &&
3150 test_cmp expect actual
3154 ###########################################################################
3155 # Rules suggested by section 9:
3157 # If the other side of history did a directory rename to a path that your
3158 # side renamed away, then ignore that particular rename from the other
3159 # side of history for any implicit directory renames.
3160 ###########################################################################
3162 ###########################################################################
3163 # SECTION 10: Handling untracked files
3165 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3166 # the operation if untracked or dirty files would be deleted or overwritten
3167 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3168 # and if it doesn't abort, then it muddies up the working directory before
3169 # we even get to the point of detecting renames, so we need some special
3170 # handling, at least in the case of directory renames.
3171 ###########################################################################
3173 # Testcase 10a, Overwrite untracked: normal rename/delete
3174 # Commit O: z/{b,c_1}
3175 # Commit A: z/b + untracked z/c + untracked z/d
3176 # Commit B: z/{b,d_1}
3177 # Expected: Aborted Merge +
3178 # ERROR_MSG(untracked working tree files would be overwritten by merge)
3180 test_setup_10a () {
3181 git init 10a &&
3183 cd 10a &&
3185 mkdir z &&
3186 echo b >z/b &&
3187 echo c >z/c &&
3188 git add z &&
3189 test_tick &&
3190 git commit -m "O" &&
3192 git branch O &&
3193 git branch A &&
3194 git branch B &&
3196 git checkout A &&
3197 git rm z/c &&
3198 test_tick &&
3199 git commit -m "A" &&
3201 git checkout B &&
3202 git mv z/c z/d &&
3203 test_tick &&
3204 git commit -m "B"
3208 test_expect_success '10a: Overwrite untracked with normal rename/delete' '
3209 test_setup_10a &&
3211 cd 10a &&
3213 git checkout A^0 &&
3214 echo very >z/c &&
3215 echo important >z/d &&
3217 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3218 test_path_is_missing .git/MERGE_HEAD &&
3219 test_grep "The following untracked working tree files would be overwritten by merge" err &&
3221 git ls-files -s >out &&
3222 test_line_count = 1 out &&
3223 git ls-files -o >out &&
3224 test_line_count = 4 out &&
3226 echo very >expect &&
3227 test_cmp expect z/c &&
3229 echo important >expect &&
3230 test_cmp expect z/d &&
3232 git rev-parse HEAD:z/b >actual &&
3233 git rev-parse O:z/b >expect &&
3234 test_cmp expect actual
3238 # Testcase 10b, Overwrite untracked: dir rename + delete
3239 # Commit O: z/{b,c_1}
3240 # Commit A: y/b + untracked y/{c,d,e}
3241 # Commit B: z/{b,d_1,e}
3242 # Expected: Failed Merge; y/b + untracked y/c + untracked y/d on disk +
3243 # z/c_1 -> z/d_1 rename recorded at stage 3 for y/d +
3244 # ERROR_MSG(refusing to lose untracked file at 'y/d')
3246 test_setup_10b () {
3247 git init 10b &&
3249 cd 10b &&
3251 mkdir z &&
3252 echo b >z/b &&
3253 echo c >z/c &&
3254 git add z &&
3255 test_tick &&
3256 git commit -m "O" &&
3258 git branch O &&
3259 git branch A &&
3260 git branch B &&
3262 git checkout A &&
3263 git rm z/c &&
3264 git mv z/ y/ &&
3265 test_tick &&
3266 git commit -m "A" &&
3268 git checkout B &&
3269 git mv z/c z/d &&
3270 echo e >z/e &&
3271 git add z/e &&
3272 test_tick &&
3273 git commit -m "B"
3277 test_expect_success '10b: Overwrite untracked with dir rename + delete' '
3278 test_setup_10b &&
3280 cd 10b &&
3282 git checkout A^0 &&
3283 echo very >y/c &&
3284 echo important >y/d &&
3285 echo contents >y/e &&
3287 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3288 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3289 then
3290 test_path_is_missing .git/MERGE_HEAD &&
3291 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3293 git ls-files -s >out &&
3294 test_line_count = 1 out &&
3295 git ls-files -u >out &&
3296 test_line_count = 0 out &&
3297 git ls-files -o >out &&
3298 test_line_count = 5 out
3299 else
3300 test_grep "CONFLICT (rename/delete).*Version B\^0 of y/d left in tree at y/d~B\^0" out &&
3301 test_grep "Error: Refusing to lose untracked file at y/e; writing to y/e~B\^0 instead" out &&
3303 git ls-files -s >out &&
3304 test_line_count = 3 out &&
3305 git ls-files -u >out &&
3306 test_line_count = 2 out &&
3307 git ls-files -o >out &&
3308 test_line_count = 5 out &&
3310 git rev-parse >actual \
3311 :0:y/b :3:y/d :3:y/e &&
3312 git rev-parse >expect \
3313 O:z/b O:z/c B:z/e &&
3314 test_cmp expect actual
3315 fi &&
3317 echo very >expect &&
3318 test_cmp expect y/c &&
3320 echo important >expect &&
3321 test_cmp expect y/d &&
3323 echo contents >expect &&
3324 test_cmp expect y/e
3328 # Testcase 10c, Overwrite untracked: dir rename/rename(1to2)
3329 # Commit O: z/{a,b}, x/{c,d}
3330 # Commit A: y/{a,b}, w/c, x/d + different untracked y/c
3331 # Commit B: z/{a,b,c}, x/d
3332 # Expected: Failed Merge; y/{a,b} + x/d + untracked y/c +
3333 # CONFLICT(rename/rename) x/c -> w/c vs y/c +
3334 # y/c~B^0 +
3335 # ERROR_MSG(Refusing to lose untracked file at y/c)
3337 test_setup_10c () {
3338 git init 10c_$1 &&
3340 cd 10c_$1 &&
3342 mkdir z x &&
3343 echo a >z/a &&
3344 echo b >z/b &&
3345 echo c >x/c &&
3346 echo d >x/d &&
3347 git add z x &&
3348 test_tick &&
3349 git commit -m "O" &&
3351 git branch O &&
3352 git branch A &&
3353 git branch B &&
3355 git checkout A &&
3356 mkdir w &&
3357 git mv x/c w/c &&
3358 git mv z/ y/ &&
3359 test_tick &&
3360 git commit -m "A" &&
3362 git checkout B &&
3363 git mv x/c z/ &&
3364 test_tick &&
3365 git commit -m "B"
3369 test_expect_success '10c1: Overwrite untracked with dir rename/rename(1to2)' '
3370 test_setup_10c 1 &&
3372 cd 10c_1 &&
3374 git checkout A^0 &&
3375 echo important >y/c &&
3377 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3378 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3379 then
3380 test_path_is_missing .git/MERGE_HEAD &&
3381 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3383 git ls-files -s >out &&
3384 test_line_count = 4 out &&
3385 git ls-files -u >out &&
3386 test_line_count = 0 out &&
3387 git ls-files -o >out &&
3388 test_line_count = 3 out
3389 else
3390 test_grep "CONFLICT (rename/rename)" out &&
3391 test_grep "Refusing to lose untracked file at y/c; adding as y/c~B\^0 instead" out &&
3393 git ls-files -s >out &&
3394 test_line_count = 6 out &&
3395 git ls-files -u >out &&
3396 test_line_count = 3 out &&
3397 git ls-files -o >out &&
3398 test_line_count = 3 out &&
3400 git rev-parse >actual \
3401 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :3:y/c &&
3402 git rev-parse >expect \
3403 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3404 test_cmp expect actual &&
3406 git hash-object y/c~B^0 >actual &&
3407 git rev-parse O:x/c >expect &&
3408 test_cmp expect actual
3409 fi &&
3411 echo important >expect &&
3412 test_cmp expect y/c
3416 test_expect_success '10c2: Overwrite untracked with dir rename/rename(1to2), other direction' '
3417 test_setup_10c 2 &&
3419 cd 10c_2 &&
3421 git reset --hard &&
3422 git clean -fdqx &&
3424 git checkout B^0 &&
3425 mkdir y &&
3426 echo important >y/c &&
3428 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 >out 2>err &&
3429 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3430 then
3431 test_path_is_missing .git/MERGE_HEAD &&
3432 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3434 git ls-files -s >out &&
3435 test_line_count = 4 out &&
3436 git ls-files -u >out &&
3437 test_line_count = 0 out &&
3438 git ls-files -o >out &&
3439 test_line_count = 3 out
3440 else
3441 test_grep "CONFLICT (rename/rename)" out &&
3442 test_grep "Refusing to lose untracked file at y/c; adding as y/c~HEAD instead" out &&
3444 git ls-files -s >out &&
3445 test_line_count = 6 out &&
3446 git ls-files -u >out &&
3447 test_line_count = 3 out &&
3448 git ls-files -o >out &&
3449 test_line_count = 3 out &&
3451 git rev-parse >actual \
3452 :0:y/a :0:y/b :0:x/d :1:x/c :3:w/c :2:y/c &&
3453 git rev-parse >expect \
3454 O:z/a O:z/b O:x/d O:x/c O:x/c O:x/c &&
3455 test_cmp expect actual &&
3457 git hash-object y/c~HEAD >actual &&
3458 git rev-parse O:x/c >expect &&
3459 test_cmp expect actual
3460 fi &&
3462 echo important >expect &&
3463 test_cmp expect y/c
3467 # Testcase 10d, Delete untracked w/ dir rename/rename(2to1)
3468 # Commit O: z/{a,b,c_1}, x/{d,e,f_2}
3469 # Commit A: y/{a,b}, x/{d,e,f_2,wham_1} + untracked y/wham
3470 # Commit B: z/{a,b,c_1,wham_2}, y/{d,e}
3471 # Expected: Failed Merge; y/{a,b,d,e} + untracked y/{wham,wham~merged}+
3472 # CONFLICT(rename/rename) z/c_1 vs x/f_2 -> y/wham
3473 # ERROR_MSG(Refusing to lose untracked file at y/wham)
3475 test_setup_10d () {
3476 git init 10d &&
3478 cd 10d &&
3480 mkdir z x &&
3481 echo a >z/a &&
3482 echo b >z/b &&
3483 echo c >z/c &&
3484 echo d >x/d &&
3485 echo e >x/e &&
3486 echo f >x/f &&
3487 git add z x &&
3488 test_tick &&
3489 git commit -m "O" &&
3491 git branch O &&
3492 git branch A &&
3493 git branch B &&
3495 git checkout A &&
3496 git mv z/c x/wham &&
3497 git mv z/ y/ &&
3498 test_tick &&
3499 git commit -m "A" &&
3501 git checkout B &&
3502 git mv x/f z/wham &&
3503 git mv x/ y/ &&
3504 test_tick &&
3505 git commit -m "B"
3509 test_expect_success '10d: Delete untracked with dir rename/rename(2to1)' '
3510 test_setup_10d &&
3512 cd 10d &&
3514 git checkout A^0 &&
3515 echo important >y/wham &&
3517 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3518 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3519 then
3520 test_path_is_missing .git/MERGE_HEAD &&
3521 test_grep "error: The following untracked working tree files would be overwritten by merge" err &&
3523 git ls-files -s >out &&
3524 test_line_count = 6 out &&
3525 git ls-files -u >out &&
3526 test_line_count = 0 out &&
3527 git ls-files -o >out &&
3528 test_line_count = 3 out
3529 else
3530 test_grep "CONFLICT (rename/rename)" out &&
3531 test_grep "Refusing to lose untracked file at y/wham" out &&
3533 git ls-files -s >out &&
3534 test_line_count = 6 out &&
3535 git ls-files -u >out &&
3536 test_line_count = 2 out &&
3537 git ls-files -o >out &&
3538 test_line_count = 3 out &&
3540 git rev-parse >actual \
3541 :0:y/a :0:y/b :0:y/d :0:y/e :2:y/wham :3:y/wham &&
3542 git rev-parse >expect \
3543 O:z/a O:z/b O:x/d O:x/e O:z/c O:x/f &&
3544 test_cmp expect actual &&
3546 test_must_fail git rev-parse :1:y/wham &&
3548 # Test that two-way merge in y/wham~merged is as expected
3549 git cat-file -p :2:y/wham >expect &&
3550 git cat-file -p :3:y/wham >other &&
3551 >empty &&
3552 test_must_fail git merge-file \
3553 -L "HEAD" \
3554 -L "" \
3555 -L "B^0" \
3556 expect empty other &&
3557 test_cmp expect y/wham~merged
3558 fi &&
3560 echo important >expect &&
3561 test_cmp expect y/wham
3565 # Testcase 10e, Does git complain about untracked file that's not in the way?
3566 # Commit O: z/{a,b}
3567 # Commit A: y/{a,b} + untracked z/c
3568 # Commit B: z/{a,b,c}
3569 # Expected: y/{a,b,c} + untracked z/c
3571 test_setup_10e () {
3572 git init 10e &&
3574 cd 10e &&
3576 mkdir z &&
3577 echo a >z/a &&
3578 echo b >z/b &&
3579 git add z &&
3580 test_tick &&
3581 git commit -m "O" &&
3583 git branch O &&
3584 git branch A &&
3585 git branch B &&
3587 git checkout A &&
3588 git mv z/ y/ &&
3589 test_tick &&
3590 git commit -m "A" &&
3592 git checkout B &&
3593 echo c >z/c &&
3594 git add z/c &&
3595 test_tick &&
3596 git commit -m "B"
3600 test_expect_merge_algorithm failure success '10e: Does git complain about untracked file that is not really in the way?' '
3601 test_setup_10e &&
3603 cd 10e &&
3605 git checkout A^0 &&
3606 mkdir z &&
3607 echo random >z/c &&
3609 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3610 test_grep ! "following untracked working tree files would be overwritten by merge" err &&
3612 git ls-files -s >out &&
3613 test_line_count = 3 out &&
3614 git ls-files -u >out &&
3615 test_line_count = 0 out &&
3616 git ls-files -o >out &&
3617 test_line_count = 3 out &&
3619 git rev-parse >actual \
3620 :0:y/a :0:y/b :0:y/c &&
3621 git rev-parse >expect \
3622 O:z/a O:z/b B:z/c &&
3623 test_cmp expect actual &&
3625 echo random >expect &&
3626 test_cmp expect z/c
3630 ###########################################################################
3631 # SECTION 11: Handling dirty (not up-to-date) files
3633 # unpack_trees(), upon which the recursive merge algorithm is based, aborts
3634 # the operation if untracked or dirty files would be deleted or overwritten
3635 # by the merge. Unfortunately, unpack_trees() does not understand renames,
3636 # and if it doesn't abort, then it muddies up the working directory before
3637 # we even get to the point of detecting renames, so we need some special
3638 # handling. This was true even of normal renames, but there are additional
3639 # codepaths that need special handling with directory renames. Add
3640 # testcases for both renamed-by-directory-rename-detection and standard
3641 # rename cases.
3642 ###########################################################################
3644 # Testcase 11a, Avoid losing dirty contents with simple rename
3645 # Commit O: z/{a,b_v1},
3646 # Commit A: z/{a,c_v1}, and z/c_v1 has uncommitted mods
3647 # Commit B: z/{a,b_v2}
3648 # Expected: ERROR_MSG(Refusing to lose dirty file at z/c) +
3649 # z/a, staged version of z/c has sha1sum matching B:z/b_v2,
3650 # z/c~HEAD with contents of B:z/b_v2,
3651 # z/c with uncommitted mods on top of A:z/c_v1
3653 test_setup_11a () {
3654 git init 11a &&
3656 cd 11a &&
3658 mkdir z &&
3659 echo a >z/a &&
3660 test_seq 1 10 >z/b &&
3661 git add z &&
3662 test_tick &&
3663 git commit -m "O" &&
3665 git branch O &&
3666 git branch A &&
3667 git branch B &&
3669 git checkout A &&
3670 git mv z/b z/c &&
3671 test_tick &&
3672 git commit -m "A" &&
3674 git checkout B &&
3675 echo 11 >>z/b &&
3676 git add z/b &&
3677 test_tick &&
3678 git commit -m "B"
3682 test_expect_success '11a: Avoid losing dirty contents with simple rename' '
3683 test_setup_11a &&
3685 cd 11a &&
3687 git checkout A^0 &&
3688 echo stuff >>z/c &&
3690 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3691 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3692 then
3693 test_path_is_missing .git/MERGE_HEAD &&
3694 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3695 else
3696 test_grep "Refusing to lose dirty file at z/c" out &&
3698 git ls-files -s >out &&
3699 test_line_count = 2 out &&
3700 git ls-files -u >out &&
3701 test_line_count = 1 out &&
3702 git ls-files -o >out &&
3703 test_line_count = 3 out &&
3705 git rev-parse >actual \
3706 :0:z/a :2:z/c &&
3707 git rev-parse >expect \
3708 O:z/a B:z/b &&
3709 test_cmp expect actual &&
3711 git hash-object z/c~HEAD >actual &&
3712 git rev-parse B:z/b >expect &&
3713 test_cmp expect actual
3714 fi &&
3716 test_seq 1 10 >expected &&
3717 echo stuff >>expected &&
3718 test_cmp expected z/c
3723 # Testcase 11b, Avoid losing dirty file involved in directory rename
3724 # Commit O: z/a, x/{b,c_v1}
3725 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3726 # Commit B: y/a, x/{b,c_v2}
3727 # Expected: y/{a,c_v2}, x/b, z/c_v1 with uncommitted mods untracked,
3728 # ERROR_MSG(Refusing to lose dirty file at z/c)
3731 test_setup_11b () {
3732 git init 11b &&
3734 cd 11b &&
3736 mkdir z x &&
3737 echo a >z/a &&
3738 echo b >x/b &&
3739 test_seq 1 10 >x/c &&
3740 git add z x &&
3741 test_tick &&
3742 git commit -m "O" &&
3744 git branch O &&
3745 git branch A &&
3746 git branch B &&
3748 git checkout A &&
3749 git mv x/c z/c &&
3750 test_tick &&
3751 git commit -m "A" &&
3753 git checkout B &&
3754 git mv z y &&
3755 echo 11 >>x/c &&
3756 git add x/c &&
3757 test_tick &&
3758 git commit -m "B"
3762 test_expect_success '11b: Avoid losing dirty file involved in directory rename' '
3763 test_setup_11b &&
3765 cd 11b &&
3767 git checkout A^0 &&
3768 echo stuff >>z/c &&
3770 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3771 then
3772 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3773 test_path_is_missing .git/MERGE_HEAD &&
3774 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3775 else
3776 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3777 test_grep "Refusing to lose dirty file at z/c" out &&
3779 git ls-files -s >out &&
3780 test_line_count = 3 out &&
3781 git ls-files -u >out &&
3782 test_line_count = 0 out &&
3783 git ls-files -m >out &&
3784 test_line_count = 0 out &&
3785 git ls-files -o >out &&
3786 test_line_count = 3 out &&
3788 git rev-parse >actual \
3789 :0:x/b :0:y/a :0:y/c &&
3790 git rev-parse >expect \
3791 O:x/b O:z/a B:x/c &&
3792 test_cmp expect actual &&
3794 git hash-object y/c >actual &&
3795 git rev-parse B:x/c >expect &&
3796 test_cmp expect actual
3797 fi &&
3799 grep -q stuff z/c &&
3800 test_seq 1 10 >expected &&
3801 echo stuff >>expected &&
3802 test_cmp expected z/c
3806 # Testcase 11c, Avoid losing not-up-to-date with rename + D/F conflict
3807 # Commit O: y/a, x/{b,c_v1}
3808 # Commit A: y/{a,c_v1}, x/b, and y/c_v1 has uncommitted mods
3809 # Commit B: y/{a,c/d}, x/{b,c_v2}
3810 # Expected: Abort_msg("following files would be overwritten by merge") +
3811 # y/c left untouched (still has uncommitted mods)
3813 test_setup_11c () {
3814 git init 11c &&
3816 cd 11c &&
3818 mkdir y x &&
3819 echo a >y/a &&
3820 echo b >x/b &&
3821 test_seq 1 10 >x/c &&
3822 git add y x &&
3823 test_tick &&
3824 git commit -m "O" &&
3826 git branch O &&
3827 git branch A &&
3828 git branch B &&
3830 git checkout A &&
3831 git mv x/c y/c &&
3832 test_tick &&
3833 git commit -m "A" &&
3835 git checkout B &&
3836 mkdir y/c &&
3837 echo d >y/c/d &&
3838 echo 11 >>x/c &&
3839 git add x/c y/c/d &&
3840 test_tick &&
3841 git commit -m "B"
3845 test_expect_success '11c: Avoid losing not-uptodate with rename + D/F conflict' '
3846 test_setup_11c &&
3848 cd 11c &&
3850 git checkout A^0 &&
3851 echo stuff >>y/c &&
3853 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3854 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3855 then
3856 test_path_is_missing .git/MERGE_HEAD &&
3857 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3858 else
3859 test_grep "following files would be overwritten by merge" err
3860 fi &&
3862 grep -q stuff y/c &&
3863 test_seq 1 10 >expected &&
3864 echo stuff >>expected &&
3865 test_cmp expected y/c &&
3867 git ls-files -s >out &&
3868 test_line_count = 3 out &&
3869 git ls-files -u >out &&
3870 test_line_count = 0 out &&
3871 git ls-files -m >out &&
3872 test_line_count = 1 out &&
3873 git ls-files -o >out &&
3874 test_line_count = 3 out
3878 # Testcase 11d, Avoid losing not-up-to-date with rename + D/F conflict
3879 # Commit O: z/a, x/{b,c_v1}
3880 # Commit A: z/{a,c_v1}, x/b, and z/c_v1 has uncommitted mods
3881 # Commit B: y/{a,c/d}, x/{b,c_v2}
3882 # Expected: D/F: y/c_v2 vs y/c/d) +
3883 # Warning_Msg("Refusing to lose dirty file at z/c) +
3884 # y/{a,c~HEAD,c/d}, x/b, now-untracked z/c_v1 with uncommitted mods
3886 test_setup_11d () {
3887 git init 11d &&
3889 cd 11d &&
3891 mkdir z x &&
3892 echo a >z/a &&
3893 echo b >x/b &&
3894 test_seq 1 10 >x/c &&
3895 git add z x &&
3896 test_tick &&
3897 git commit -m "O" &&
3899 git branch O &&
3900 git branch A &&
3901 git branch B &&
3903 git checkout A &&
3904 git mv x/c z/c &&
3905 test_tick &&
3906 git commit -m "A" &&
3908 git checkout B &&
3909 git mv z y &&
3910 mkdir y/c &&
3911 echo d >y/c/d &&
3912 echo 11 >>x/c &&
3913 git add x/c y/c/d &&
3914 test_tick &&
3915 git commit -m "B"
3919 test_expect_success '11d: Avoid losing not-uptodate with rename + D/F conflict' '
3920 test_setup_11d &&
3922 cd 11d &&
3924 git checkout A^0 &&
3925 echo stuff >>z/c &&
3927 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
3928 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
3929 then
3930 test_path_is_missing .git/MERGE_HEAD &&
3931 test_grep "error: Your local changes to the following files would be overwritten by merge" err
3932 else
3933 test_grep "Refusing to lose dirty file at z/c" out &&
3935 git ls-files -s >out &&
3936 test_line_count = 4 out &&
3937 git ls-files -u >out &&
3938 test_line_count = 1 out &&
3939 git ls-files -o >out &&
3940 test_line_count = 4 out &&
3942 git rev-parse >actual \
3943 :0:x/b :0:y/a :0:y/c/d :3:y/c &&
3944 git rev-parse >expect \
3945 O:x/b O:z/a B:y/c/d B:x/c &&
3946 test_cmp expect actual &&
3948 git hash-object y/c~HEAD >actual &&
3949 git rev-parse B:x/c >expect &&
3950 test_cmp expect actual
3951 fi &&
3953 grep -q stuff z/c &&
3954 test_seq 1 10 >expected &&
3955 echo stuff >>expected &&
3956 test_cmp expected z/c
3960 # Testcase 11e, Avoid deleting not-up-to-date with dir rename/rename(1to2)/add
3961 # Commit O: z/{a,b}, x/{c_1,d}
3962 # Commit A: y/{a,b,c_2}, x/d, w/c_1, and y/c_2 has uncommitted mods
3963 # Commit B: z/{a,b,c_1}, x/d
3964 # Expected: Failed Merge; y/{a,b} + x/d +
3965 # CONFLICT(rename/rename) x/c_1 -> w/c_1 vs y/c_1 +
3966 # ERROR_MSG(Refusing to lose dirty file at y/c)
3967 # y/c~B^0 has O:x/c_1 contents
3968 # y/c~HEAD has A:y/c_2 contents
3969 # y/c has dirty file from before merge
3971 test_setup_11e () {
3972 git init 11e &&
3974 cd 11e &&
3976 mkdir z x &&
3977 echo a >z/a &&
3978 echo b >z/b &&
3979 echo c >x/c &&
3980 echo d >x/d &&
3981 git add z x &&
3982 test_tick &&
3983 git commit -m "O" &&
3985 git branch O &&
3986 git branch A &&
3987 git branch B &&
3989 git checkout A &&
3990 git mv z/ y/ &&
3991 echo different >y/c &&
3992 mkdir w &&
3993 git mv x/c w/ &&
3994 git add y/c &&
3995 test_tick &&
3996 git commit -m "A" &&
3998 git checkout B &&
3999 git mv x/c z/ &&
4000 test_tick &&
4001 git commit -m "B"
4005 test_expect_success '11e: Avoid deleting not-uptodate with dir rename/rename(1to2)/add' '
4006 test_setup_11e &&
4008 cd 11e &&
4010 git checkout A^0 &&
4011 echo mods >>y/c &&
4013 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4014 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4015 then
4016 test_path_is_missing .git/MERGE_HEAD &&
4017 test_grep "error: Your local changes to the following files would be overwritten by merge" err
4018 else
4019 test_grep "CONFLICT (rename/rename)" out &&
4020 test_grep "Refusing to lose dirty file at y/c" out &&
4022 git ls-files -s >out &&
4023 test_line_count = 7 out &&
4024 git ls-files -u >out &&
4025 test_line_count = 4 out &&
4026 git ls-files -o >out &&
4027 test_line_count = 3 out &&
4029 git rev-parse >actual \
4030 :0:y/a :0:y/b :0:x/d :1:x/c :2:w/c :2:y/c :3:y/c &&
4031 git rev-parse >expect \
4032 O:z/a O:z/b O:x/d O:x/c O:x/c A:y/c O:x/c &&
4033 test_cmp expect actual &&
4035 # See if y/c~merged has expected contents; requires manually
4036 # doing the expected file merge
4037 git cat-file -p A:y/c >c1 &&
4038 git cat-file -p B:z/c >c2 &&
4039 >empty &&
4040 test_must_fail git merge-file \
4041 -L "HEAD" \
4042 -L "" \
4043 -L "B^0" \
4044 c1 empty c2 &&
4045 test_cmp c1 y/c~merged
4046 fi &&
4048 echo different >expected &&
4049 echo mods >>expected &&
4050 test_cmp expected y/c
4054 # Testcase 11f, Avoid deleting not-up-to-date w/ dir rename/rename(2to1)
4055 # Commit O: z/{a,b}, x/{c_1,d_2}
4056 # Commit A: y/{a,b,wham_1}, x/d_2, except y/wham has uncommitted mods
4057 # Commit B: z/{a,b,wham_2}, x/c_1
4058 # Expected: Failed Merge; y/{a,b} + untracked y/{wham~merged} +
4059 # y/wham with dirty changes from before merge +
4060 # CONFLICT(rename/rename) x/c vs x/d -> y/wham
4061 # ERROR_MSG(Refusing to lose dirty file at y/wham)
4063 test_setup_11f () {
4064 git init 11f &&
4066 cd 11f &&
4068 mkdir z x &&
4069 echo a >z/a &&
4070 echo b >z/b &&
4071 test_seq 1 10 >x/c &&
4072 echo d >x/d &&
4073 git add z x &&
4074 test_tick &&
4075 git commit -m "O" &&
4077 git branch O &&
4078 git branch A &&
4079 git branch B &&
4081 git checkout A &&
4082 git mv z/ y/ &&
4083 git mv x/c y/wham &&
4084 test_tick &&
4085 git commit -m "A" &&
4087 git checkout B &&
4088 git mv x/d z/wham &&
4089 test_tick &&
4090 git commit -m "B"
4094 test_expect_success '11f: Avoid deleting not-uptodate with dir rename/rename(2to1)' '
4095 test_setup_11f &&
4097 cd 11f &&
4099 git checkout A^0 &&
4100 echo important >>y/wham &&
4102 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
4103 if test "$GIT_TEST_MERGE_ALGORITHM" = ort
4104 then
4105 test_path_is_missing .git/MERGE_HEAD &&
4106 test_grep "error: Your local changes to the following files would be overwritten by merge" err
4107 else
4108 test_grep "CONFLICT (rename/rename)" out &&
4109 test_grep "Refusing to lose dirty file at y/wham" out &&
4111 git ls-files -s >out &&
4112 test_line_count = 4 out &&
4113 git ls-files -u >out &&
4114 test_line_count = 2 out &&
4115 git ls-files -o >out &&
4116 test_line_count = 3 out &&
4118 test_must_fail git rev-parse :1:y/wham &&
4120 git rev-parse >actual \
4121 :0:y/a :0:y/b :2:y/wham :3:y/wham &&
4122 git rev-parse >expect \
4123 O:z/a O:z/b O:x/c O:x/d &&
4124 test_cmp expect actual &&
4126 # Test that two-way merge in y/wham~merged is as expected
4127 git cat-file -p :2:y/wham >expect &&
4128 git cat-file -p :3:y/wham >other &&
4129 >empty &&
4130 test_must_fail git merge-file \
4131 -L "HEAD" \
4132 -L "" \
4133 -L "B^0" \
4134 expect empty other &&
4135 test_cmp expect y/wham~merged
4136 fi &&
4138 test_seq 1 10 >expected &&
4139 echo important >>expected &&
4140 test_cmp expected y/wham
4144 ###########################################################################
4145 # SECTION 12: Everything else
4147 # Tests suggested by others. Tests added after implementation completed
4148 # and submitted. Grab bag.
4149 ###########################################################################
4151 # Testcase 12a, Moving one directory hierarchy into another
4152 # (Related to testcase 9a)
4153 # Commit O: node1/{leaf1,leaf2}, node2/{leaf3,leaf4}
4154 # Commit A: node1/{leaf1,leaf2,node2/{leaf3,leaf4}}
4155 # Commit B: node1/{leaf1,leaf2,leaf5}, node2/{leaf3,leaf4,leaf6}
4156 # Expected: node1/{leaf1,leaf2,leaf5,node2/{leaf3,leaf4,leaf6}}
4158 test_setup_12a () {
4159 git init 12a &&
4161 cd 12a &&
4163 mkdir -p node1 node2 &&
4164 echo leaf1 >node1/leaf1 &&
4165 echo leaf2 >node1/leaf2 &&
4166 echo leaf3 >node2/leaf3 &&
4167 echo leaf4 >node2/leaf4 &&
4168 git add node1 node2 &&
4169 test_tick &&
4170 git commit -m "O" &&
4172 git branch O &&
4173 git branch A &&
4174 git branch B &&
4176 git checkout A &&
4177 git mv node2/ node1/ &&
4178 test_tick &&
4179 git commit -m "A" &&
4181 git checkout B &&
4182 echo leaf5 >node1/leaf5 &&
4183 echo leaf6 >node2/leaf6 &&
4184 git add node1 node2 &&
4185 test_tick &&
4186 git commit -m "B"
4190 test_expect_success '12a: Moving one directory hierarchy into another' '
4191 test_setup_12a &&
4193 cd 12a &&
4195 git checkout A^0 &&
4197 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4199 git ls-files -s >out &&
4200 test_line_count = 6 out &&
4202 git rev-parse >actual \
4203 HEAD:node1/leaf1 HEAD:node1/leaf2 HEAD:node1/leaf5 \
4204 HEAD:node1/node2/leaf3 \
4205 HEAD:node1/node2/leaf4 \
4206 HEAD:node1/node2/leaf6 &&
4207 git rev-parse >expect \
4208 O:node1/leaf1 O:node1/leaf2 B:node1/leaf5 \
4209 O:node2/leaf3 \
4210 O:node2/leaf4 \
4211 B:node2/leaf6 &&
4212 test_cmp expect actual
4216 # Testcase 12b1, Moving two directory hierarchies into each other
4217 # (Related to testcases 1c and 12c)
4218 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4219 # Commit A: node1/{leaf1, leaf2, node2/{leaf3, leaf4}}
4220 # Commit B: node2/{leaf3, leaf4, node1/{leaf1, leaf2}}
4221 # Expected: node1/node2/{leaf3, leaf4}
4222 # node2/node1/{leaf1, leaf2}
4223 # NOTE: If there were new files added to the old node1/ or node2/ directories,
4224 # then we would need to detect renames for those directories and would
4225 # find that:
4226 # commit A renames node2/ -> node1/node2/
4227 # commit B renames node1/ -> node2/node1/
4228 # Applying those directory renames to the initial result (making all
4229 # four paths experience a transitive renaming), yields
4230 # node1/node2/node1/{leaf1, leaf2}
4231 # node2/node1/node2/{leaf3, leaf4}
4232 # as the result. It may be really weird to have two directories
4233 # rename each other, but simple rules give weird results when given
4234 # weird inputs. HOWEVER, the "If" at the beginning of those NOTE was
4235 # false; there were no new files added and thus there is no directory
4236 # rename detection to perform. As such, we just have simple renames
4237 # and the expected answer is:
4238 # node1/node2/{leaf3, leaf4}
4239 # node2/node1/{leaf1, leaf2}
4241 test_setup_12b1 () {
4242 git init 12b1 &&
4244 cd 12b1 &&
4246 mkdir -p node1 node2 &&
4247 echo leaf1 >node1/leaf1 &&
4248 echo leaf2 >node1/leaf2 &&
4249 echo leaf3 >node2/leaf3 &&
4250 echo leaf4 >node2/leaf4 &&
4251 git add node1 node2 &&
4252 test_tick &&
4253 git commit -m "O" &&
4255 git branch O &&
4256 git branch A &&
4257 git branch B &&
4259 git checkout A &&
4260 git mv node2/ node1/ &&
4261 test_tick &&
4262 git commit -m "A" &&
4264 git checkout B &&
4265 git mv node1/ node2/ &&
4266 test_tick &&
4267 git commit -m "B"
4271 test_expect_merge_algorithm failure success '12b1: Moving two directory hierarchies into each other' '
4272 test_setup_12b1 &&
4274 cd 12b1 &&
4276 git checkout A^0 &&
4278 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4280 git ls-files -s >out &&
4281 test_line_count = 4 out &&
4283 git rev-parse >actual \
4284 HEAD:node2/node1/leaf1 \
4285 HEAD:node2/node1/leaf2 \
4286 HEAD:node1/node2/leaf3 \
4287 HEAD:node1/node2/leaf4 &&
4288 git rev-parse >expect \
4289 O:node1/leaf1 \
4290 O:node1/leaf2 \
4291 O:node2/leaf3 \
4292 O:node2/leaf4 &&
4293 test_cmp expect actual
4297 # Testcase 12b2, Moving two directory hierarchies into each other
4298 # (Related to testcases 1c and 12c)
4299 # Commit O: node1/{leaf1, leaf2}, node2/{leaf3, leaf4}
4300 # Commit A: node1/{leaf1, leaf2, leaf5, node2/{leaf3, leaf4}}
4301 # Commit B: node2/{leaf3, leaf4, leaf6, node1/{leaf1, leaf2}}
4302 # Expected: node1/node2/{node1/{leaf1, leaf2}, leaf6}
4303 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4304 # NOTE: Without directory renames, we would expect
4305 # A: node2/leaf3 -> node1/node2/leaf3
4306 # A: node2/leaf1 -> node1/node2/leaf4
4307 # A: Adds node1/leaf5
4308 # B: node1/leaf1 -> node2/node1/leaf1
4309 # B: node1/leaf2 -> node2/node1/leaf2
4310 # B: Adds node2/leaf6
4311 # with directory rename detection, we note that
4312 # commit A renames node2/ -> node1/node2/
4313 # commit B renames node1/ -> node2/node1/
4314 # therefore, applying A's directory rename to the paths added in B gives:
4315 # B: node1/leaf1 -> node1/node2/node1/leaf1
4316 # B: node1/leaf2 -> node1/node2/node1/leaf2
4317 # B: Adds node1/node2/leaf6
4318 # and applying B's directory rename to the paths added in A gives:
4319 # A: node2/leaf3 -> node2/node1/node2/leaf3
4320 # A: node2/leaf1 -> node2/node1/node2/leaf4
4321 # A: Adds node2/node1/leaf5
4322 # resulting in the expected
4323 # node1/node2/{node1/{leaf1, leaf2}, leaf6}
4324 # node2/node1/{node2/{leaf3, leaf4}, leaf5}
4326 # You may ask, is it weird to have two directories rename each other?
4327 # To which, I can do no more than shrug my shoulders and say that
4328 # even simple rules give weird results when given weird inputs.
4330 test_setup_12b2 () {
4331 git init 12b2 &&
4333 cd 12b2 &&
4335 mkdir -p node1 node2 &&
4336 echo leaf1 >node1/leaf1 &&
4337 echo leaf2 >node1/leaf2 &&
4338 echo leaf3 >node2/leaf3 &&
4339 echo leaf4 >node2/leaf4 &&
4340 git add node1 node2 &&
4341 test_tick &&
4342 git commit -m "O" &&
4344 git branch O &&
4345 git branch A &&
4346 git branch B &&
4348 git checkout A &&
4349 git mv node2/ node1/ &&
4350 echo leaf5 >node1/leaf5 &&
4351 git add node1/leaf5 &&
4352 test_tick &&
4353 git commit -m "A" &&
4355 git checkout B &&
4356 git mv node1/ node2/ &&
4357 echo leaf6 >node2/leaf6 &&
4358 git add node2/leaf6 &&
4359 test_tick &&
4360 git commit -m "B"
4364 test_expect_success '12b2: Moving two directory hierarchies into each other' '
4365 test_setup_12b2 &&
4367 cd 12b2 &&
4369 git checkout A^0 &&
4371 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4373 git ls-files -s >out &&
4374 test_line_count = 6 out &&
4376 git rev-parse >actual \
4377 HEAD:node1/node2/node1/leaf1 \
4378 HEAD:node1/node2/node1/leaf2 \
4379 HEAD:node2/node1/node2/leaf3 \
4380 HEAD:node2/node1/node2/leaf4 \
4381 HEAD:node2/node1/leaf5 \
4382 HEAD:node1/node2/leaf6 &&
4383 git rev-parse >expect \
4384 O:node1/leaf1 \
4385 O:node1/leaf2 \
4386 O:node2/leaf3 \
4387 O:node2/leaf4 \
4388 A:node1/leaf5 \
4389 B:node2/leaf6 &&
4390 test_cmp expect actual
4394 # Testcase 12c1, Moving two directory hierarchies into each other w/ content merge
4395 # (Related to testcase 12b)
4396 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4397 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}}
4398 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3}
4399 # Expected: Content merge conflicts for each of:
4400 # node1/node2/node1/{leaf1, leaf2},
4401 # node2/node1/node2/{leaf3, leaf4}
4402 # NOTE: This is *exactly* like 12b1, except that every path is modified on
4403 # each side of the merge.
4405 test_setup_12c1 () {
4406 git init 12c1 &&
4408 cd 12c1 &&
4410 mkdir -p node1 node2 &&
4411 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4412 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4413 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4414 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4415 git add node1 node2 &&
4416 test_tick &&
4417 git commit -m "O" &&
4419 git branch O &&
4420 git branch A &&
4421 git branch B &&
4423 git checkout A &&
4424 git mv node2/ node1/ &&
4425 for i in $(git ls-files); do echo side A >>$i; done &&
4426 git add -u &&
4427 test_tick &&
4428 git commit -m "A" &&
4430 git checkout B &&
4431 git mv node1/ node2/ &&
4432 for i in $(git ls-files); do echo side B >>$i; done &&
4433 git add -u &&
4434 test_tick &&
4435 git commit -m "B"
4439 test_expect_merge_algorithm failure success '12c1: Moving one directory hierarchy into another w/ content merge' '
4440 test_setup_12c1 &&
4442 cd 12c1 &&
4444 git checkout A^0 &&
4446 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4448 git ls-files -u >out &&
4449 test_line_count = 12 out &&
4451 git rev-parse >actual \
4452 :1:node2/node1/leaf1 \
4453 :1:node2/node1/leaf2 \
4454 :1:node1/node2/leaf3 \
4455 :1:node1/node2/leaf4 \
4456 :2:node2/node1/leaf1 \
4457 :2:node2/node1/leaf2 \
4458 :2:node1/node2/leaf3 \
4459 :2:node1/node2/leaf4 \
4460 :3:node2/node1/leaf1 \
4461 :3:node2/node1/leaf2 \
4462 :3:node1/node2/leaf3 \
4463 :3:node1/node2/leaf4 &&
4464 git rev-parse >expect \
4465 O:node1/leaf1 \
4466 O:node1/leaf2 \
4467 O:node2/leaf3 \
4468 O:node2/leaf4 \
4469 A:node1/leaf1 \
4470 A:node1/leaf2 \
4471 A:node1/node2/leaf3 \
4472 A:node1/node2/leaf4 \
4473 B:node2/node1/leaf1 \
4474 B:node2/node1/leaf2 \
4475 B:node2/leaf3 \
4476 B:node2/leaf4 &&
4477 test_cmp expect actual
4481 # Testcase 12c2, Moving two directory hierarchies into each other w/ content merge
4482 # (Related to testcase 12b)
4483 # Commit O: node1/{ leaf1_1, leaf2_1}, node2/{leaf3_1, leaf4_1}
4484 # Commit A: node1/{ leaf1_2, leaf2_2, node2/{leaf3_2, leaf4_2}, leaf5}
4485 # Commit B: node2/{node1/{leaf1_3, leaf2_3}, leaf3_3, leaf4_3, leaf6}
4486 # Expected: Content merge conflicts for each of:
4487 # node1/node2/node1/{leaf1, leaf2}
4488 # node2/node1/node2/{leaf3, leaf4}
4489 # plus
4490 # node2/node1/leaf5
4491 # node1/node2/leaf6
4492 # NOTE: This is *exactly* like 12b2, except that every path from O is modified
4493 # on each side of the merge.
4495 test_setup_12c2 () {
4496 git init 12c2 &&
4498 cd 12c2 &&
4500 mkdir -p node1 node2 &&
4501 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf1\n" >node1/leaf1 &&
4502 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf2\n" >node1/leaf2 &&
4503 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf3\n" >node2/leaf3 &&
4504 printf "1\n2\n3\n4\n5\n6\n7\n8\nleaf4\n" >node2/leaf4 &&
4505 git add node1 node2 &&
4506 test_tick &&
4507 git commit -m "O" &&
4509 git branch O &&
4510 git branch A &&
4511 git branch B &&
4513 git checkout A &&
4514 git mv node2/ node1/ &&
4515 for i in $(git ls-files); do echo side A >>$i; done &&
4516 git add -u &&
4517 echo leaf5 >node1/leaf5 &&
4518 git add node1/leaf5 &&
4519 test_tick &&
4520 git commit -m "A" &&
4522 git checkout B &&
4523 git mv node1/ node2/ &&
4524 for i in $(git ls-files); do echo side B >>$i; done &&
4525 git add -u &&
4526 echo leaf6 >node2/leaf6 &&
4527 git add node2/leaf6 &&
4528 test_tick &&
4529 git commit -m "B"
4533 test_expect_success '12c2: Moving one directory hierarchy into another w/ content merge' '
4534 test_setup_12c2 &&
4536 cd 12c2 &&
4538 git checkout A^0 &&
4540 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
4542 git ls-files -s >out &&
4543 test_line_count = 14 out &&
4544 git ls-files -u >out &&
4545 test_line_count = 12 out &&
4547 git rev-parse >actual \
4548 :1:node1/node2/node1/leaf1 \
4549 :1:node1/node2/node1/leaf2 \
4550 :1:node2/node1/node2/leaf3 \
4551 :1:node2/node1/node2/leaf4 \
4552 :2:node1/node2/node1/leaf1 \
4553 :2:node1/node2/node1/leaf2 \
4554 :2:node2/node1/node2/leaf3 \
4555 :2:node2/node1/node2/leaf4 \
4556 :3:node1/node2/node1/leaf1 \
4557 :3:node1/node2/node1/leaf2 \
4558 :3:node2/node1/node2/leaf3 \
4559 :3:node2/node1/node2/leaf4 \
4560 :0:node2/node1/leaf5 \
4561 :0:node1/node2/leaf6 &&
4562 git rev-parse >expect \
4563 O:node1/leaf1 \
4564 O:node1/leaf2 \
4565 O:node2/leaf3 \
4566 O:node2/leaf4 \
4567 A:node1/leaf1 \
4568 A:node1/leaf2 \
4569 A:node1/node2/leaf3 \
4570 A:node1/node2/leaf4 \
4571 B:node2/node1/leaf1 \
4572 B:node2/node1/leaf2 \
4573 B:node2/leaf3 \
4574 B:node2/leaf4 \
4575 A:node1/leaf5 \
4576 B:node2/leaf6 &&
4577 test_cmp expect actual
4581 # Testcase 12d, Rename/merge of subdirectory into the root
4582 # Commit O: a/b/subdir/foo
4583 # Commit A: subdir/foo
4584 # Commit B: a/b/subdir/foo, a/b/bar
4585 # Expected: subdir/foo, bar
4587 test_setup_12d () {
4588 git init 12d &&
4590 cd 12d &&
4592 mkdir -p a/b/subdir &&
4593 test_commit a/b/subdir/foo &&
4595 git branch O &&
4596 git branch A &&
4597 git branch B &&
4599 git checkout A &&
4600 mkdir subdir &&
4601 git mv a/b/subdir/foo.t subdir/foo.t &&
4602 test_tick &&
4603 git commit -m "A" &&
4605 git checkout B &&
4606 test_commit a/b/bar
4610 test_expect_success '12d: Rename/merge subdir into the root, variant 1' '
4611 test_setup_12d &&
4613 cd 12d &&
4615 git checkout A^0 &&
4617 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4619 git ls-files -s >out &&
4620 test_line_count = 2 out &&
4622 git rev-parse >actual \
4623 HEAD:subdir/foo.t HEAD:bar.t &&
4624 git rev-parse >expect \
4625 O:a/b/subdir/foo.t B:a/b/bar.t &&
4626 test_cmp expect actual &&
4628 git hash-object bar.t >actual &&
4629 git rev-parse B:a/b/bar.t >expect &&
4630 test_cmp expect actual &&
4632 test_must_fail git rev-parse HEAD:a/b/subdir/foo.t &&
4633 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4634 test_path_is_missing a/ &&
4635 test_path_is_file bar.t
4639 # Testcase 12e, Rename/merge of subdirectory into the root
4640 # Commit O: a/b/foo
4641 # Commit A: foo
4642 # Commit B: a/b/foo, a/b/bar
4643 # Expected: foo, bar
4645 test_setup_12e () {
4646 git init 12e &&
4648 cd 12e &&
4650 mkdir -p a/b &&
4651 test_commit a/b/foo &&
4653 git branch O &&
4654 git branch A &&
4655 git branch B &&
4657 git checkout A &&
4658 mkdir subdir &&
4659 git mv a/b/foo.t foo.t &&
4660 test_tick &&
4661 git commit -m "A" &&
4663 git checkout B &&
4664 test_commit a/b/bar
4668 test_expect_success '12e: Rename/merge subdir into the root, variant 2' '
4669 test_setup_12e &&
4671 cd 12e &&
4673 git checkout A^0 &&
4675 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4677 git ls-files -s >out &&
4678 test_line_count = 2 out &&
4680 git rev-parse >actual \
4681 HEAD:foo.t HEAD:bar.t &&
4682 git rev-parse >expect \
4683 O:a/b/foo.t B:a/b/bar.t &&
4684 test_cmp expect actual &&
4686 git hash-object bar.t >actual &&
4687 git rev-parse B:a/b/bar.t >expect &&
4688 test_cmp expect actual &&
4690 test_must_fail git rev-parse HEAD:a/b/foo.t &&
4691 test_must_fail git rev-parse HEAD:a/b/bar.t &&
4692 test_path_is_missing a/ &&
4693 test_path_is_file bar.t
4697 # Testcase 12f, Rebase of patches with big directory rename
4698 # Commit O:
4699 # dir/subdir/{a,b,c,d,e_O,Makefile_TOP_O}
4700 # dir/subdir/tweaked/{f,g,h,Makefile_SUB_O}
4701 # dir/unchanged/<LOTS OF FILES>
4702 # Commit A:
4703 # (Remove f & g, move e into newsubdir, rename dir/->folder/, modify files)
4704 # folder/subdir/{a,b,c,d,Makefile_TOP_A}
4705 # folder/subdir/newsubdir/e_A
4706 # folder/subdir/tweaked/{h,Makefile_SUB_A}
4707 # folder/unchanged/<LOTS OF FILES>
4708 # Commit B1:
4709 # (add newfile.{c,py}, modify underscored files)
4710 # dir/{a,b,c,d,e_B1,Makefile_TOP_B1,newfile.c}
4711 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4712 # dir/unchanged/<LOTS OF FILES>
4713 # Commit B2:
4714 # (Modify e further, add newfile.rs)
4715 # dir/{a,b,c,d,e_B2,Makefile_TOP_B1,newfile.c,newfile.rs}
4716 # dir/tweaked/{f,g,h,Makefile_SUB_B1,newfile.py}
4717 # dir/unchanged/<LOTS OF FILES>
4718 # Expected:
4719 # B1-picked:
4720 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c}
4721 # folder/subdir/newsubdir/e_Merge1
4722 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4723 # folder/unchanged/<LOTS OF FILES>
4724 # B2-picked:
4725 # folder/subdir/{a,b,c,d,Makefile_TOP_Merge1,newfile.c,newfile.rs}
4726 # folder/subdir/newsubdir/e_Merge2
4727 # folder/subdir/tweaked/{h,Makefile_SUB_Merge1,newfile.py}
4728 # folder/unchanged/<LOTS OF FILES>
4729 # Things being checked here:
4730 # 1. dir/subdir/newfile.c does not get pushed into folder/subdir/newsubdir/.
4731 # dir/subdir/{a,b,c,d} -> folder/subdir/{a,b,c,d} looks like
4732 # dir/ -> folder/,
4733 # whereas dir/subdir/e -> folder/subdir/newsubdir/e looks like
4734 # dir/subdir/ -> folder/subdir/newsubdir/
4735 # and if we note that newfile.c is found in dir/subdir/, we might overlook
4736 # the dir/ -> folder/ rule that has more weight. Older git versions did
4737 # this.
4738 # 2. The code to do trivial directory resolves. Note that
4739 # dir/subdir/unchanged/ is unchanged and can be deleted, and files in the
4740 # new folder/subdir/unchanged/ are not needed as a target to any renames.
4741 # Thus, in the second collect_merge_info_callback() we can just resolve
4742 # these two directories trivially without recursing.)
4743 # 3. Exercising the codepaths for caching renames and deletes from one cherry
4744 # pick and re-applying them in the subsequent one.
4746 test_setup_12f () {
4747 git init 12f &&
4749 cd 12f &&
4751 mkdir -p dir/unchanged &&
4752 mkdir -p dir/subdir/tweaked &&
4753 echo a >dir/subdir/a &&
4754 echo b >dir/subdir/b &&
4755 echo c >dir/subdir/c &&
4756 echo d >dir/subdir/d &&
4757 test_seq 1 10 >dir/subdir/e &&
4758 test_seq 10 20 >dir/subdir/Makefile &&
4759 echo f >dir/subdir/tweaked/f &&
4760 echo g >dir/subdir/tweaked/g &&
4761 echo h >dir/subdir/tweaked/h &&
4762 test_seq 20 30 >dir/subdir/tweaked/Makefile &&
4763 for i in $(test_seq 1 88); do
4764 echo content $i >dir/unchanged/file_$i
4765 done &&
4766 git add . &&
4767 git commit -m "O" &&
4769 git branch O &&
4770 git branch A &&
4771 git branch B &&
4773 git switch A &&
4774 git rm dir/subdir/tweaked/f dir/subdir/tweaked/g &&
4775 test_seq 2 10 >dir/subdir/e &&
4776 test_seq 11 20 >dir/subdir/Makefile &&
4777 test_seq 21 30 >dir/subdir/tweaked/Makefile &&
4778 mkdir dir/subdir/newsubdir &&
4779 git mv dir/subdir/e dir/subdir/newsubdir/ &&
4780 git mv dir folder &&
4781 git add . &&
4782 git commit -m "A" &&
4784 git switch B &&
4785 mkdir dir/subdir/newsubdir/ &&
4786 echo c code >dir/subdir/newfile.c &&
4787 echo python code >dir/subdir/newsubdir/newfile.py &&
4788 test_seq 1 11 >dir/subdir/e &&
4789 test_seq 10 21 >dir/subdir/Makefile &&
4790 test_seq 20 31 >dir/subdir/tweaked/Makefile &&
4791 git add . &&
4792 git commit -m "B1" &&
4794 echo rust code >dir/subdir/newfile.rs &&
4795 test_seq 1 12 >dir/subdir/e &&
4796 git add . &&
4797 git commit -m "B2"
4801 test_expect_merge_algorithm failure success '12f: Trivial directory resolve, caching, all kinds of fun' '
4802 test_setup_12f &&
4804 cd 12f &&
4806 git checkout A^0 &&
4807 git branch Bmod B &&
4809 GIT_TRACE2_PERF="$(pwd)/trace.output" git -c merge.directoryRenames=true rebase A Bmod &&
4811 echo Checking the pick of B1... &&
4813 test_must_fail git rev-parse Bmod~1:dir &&
4815 git ls-tree -r Bmod~1 >out &&
4816 test_line_count = 98 out &&
4818 git diff --name-status A Bmod~1 >actual &&
4819 q_to_tab >expect <<-\EOF &&
4820 MQfolder/subdir/Makefile
4821 AQfolder/subdir/newfile.c
4822 MQfolder/subdir/newsubdir/e
4823 AQfolder/subdir/newsubdir/newfile.py
4824 MQfolder/subdir/tweaked/Makefile
4826 test_cmp expect actual &&
4828 # Three-way merged files
4829 test_seq 2 11 >e_Merge1 &&
4830 test_seq 11 21 >Makefile_TOP &&
4831 test_seq 21 31 >Makefile_SUB &&
4832 git hash-object >expect \
4833 e_Merge1 \
4834 Makefile_TOP \
4835 Makefile_SUB &&
4836 git rev-parse >actual \
4837 Bmod~1:folder/subdir/newsubdir/e \
4838 Bmod~1:folder/subdir/Makefile \
4839 Bmod~1:folder/subdir/tweaked/Makefile &&
4840 test_cmp expect actual &&
4842 # New files showed up at the right location with right contents
4843 git rev-parse >expect \
4844 B~1:dir/subdir/newfile.c \
4845 B~1:dir/subdir/newsubdir/newfile.py &&
4846 git rev-parse >actual \
4847 Bmod~1:folder/subdir/newfile.c \
4848 Bmod~1:folder/subdir/newsubdir/newfile.py &&
4849 test_cmp expect actual &&
4851 # Removed files
4852 test_path_is_missing folder/subdir/tweaked/f &&
4853 test_path_is_missing folder/subdir/tweaked/g &&
4855 # Unchanged files or directories
4856 git rev-parse >actual \
4857 Bmod~1:folder/subdir/a \
4858 Bmod~1:folder/subdir/b \
4859 Bmod~1:folder/subdir/c \
4860 Bmod~1:folder/subdir/d \
4861 Bmod~1:folder/unchanged \
4862 Bmod~1:folder/subdir/tweaked/h &&
4863 git rev-parse >expect \
4864 O:dir/subdir/a \
4865 O:dir/subdir/b \
4866 O:dir/subdir/c \
4867 O:dir/subdir/d \
4868 O:dir/unchanged \
4869 O:dir/subdir/tweaked/h &&
4870 test_cmp expect actual &&
4872 echo Checking the pick of B2... &&
4874 test_must_fail git rev-parse Bmod:dir &&
4876 git ls-tree -r Bmod >out &&
4877 test_line_count = 99 out &&
4879 git diff --name-status Bmod~1 Bmod >actual &&
4880 q_to_tab >expect <<-\EOF &&
4881 AQfolder/subdir/newfile.rs
4882 MQfolder/subdir/newsubdir/e
4884 test_cmp expect actual &&
4886 # Three-way merged file
4887 test_seq 2 12 >e_Merge2 &&
4888 git hash-object e_Merge2 >expect &&
4889 git rev-parse Bmod:folder/subdir/newsubdir/e >actual &&
4890 test_cmp expect actual &&
4892 grep region_enter.*collect_merge_info trace.output >collect &&
4893 test_line_count = 4 collect &&
4894 grep region_enter.*process_entries$ trace.output >process &&
4895 test_line_count = 2 process
4899 # Testcase 12g, Testcase with two kinds of "relevant" renames
4900 # Commit O: somefile_O, subdir/{a_O,b_O}
4901 # Commit A: somefile_A, subdir/{a_O,b_O,c_A}
4902 # Commit B: newfile_B, newdir/{a_B,b_B}
4903 # Expected: newfile_{merged}, newdir/{a_B,b_B,c_A}
4905 test_setup_12g () {
4906 git init 12g &&
4908 cd 12g &&
4910 mkdir -p subdir &&
4911 test_write_lines upon a time there was a >somefile &&
4912 test_write_lines 1 2 3 4 5 6 7 8 9 10 >subdir/a &&
4913 test_write_lines one two three four five six >subdir/b &&
4914 git add . &&
4915 test_tick &&
4916 git commit -m "O" &&
4918 git branch O &&
4919 git branch A &&
4920 git branch B &&
4922 git switch A &&
4923 test_write_lines once upon a time there was a >somefile &&
4924 > subdir/c &&
4925 git add somefile subdir/c &&
4926 test_tick &&
4927 git commit -m "A" &&
4929 git checkout B &&
4930 git mv somefile newfile &&
4931 git mv subdir newdir &&
4932 echo repo >>newfile &&
4933 test_write_lines 1 2 3 4 5 6 7 8 9 10 11 >newdir/a &&
4934 test_write_lines one two three four five six seven >newdir/b &&
4935 git add newfile newdir &&
4936 test_tick &&
4937 git commit -m "B"
4941 test_expect_success '12g: Testcase with two kinds of "relevant" renames' '
4942 test_setup_12g &&
4944 cd 12g &&
4946 git checkout A^0 &&
4948 git -c merge.directoryRenames=true merge -s recursive B^0 &&
4950 test_write_lines once upon a time there was a repo >expect &&
4951 test_cmp expect newfile &&
4953 git ls-files -s >out &&
4954 test_line_count = 4 out &&
4956 git rev-parse >actual \
4957 HEAD:newdir/a HEAD:newdir/b HEAD:newdir/c &&
4958 git rev-parse >expect \
4959 B:newdir/a B:newdir/b A:subdir/c &&
4960 test_cmp expect actual &&
4962 test_must_fail git rev-parse HEAD:subdir/a &&
4963 test_must_fail git rev-parse HEAD:subdir/b &&
4964 test_must_fail git rev-parse HEAD:subdir/c &&
4965 test_path_is_missing subdir/ &&
4966 test_path_is_file newdir/c
4970 # Testcase 12h, Testcase with two kinds of "relevant" renames
4971 # Commit O: olddir/{a_1, b}
4972 # Commit A: newdir/{a_2, b}
4973 # Commit B: olddir/{alpha_1, b}
4974 # Expected: newdir/{alpha_2, b}
4976 test_setup_12h () {
4977 git init 12h &&
4979 cd 12h &&
4981 mkdir olddir &&
4982 test_seq 3 8 >olddir/a &&
4983 >olddir/b &&
4984 git add olddir &&
4985 git commit -m orig &&
4987 git branch O &&
4988 git branch A &&
4989 git branch B &&
4991 git switch A &&
4992 test_seq 3 10 >olddir/a &&
4993 git add olddir/a &&
4994 git mv olddir newdir &&
4995 git commit -m A &&
4997 git switch B &&
4999 git mv olddir/a olddir/alpha &&
5000 git commit -m B
5004 test_expect_failure '12h: renaming a file within a renamed directory' '
5005 test_setup_12h &&
5007 cd 12h &&
5009 git checkout A^0 &&
5011 test_might_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5013 git ls-files >tracked &&
5014 test_line_count = 2 tracked &&
5016 test_path_is_missing olddir/a &&
5017 test_path_is_file newdir/alpha &&
5018 test_path_is_file newdir/b &&
5020 git rev-parse >actual \
5021 HEAD:newdir/alpha HEAD:newdir/b &&
5022 git rev-parse >expect \
5023 A:newdir/a O:oldir/b &&
5024 test_cmp expect actual
5028 # Testcase 12i, Directory rename causes rename-to-self
5029 # Commit O: source/{subdir/foo, bar, baz_1}
5030 # Commit A: source/{foo, bar, baz_1}
5031 # Commit B: source/{subdir/{foo, bar}, baz_2}
5032 # Expected: source/{foo, bar, baz_2}, with conflicts on
5033 # source/bar vs. source/subdir/bar
5035 test_setup_12i () {
5036 git init 12i &&
5038 cd 12i &&
5040 mkdir -p source/subdir &&
5041 echo foo >source/subdir/foo &&
5042 echo bar >source/bar &&
5043 echo baz >source/baz &&
5044 git add source &&
5045 git commit -m orig &&
5047 git branch O &&
5048 git branch A &&
5049 git branch B &&
5051 git switch A &&
5052 git mv source/subdir/foo source/foo &&
5053 git commit -m A &&
5055 git switch B &&
5056 git mv source/bar source/subdir/bar &&
5057 echo more baz >>source/baz &&
5058 git commit -m B
5062 test_expect_success '12i: Directory rename causes rename-to-self' '
5063 test_setup_12i &&
5065 cd 12i &&
5067 git checkout A^0 &&
5069 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5071 test_path_is_missing source/subdir &&
5072 test_path_is_file source/bar &&
5073 test_path_is_file source/baz &&
5075 git ls-files | uniq >tracked &&
5076 test_line_count = 3 tracked &&
5078 git status --porcelain -uno >actual &&
5079 cat >expect <<-\EOF &&
5080 UU source/bar
5081 M source/baz
5083 test_cmp expect actual
5087 # Testcase 12j, Directory rename to root causes rename-to-self
5088 # Commit O: {subdir/foo, bar, baz_1}
5089 # Commit A: {foo, bar, baz_1}
5090 # Commit B: {subdir/{foo, bar}, baz_2}
5091 # Expected: {foo, bar, baz_2}, with conflicts on bar vs. subdir/bar
5093 test_setup_12j () {
5094 git init 12j &&
5096 cd 12j &&
5098 mkdir -p subdir &&
5099 echo foo >subdir/foo &&
5100 echo bar >bar &&
5101 echo baz >baz &&
5102 git add . &&
5103 git commit -m orig &&
5105 git branch O &&
5106 git branch A &&
5107 git branch B &&
5109 git switch A &&
5110 git mv subdir/foo foo &&
5111 git commit -m A &&
5113 git switch B &&
5114 git mv bar subdir/bar &&
5115 echo more baz >>baz &&
5116 git commit -m B
5120 test_expect_success '12j: Directory rename to root causes rename-to-self' '
5121 test_setup_12j &&
5123 cd 12j &&
5125 git checkout A^0 &&
5127 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5129 test_path_is_missing subdir &&
5130 test_path_is_file bar &&
5131 test_path_is_file baz &&
5133 git ls-files | uniq >tracked &&
5134 test_line_count = 3 tracked &&
5136 git status --porcelain -uno >actual &&
5137 cat >expect <<-\EOF &&
5138 UU bar
5139 M baz
5141 test_cmp expect actual
5145 # Testcase 12k, Directory rename with sibling causes rename-to-self
5146 # Commit O: dirB/foo, dirA/{bar, baz_1}
5147 # Commit A: dirA/{foo, bar, baz_1}
5148 # Commit B: dirB/{foo, bar}, dirA/baz_2
5149 # Expected: dirA/{foo, bar, baz_2}, with conflicts on dirA/bar vs. dirB/bar
5151 test_setup_12k () {
5152 git init 12k &&
5154 cd 12k &&
5156 mkdir dirA dirB &&
5157 echo foo >dirB/foo &&
5158 echo bar >dirA/bar &&
5159 echo baz >dirA/baz &&
5160 git add . &&
5161 git commit -m orig &&
5163 git branch O &&
5164 git branch A &&
5165 git branch B &&
5167 git switch A &&
5168 git mv dirB/* dirA/ &&
5169 git commit -m A &&
5171 git switch B &&
5172 git mv dirA/bar dirB/bar &&
5173 echo more baz >>dirA/baz &&
5174 git commit -m B
5178 test_expect_success '12k: Directory rename with sibling causes rename-to-self' '
5179 test_setup_12k &&
5181 cd 12k &&
5183 git checkout A^0 &&
5185 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5187 test_path_is_missing dirB &&
5188 test_path_is_file dirA/bar &&
5189 test_path_is_file dirA/baz &&
5191 git ls-files | uniq >tracked &&
5192 test_line_count = 3 tracked &&
5194 git status --porcelain -uno >actual &&
5195 cat >expect <<-\EOF &&
5196 UU dirA/bar
5197 M dirA/baz
5199 test_cmp expect actual
5203 # Testcase 12l, Both sides rename a directory into the other side, both add
5204 # a file which after directory renames are the same filename
5205 # Commit O: sub1/file, sub2/other
5206 # Commit A: sub3/file, sub2/{other, new_add_add_file_1}
5207 # Commit B: sub1/{file, newfile}, sub1/sub2/{other, new_add_add_file_2}
5209 # In words:
5210 # A: sub1/ -> sub3/, add sub2/new_add_add_file_1
5211 # B: sub2/ -> sub1/sub2, add sub1/newfile, add sub1/sub2/new_add_add_file_2
5213 # Expected: sub3/{file, newfile, sub2/other}
5214 # CONFLICT (add/add): sub1/sub2/new_add_add_file
5216 # Note that sub1/newfile is not extraneous. Directory renames are only
5217 # detected if they are needed, and they are only needed if the old directory
5218 # had a new file added on the opposite side of history. So sub1/newfile
5219 # is needed for there to be a sub1/ -> sub3/ rename.
5221 test_setup_12l () {
5222 git init 12l_$1 &&
5224 cd 12l_$1 &&
5226 mkdir sub1 sub2
5227 echo file >sub1/file &&
5228 echo other >sub2/other &&
5229 git add sub1 sub2 &&
5230 git commit -m "O" &&
5232 git branch O &&
5233 git branch A &&
5234 git branch B &&
5236 git checkout A &&
5237 git mv sub1 sub3 &&
5238 echo conflicting >sub2/new_add_add_file &&
5239 git add sub2 &&
5240 test_tick &&
5241 git add -u &&
5242 git commit -m "A" &&
5244 git checkout B &&
5245 echo dissimilar >sub2/new_add_add_file &&
5246 echo brand >sub1/newfile &&
5247 git add sub1 sub2 &&
5248 git mv sub2 sub1 &&
5249 test_tick &&
5250 git commit -m "B"
5254 test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' '
5255 test_setup_12l BintoA &&
5257 cd 12l_BintoA &&
5259 git checkout -q A^0 &&
5261 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 &&
5263 test_stdout_line_count = 5 git ls-files -s &&
5265 git rev-parse >actual \
5266 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5267 :2:sub1/sub2/new_add_add_file \
5268 :3:sub1/sub2/new_add_add_file &&
5269 git rev-parse >expect \
5270 O:sub1/file B:sub1/newfile O:sub2/other \
5271 A:sub2/new_add_add_file \
5272 B:sub1/sub2/new_add_add_file &&
5273 test_cmp expect actual &&
5275 git ls-files -o >actual &&
5276 test_write_lines actual expect >expect &&
5277 test_cmp expect actual
5281 test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' '
5282 test_setup_12l AintoB &&
5284 cd 12l_AintoB &&
5286 git checkout -q B^0 &&
5288 test_must_fail git -c merge.directoryRenames=true merge -s recursive A^0 &&
5290 test_stdout_line_count = 5 git ls-files -s &&
5292 git rev-parse >actual \
5293 :0:sub3/file :0:sub3/newfile :0:sub3/sub2/other \
5294 :2:sub1/sub2/new_add_add_file \
5295 :3:sub1/sub2/new_add_add_file &&
5296 git rev-parse >expect \
5297 O:sub1/file B:sub1/newfile O:sub2/other \
5298 B:sub1/sub2/new_add_add_file \
5299 A:sub2/new_add_add_file &&
5300 test_cmp expect actual &&
5302 git ls-files -o >actual &&
5303 test_write_lines actual expect >expect &&
5304 test_cmp expect actual
5308 # Testcase 12m, Directory rename, plus change of parent dir to symlink
5309 # Commit O: dir/subdir/file
5310 # Commit A: renamed-dir/subdir/file
5311 # Commit B: dir/subdir
5312 # In words:
5313 # A: dir/subdir/ -> renamed-dir/subdir
5314 # B: delete dir/subdir/file, add dir/subdir as symlink
5316 # Expected: CONFLICT (rename/delete): renamed-dir/subdir/file,
5317 # CONFLICT (file location): renamed-dir/subdir vs. dir/subdir
5318 # CONFLICT (directory/file): renamed-dir/subdir symlink has
5319 # renamed-dir/subdir in the way
5321 test_setup_12m () {
5322 git init 12m &&
5324 cd 12m &&
5326 mkdir -p dir/subdir &&
5327 echo 1 >dir/subdir/file &&
5328 git add . &&
5329 git commit -m "O" &&
5331 git branch O &&
5332 git branch A &&
5333 git branch B &&
5335 git switch A &&
5336 git mv dir/ renamed-dir/ &&
5337 git add . &&
5338 git commit -m "A" &&
5340 git switch B &&
5341 git rm dir/subdir/file &&
5342 mkdir dir &&
5343 ln -s /dev/null dir/subdir &&
5344 git add . &&
5345 git commit -m "B"
5349 test_expect_merge_algorithm failure success '12m: Change parent of renamed-dir to symlink on other side' '
5350 test_setup_12m &&
5352 cd 12m &&
5354 git checkout -q A^0 &&
5356 test_must_fail git -c merge.directoryRenames=conflict merge -s recursive B^0 &&
5358 test_stdout_line_count = 3 git ls-files -s &&
5359 test_stdout_line_count = 2 ls -1 renamed-dir &&
5360 test_path_is_missing dir
5364 ###########################################################################
5365 # SECTION 13: Checking informational and conflict messages
5367 # A year after directory rename detection became the default, it was
5368 # instead decided to report conflicts on the pathname on the basis that
5369 # some users may expect the new files added or moved into a directory to
5370 # be unrelated to all the other files in that directory, and thus that
5371 # directory rename detection is unexpected. Test that the messages printed
5372 # match our expectation.
5373 ###########################################################################
5375 # Testcase 13a, Basic directory rename with newly added files
5376 # Commit O: z/{b,c}
5377 # Commit A: y/{b,c}
5378 # Commit B: z/{b,c,d,e/f}
5379 # Expected: y/{b,c,d,e/f}, with notices/conflicts for both y/d and y/e/f
5381 test_setup_13a () {
5382 git init 13a_$1 &&
5384 cd 13a_$1 &&
5386 mkdir z &&
5387 echo b >z/b &&
5388 echo c >z/c &&
5389 git add z &&
5390 test_tick &&
5391 git commit -m "O" &&
5393 git branch O &&
5394 git branch A &&
5395 git branch B &&
5397 git checkout A &&
5398 git mv z y &&
5399 test_tick &&
5400 git commit -m "A" &&
5402 git checkout B &&
5403 echo d >z/d &&
5404 mkdir z/e &&
5405 echo f >z/e/f &&
5406 git add z/d z/e/f &&
5407 test_tick &&
5408 git commit -m "B"
5412 test_expect_success '13a(conflict): messages for newly added files' '
5413 test_setup_13a conflict &&
5415 cd 13a_conflict &&
5417 git checkout A^0 &&
5419 test_must_fail git merge -s recursive B^0 >out 2>err &&
5421 test_grep CONFLICT..file.location.*z/e/f.added.in.B^0.*y/e/f out &&
5422 test_grep CONFLICT..file.location.*z/d.added.in.B^0.*y/d out &&
5424 git ls-files >paths &&
5425 ! grep z/ paths &&
5426 grep "y/[de]" paths &&
5428 test_path_is_missing z/d &&
5429 test_path_is_file y/d &&
5430 test_path_is_missing z/e/f &&
5431 test_path_is_file y/e/f
5435 test_expect_success '13a(info): messages for newly added files' '
5436 test_setup_13a info &&
5438 cd 13a_info &&
5440 git reset --hard &&
5441 git checkout A^0 &&
5443 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5445 test_grep Path.updated:.*z/e/f.added.in.B^0.*y/e/f out &&
5446 test_grep Path.updated:.*z/d.added.in.B^0.*y/d out &&
5448 git ls-files >paths &&
5449 ! grep z/ paths &&
5450 grep "y/[de]" paths &&
5452 test_path_is_missing z/d &&
5453 test_path_is_file y/d &&
5454 test_path_is_missing z/e/f &&
5455 test_path_is_file y/e/f
5459 # Testcase 13b, Transitive rename with conflicted content merge and default
5460 # "conflict" setting
5461 # (Related to testcase 1c, 9b)
5462 # Commit O: z/{b,c}, x/d_1
5463 # Commit A: y/{b,c}, x/d_2
5464 # Commit B: z/{b,c,d_3}
5465 # Expected: y/{b,c,d_merged}, with two conflict messages for y/d,
5466 # one about content, and one about file location
5468 test_setup_13b () {
5469 git init 13b_$1 &&
5471 cd 13b_$1 &&
5473 mkdir x &&
5474 mkdir z &&
5475 test_seq 1 10 >x/d &&
5476 echo b >z/b &&
5477 echo c >z/c &&
5478 git add x z &&
5479 test_tick &&
5480 git commit -m "O" &&
5482 git branch O &&
5483 git branch A &&
5484 git branch B &&
5486 git checkout A &&
5487 git mv z y &&
5488 echo 11 >>x/d &&
5489 git add x/d &&
5490 test_tick &&
5491 git commit -m "A" &&
5493 git checkout B &&
5494 echo eleven >>x/d &&
5495 git mv x/d z/d &&
5496 git add z/d &&
5497 test_tick &&
5498 git commit -m "B"
5502 test_expect_success '13b(conflict): messages for transitive rename with conflicted content' '
5503 test_setup_13b conflict &&
5505 cd 13b_conflict &&
5507 git checkout A^0 &&
5509 test_must_fail git merge -s recursive B^0 >out 2>err &&
5511 test_grep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5512 test_grep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5514 git ls-files >paths &&
5515 ! grep z/ paths &&
5516 grep "y/d" paths &&
5518 test_path_is_missing z/d &&
5519 test_path_is_file y/d
5523 test_expect_success '13b(info): messages for transitive rename with conflicted content' '
5524 test_setup_13b info &&
5526 cd 13b_info &&
5528 git reset --hard &&
5529 git checkout A^0 &&
5531 test_must_fail git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5533 test_grep CONFLICT.*content.*Merge.conflict.in.y/d out &&
5534 test_grep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5536 git ls-files >paths &&
5537 ! grep z/ paths &&
5538 grep "y/d" paths &&
5540 test_path_is_missing z/d &&
5541 test_path_is_file y/d
5545 # Testcase 13c, Rename/rename(1to1) due to directory rename
5546 # Commit O: z/{b,c}, x/{d,e}
5547 # Commit A: y/{b,c,d}, x/e
5548 # Commit B: z/{b,c,d}, x/e
5549 # Expected: y/{b,c,d}, x/e, with info or conflict messages for d
5550 # A: renamed x/d -> z/d; B: renamed z/ -> y/ AND renamed x/d to y/d
5551 # One could argue A had partial knowledge of what was done with
5552 # d and B had full knowledge, but that's a slippery slope as
5553 # shown in testcase 13d.
5555 test_setup_13c () {
5556 git init 13c_$1 &&
5558 cd 13c_$1 &&
5560 mkdir x &&
5561 mkdir z &&
5562 test_seq 1 10 >x/d &&
5563 echo e >x/e &&
5564 echo b >z/b &&
5565 echo c >z/c &&
5566 git add x z &&
5567 test_tick &&
5568 git commit -m "O" &&
5570 git branch O &&
5571 git branch A &&
5572 git branch B &&
5574 git checkout A &&
5575 git mv z y &&
5576 git mv x/d y/ &&
5577 test_tick &&
5578 git commit -m "A" &&
5580 git checkout B &&
5581 git mv x/d z/d &&
5582 git add z/d &&
5583 test_tick &&
5584 git commit -m "B"
5588 test_expect_success '13c(conflict): messages for rename/rename(1to1) via transitive rename' '
5589 test_setup_13c conflict &&
5591 cd 13c_conflict &&
5593 git checkout A^0 &&
5595 test_must_fail git merge -s recursive B^0 >out 2>err &&
5597 test_grep CONFLICT..file.location.*x/d.renamed.to.z/d.*moved.to.y/d out &&
5599 git ls-files >paths &&
5600 ! grep z/ paths &&
5601 grep "y/d" paths &&
5603 test_path_is_missing z/d &&
5604 test_path_is_file y/d
5608 test_expect_success '13c(info): messages for rename/rename(1to1) via transitive rename' '
5609 test_setup_13c info &&
5611 cd 13c_info &&
5613 git reset --hard &&
5614 git checkout A^0 &&
5616 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5618 test_grep Path.updated:.*x/d.renamed.to.z/d.in.B^0.*moving.it.to.y/d out &&
5620 git ls-files >paths &&
5621 ! grep z/ paths &&
5622 grep "y/d" paths &&
5624 test_path_is_missing z/d &&
5625 test_path_is_file y/d
5629 # Testcase 13d, Rename/rename(1to1) due to directory rename on both sides
5630 # Commit O: a/{z,y}, b/x, c/w
5631 # Commit A: a/z, b/{y,x}, d/w
5632 # Commit B: a/z, d/x, c/{y,w}
5633 # Expected: a/z, d/{y,x,w} with no file location conflict for x
5634 # Easy cases:
5635 # * z is always in a; so it stays in a.
5636 # * x starts in b, only modified on one side to move into d/
5637 # * w starts in c, only modified on one side to move into d/
5638 # Hard case:
5639 # * A renames a/y to b/y, and B renames b/->d/ => a/y -> d/y
5640 # * B renames a/y to c/y, and A renames c/->d/ => a/y -> d/y
5641 # No conflict in where a/y ends up, so put it in d/y.
5643 test_setup_13d () {
5644 git init 13d_$1 &&
5646 cd 13d_$1 &&
5648 mkdir a &&
5649 mkdir b &&
5650 mkdir c &&
5651 echo z >a/z &&
5652 echo y >a/y &&
5653 echo x >b/x &&
5654 echo w >c/w &&
5655 git add a b c &&
5656 test_tick &&
5657 git commit -m "O" &&
5659 git branch O &&
5660 git branch A &&
5661 git branch B &&
5663 git checkout A &&
5664 git mv a/y b/ &&
5665 git mv c/ d/ &&
5666 test_tick &&
5667 git commit -m "A" &&
5669 git checkout B &&
5670 git mv a/y c/ &&
5671 git mv b/ d/ &&
5672 test_tick &&
5673 git commit -m "B"
5677 test_expect_success '13d(conflict): messages for rename/rename(1to1) via dual transitive rename' '
5678 test_setup_13d conflict &&
5680 cd 13d_conflict &&
5682 git checkout A^0 &&
5684 test_must_fail git merge -s recursive B^0 >out 2>err &&
5686 test_grep CONFLICT..file.location.*a/y.renamed.to.b/y.*moved.to.d/y out &&
5687 test_grep CONFLICT..file.location.*a/y.renamed.to.c/y.*moved.to.d/y out &&
5689 git ls-files >paths &&
5690 ! grep b/ paths &&
5691 ! grep c/ paths &&
5692 grep "d/y" paths &&
5694 test_path_is_missing b/y &&
5695 test_path_is_missing c/y &&
5696 test_path_is_file d/y
5700 test_expect_success '13d(info): messages for rename/rename(1to1) via dual transitive rename' '
5701 test_setup_13d info &&
5703 cd 13d_info &&
5705 git reset --hard &&
5706 git checkout A^0 &&
5708 git -c merge.directoryRenames=true merge -s recursive B^0 >out 2>err &&
5710 test_grep Path.updated.*a/y.renamed.to.b/y.*moving.it.to.d/y out &&
5711 test_grep Path.updated.*a/y.renamed.to.c/y.*moving.it.to.d/y out &&
5713 git ls-files >paths &&
5714 ! grep b/ paths &&
5715 ! grep c/ paths &&
5716 grep "d/y" paths &&
5718 test_path_is_missing b/y &&
5719 test_path_is_missing c/y &&
5720 test_path_is_file d/y
5724 # Testcase 13e, directory rename in virtual merge base
5726 # This testcase has a slightly different setup than all the above cases, in
5727 # order to include a recursive case:
5729 # A C
5730 # o - o
5731 # / \ / \
5732 # O o X ?
5733 # \ / \ /
5734 # o o
5735 # B D
5737 # Commit O: a/{z,y}
5738 # Commit A: b/{z,y}
5739 # Commit B: a/{z,y,x}
5740 # Commit C: b/{z,y,x}
5741 # Commit D: b/{z,y}, a/x
5742 # Expected: b/{z,y,x} (sort of; see below for why this might not be expected)
5744 # NOTES: 'X' represents a virtual merge base. With the default of
5745 # directory rename detection yielding conflicts, merging A and B
5746 # results in a conflict complaining about whether 'x' should be
5747 # under 'a/' or 'b/'. However, when creating the virtual merge
5748 # base 'X', since virtual merge bases need to be written out as a
5749 # tree, we cannot have a conflict, so some resolution has to be
5750 # picked.
5752 # In choosing the right resolution, it's worth noting here that
5753 # commits C & D are merges of A & B that choose different
5754 # locations for 'x' (i.e. they resolve the conflict differently),
5755 # and so it would be nice when merging C & D if git could detect
5756 # this difference of opinion and report a conflict. But the only
5757 # way to do so that I can think of would be to have the virtual
5758 # merge base place 'x' in some directory other than either 'a/' or
5759 # 'b/', which seems a little weird -- especially since it'd result
5760 # in a rename/rename(1to2) conflict with a source path that never
5761 # existed in any version.
5763 # So, for now, when directory rename detection is set to
5764 # 'conflict' just avoid doing directory rename detection at all in
5765 # the recursive case. This will not allow us to detect a conflict
5766 # in the outer merge for this special kind of setup, but it at
5767 # least avoids hitting a BUG().
5769 test_setup_13e () {
5770 git init 13e &&
5772 cd 13e &&
5774 mkdir a &&
5775 echo z >a/z &&
5776 echo y >a/y &&
5777 git add a &&
5778 test_tick &&
5779 git commit -m "O" &&
5781 git branch O &&
5782 git branch A &&
5783 git branch B &&
5785 git checkout A &&
5786 git mv a/ b/ &&
5787 test_tick &&
5788 git commit -m "A" &&
5790 git checkout B &&
5791 echo x >a/x &&
5792 git add a &&
5793 test_tick &&
5794 git commit -m "B" &&
5796 git branch C A &&
5797 git branch D B &&
5799 git checkout C &&
5800 test_must_fail git -c merge.directoryRenames=conflict merge B &&
5801 git add b/x &&
5802 test_tick &&
5803 git commit -m "C" &&
5806 git checkout D &&
5807 test_must_fail git -c merge.directoryRenames=conflict merge A &&
5808 git add b/x &&
5809 mkdir a &&
5810 git mv b/x a/x &&
5811 test_tick &&
5812 git commit -m "D"
5816 test_expect_success '13e: directory rename detection in recursive case' '
5817 test_setup_13e &&
5819 cd 13e &&
5821 git checkout --quiet D^0 &&
5823 git -c merge.directoryRenames=conflict merge -s recursive C^0 >out 2>err &&
5825 test_grep ! CONFLICT out &&
5826 test_grep ! BUG: err &&
5827 test_grep ! core.dumped err &&
5828 test_must_be_empty err &&
5830 git ls-files >paths &&
5831 ! grep a/x paths &&
5832 grep b/x paths
5836 test_done