directory rename detection: testcases to avoid taking detection too far

Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 19, 2018 at 10:57 UTC 21b53733a033620598cfb6d46336ccbef5f7d460
1 file changed +153
t/t6043-merge-rename-directories.sh
+153
@@ -582,4 +582,157 @@ test_expect_success '2b-check: Directory split into two on one side, with equal
582 # messages are handled correctly.
583 ###########################################################################
584
585 +
586 +###########################################################################
587 +# SECTION 3: Path in question is the source path for some rename already
588 +#
589 +# Combining cases from Section 1 and trying to handle them could lead to
590 +# directory renaming detection being over-applied. So, this section
591 +# provides some good testcases to check that the implementation doesn't go
592 +# too far.
593 +###########################################################################
594 +
595 +# Testcase 3a, Avoid implicit rename if involved as source on other side
596 +# (Related to testcases 1c and 1f)
597 +# Commit O: z/{b,c,d}
598 +# Commit A: z/{b,c,d} (no change)
599 +# Commit B: y/{b,c}, x/d
600 +# Expected: y/{b,c}, x/d
601 +test_expect_success '3a-setup: Avoid implicit rename if involved as source on other side' '
602 + test_create_repo 3a &&
603 + (
604 + cd 3a &&
605 +
606 + mkdir z &&
607 + echo b >z/b &&
608 + echo c >z/c &&
609 + echo d >z/d &&
610 + git add z &&
611 + test_tick &&
612 + git commit -m "O" &&
613 +
614 + git branch O &&
615 + git branch A &&
616 + git branch B &&
617 +
618 + git checkout A &&
619 + test_tick &&
620 + git commit --allow-empty -m "A" &&
621 +
622 + git checkout B &&
623 + mkdir y &&
624 + mkdir x &&
625 + git mv z/b y/ &&
626 + git mv z/c y/ &&
627 + git mv z/d x/ &&
628 + rmdir z &&
629 + test_tick &&
630 + git commit -m "B"
631 + )
632 +'
633 +
634 +test_expect_success '3a-check: Avoid implicit rename if involved as source on other side' '
635 + (
636 + cd 3a &&
637 +
638 + git checkout A^0 &&
639 +
640 + git merge -s recursive B^0 &&
641 +
642 + git ls-files -s >out &&
643 + test_line_count = 3 out &&
644 +
645 + git rev-parse >actual \
646 + HEAD:y/b HEAD:y/c HEAD:x/d &&
647 + git rev-parse >expect \
648 + O:z/b O:z/c O:z/d &&
649 + test_cmp expect actual
650 + )
651 +'
652 +
653 +# Testcase 3b, Avoid implicit rename if involved as source on other side
654 +# (Related to testcases 5c and 7c, also kind of 1e and 1f)
655 +# Commit O: z/{b,c,d}
656 +# Commit A: y/{b,c}, x/d
657 +# Commit B: z/{b,c}, w/d
658 +# Expected: y/{b,c}, CONFLICT:(z/d -> x/d vs. w/d)
659 +# NOTE: We're particularly checking that since z/d is already involved as
660 +# a source in a file rename on the same side of history, that we don't
661 +# get it involved in directory rename detection. If it were, we might
662 +# end up with CONFLICT:(z/d -> y/d vs. x/d vs. w/d), i.e. a
663 +# rename/rename/rename(1to3) conflict, which is just weird.
664 +test_expect_success '3b-setup: Avoid implicit rename if involved as source on current side' '
665 + test_create_repo 3b &&
666 + (
667 + cd 3b &&
668 +
669 + mkdir z &&
670 + echo b >z/b &&
671 + echo c >z/c &&
672 + echo d >z/d &&
673 + git add z &&
674 + test_tick &&
675 + git commit -m "O" &&
676 +
677 + git branch O &&
678 + git branch A &&
679 + git branch B &&
680 +
681 + git checkout A &&
682 + mkdir y &&
683 + mkdir x &&
684 + git mv z/b y/ &&
685 + git mv z/c y/ &&
686 + git mv z/d x/ &&
687 + rmdir z &&
688 + test_tick &&
689 + git commit -m "A" &&
690 +
691 + git checkout B &&
692 + mkdir w &&
693 + git mv z/d w/ &&
694 + test_tick &&
695 + git commit -m "B"
696 + )
697 +'
698 +
699 +test_expect_success '3b-check: Avoid implicit rename if involved as source on current side' '
700 + (
701 + cd 3b &&
702 +
703 + git checkout A^0 &&
704 +
705 + test_must_fail git merge -s recursive B^0 >out &&
706 + test_i18ngrep CONFLICT.*rename/rename.*z/d.*x/d.*w/d out &&
707 + test_i18ngrep ! CONFLICT.*rename/rename.*y/d out &&
708 +
709 + git ls-files -s >out &&
710 + test_line_count = 5 out &&
711 + git ls-files -u >out &&
712 + test_line_count = 3 out &&
713 + git ls-files -o >out &&
714 + test_line_count = 1 out &&
715 +
716 + git rev-parse >actual \
717 + :0:y/b :0:y/c :1:z/d :2:x/d :3:w/d &&
718 + git rev-parse >expect \
719 + O:z/b O:z/c O:z/d O:z/d O:z/d &&
720 + test_cmp expect actual &&
721 +
722 + test_path_is_missing z/d &&
723 + git hash-object >actual \
724 + x/d w/d &&
725 + git rev-parse >expect \
726 + O:z/d O:z/d &&
727 + test_cmp expect actual
728 + )
729 +'
730 +
731 +###########################################################################
732 +# Rules suggested by section 3:
733 +#
734 +# Avoid directory-rename-detection for a path, if that path is the source
735 +# of a rename on either side of a merge.
736 +###########################################################################
737 +
738 test_done