Skip to content

Commit 84e74c6

Browse files
committed
Merge branch 'en/t6042-insane-merge-rename-testcases'
Various glitches in the heuristics of merge-recursive strategy have been documented in new tests. * en/t6042-insane-merge-rename-testcases: t6042: add testcase covering long chains of rename conflicts t6042: add testcase covering rename/rename(2to1)/delete/delete conflict t6042: add testcase covering rename/add/delete conflict type
2 parents 3a2a1dc + 651f7f3 commit 84e74c6

File tree

1 file changed

+245
-0
lines changed

1 file changed

+245
-0
lines changed

t/t6042-merge-rename-corner-cases.sh

Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,4 +693,249 @@ test_expect_success 'rename/rename/add-dest merge still knows about conflicting
693693
)
694694
'
695695

696+
# Testcase rad, rename/add/delete
697+
# Commit O: foo
698+
# Commit A: rm foo, add different bar
699+
# Commit B: rename foo->bar
700+
# Expected: CONFLICT (rename/add/delete), two-way merged bar
701+
702+
test_expect_success 'rad-setup: rename/add/delete conflict' '
703+
test_create_repo rad &&
704+
(
705+
cd rad &&
706+
echo "original file" >foo &&
707+
git add foo &&
708+
git commit -m "original" &&
709+
710+
git branch O &&
711+
git branch A &&
712+
git branch B &&
713+
714+
git checkout A &&
715+
git rm foo &&
716+
echo "different file" >bar &&
717+
git add bar &&
718+
git commit -m "Remove foo, add bar" &&
719+
720+
git checkout B &&
721+
git mv foo bar &&
722+
git commit -m "rename foo to bar"
723+
)
724+
'
725+
726+
test_expect_failure 'rad-check: rename/add/delete conflict' '
727+
(
728+
cd rad &&
729+
730+
git checkout B^0 &&
731+
test_must_fail git merge -s recursive A^0 >out 2>err &&
732+
733+
# Not sure whether the output should contain just one
734+
# "CONFLICT (rename/add/delete)" line, or if it should break
735+
# it into a pair of "CONFLICT (rename/delete)" and
736+
# "CONFLICT (rename/add)"; allow for either.
737+
test_i18ngrep "CONFLICT (rename.*add)" out &&
738+
test_i18ngrep "CONFLICT (rename.*delete)" out &&
739+
test_must_be_empty err &&
740+
741+
git ls-files -s >file_count &&
742+
test_line_count = 2 file_count &&
743+
git ls-files -u >file_count &&
744+
test_line_count = 2 file_count &&
745+
git ls-files -o >file_count &&
746+
test_line_count = 2 file_count &&
747+
748+
git rev-parse >actual \
749+
:2:bar :3:bar &&
750+
git rev-parse >expect \
751+
B:bar A:bar &&
752+
753+
test_cmp file_is_missing foo &&
754+
# bar should have two-way merged contents of the different
755+
# versions of bar; check that content from both sides is
756+
# present.
757+
grep original bar &&
758+
grep different bar
759+
)
760+
'
761+
762+
# Testcase rrdd, rename/rename(2to1)/delete/delete
763+
# Commit O: foo, bar
764+
# Commit A: rename foo->baz, rm bar
765+
# Commit B: rename bar->baz, rm foo
766+
# Expected: CONFLICT (rename/rename/delete/delete), two-way merged baz
767+
768+
test_expect_success 'rrdd-setup: rename/rename(2to1)/delete/delete conflict' '
769+
test_create_repo rrdd &&
770+
(
771+
cd rrdd &&
772+
echo foo >foo &&
773+
echo bar >bar &&
774+
git add foo bar &&
775+
git commit -m O &&
776+
777+
git branch O &&
778+
git branch A &&
779+
git branch B &&
780+
781+
git checkout A &&
782+
git mv foo baz &&
783+
git rm bar &&
784+
git commit -m "Rename foo, remove bar" &&
785+
786+
git checkout B &&
787+
git mv bar baz &&
788+
git rm foo &&
789+
git commit -m "Rename bar, remove foo"
790+
)
791+
'
792+
793+
test_expect_failure 'rrdd-check: rename/rename(2to1)/delete/delete conflict' '
794+
(
795+
cd rrdd &&
796+
797+
git checkout A^0 &&
798+
test_must_fail git merge -s recursive B^0 >out 2>err &&
799+
800+
# Not sure whether the output should contain just one
801+
# "CONFLICT (rename/rename/delete/delete)" line, or if it
802+
# should break it into three: "CONFLICT (rename/rename)" and
803+
# two "CONFLICT (rename/delete)" lines; allow for either.
804+
test_i18ngrep "CONFLICT (rename/rename)" out &&
805+
test_i18ngrep "CONFLICT (rename.*delete)" out &&
806+
test_must_be_empty err &&
807+
808+
git ls-files -s >file_count &&
809+
test_line_count = 2 file_count &&
810+
git ls-files -u >file_count &&
811+
test_line_count = 2 file_count &&
812+
git ls-files -o >file_count &&
813+
test_line_count = 2 file_count &&
814+
815+
git rev-parse >actual \
816+
:2:baz :3:baz &&
817+
git rev-parse >expect \
818+
O:foo O:bar &&
819+
820+
test_cmp file_is_missing foo &&
821+
test_cmp file_is_missing bar &&
822+
# baz should have two-way merged contents of the original
823+
# contents of foo and bar; check that content from both sides
824+
# is present.
825+
grep foo baz &&
826+
grep bar baz
827+
)
828+
'
829+
830+
# Testcase mod6, chains of rename/rename(1to2) and rename/rename(2to1)
831+
# Commit O: one, three, five
832+
# Commit A: one->two, three->four, five->six
833+
# Commit B: one->six, three->two, five->four
834+
# Expected: six CONFLICT(rename/rename) messages, each path in two of the
835+
# multi-way merged contents found in two, four, six
836+
837+
test_expect_success 'mod6-setup: chains of rename/rename(1to2) and rename/rename(2to1)' '
838+
test_create_repo mod6 &&
839+
(
840+
cd mod6 &&
841+
test_seq 11 19 >one &&
842+
test_seq 31 39 >three &&
843+
test_seq 51 59 >five &&
844+
git add . &&
845+
test_tick &&
846+
git commit -m "O" &&
847+
848+
git branch O &&
849+
git branch A &&
850+
git branch B &&
851+
852+
git checkout A &&
853+
test_seq 10 19 >one &&
854+
echo 40 >>three &&
855+
git add one three &&
856+
git mv one two &&
857+
git mv three four &&
858+
git mv five six &&
859+
test_tick &&
860+
git commit -m "A" &&
861+
862+
git checkout B &&
863+
echo 20 >>one &&
864+
echo forty >>three &&
865+
echo 60 >>five &&
866+
git add one three five &&
867+
git mv one six &&
868+
git mv three two &&
869+
git mv five four &&
870+
test_tick &&
871+
git commit -m "B"
872+
)
873+
'
874+
875+
test_expect_failure 'mod6-check: chains of rename/rename(1to2) and rename/rename(2to1)' '
876+
(
877+
cd mod6 &&
878+
879+
git checkout A^0 &&
880+
881+
test_must_fail git merge -s recursive B^0 >out 2>err &&
882+
883+
test_i18ngrep "CONFLICT (rename/rename)" out &&
884+
test_must_be_empty err &&
885+
886+
git ls-files -s >file_count &&
887+
test_line_count = 6 file_count &&
888+
git ls-files -u >file_count &&
889+
test_line_count = 6 file_count &&
890+
git ls-files -o >file_count &&
891+
test_line_count = 3 file_count &&
892+
893+
test_seq 10 20 >merged-one &&
894+
test_seq 51 60 >merged-five &&
895+
# Determine what the merge of three would give us.
896+
test_seq 30 40 >three-side-A &&
897+
test_seq 31 39 >three-side-B &&
898+
echo forty >three-side-B &&
899+
>empty &&
900+
test_must_fail git merge-file \
901+
-L "HEAD" \
902+
-L "" \
903+
-L "B^0" \
904+
three-side-A empty three-side-B &&
905+
sed -e "s/^\([<=>]\)/\1\1\1/" three-side-A >merged-three &&
906+
907+
# Verify the index is as expected
908+
git rev-parse >actual \
909+
:2:two :3:two \
910+
:2:four :3:four \
911+
:2:six :3:six &&
912+
git hash-object >expect \
913+
merged-one merged-three \
914+
merged-three merged-five \
915+
merged-five merged-one &&
916+
test_cmp expect actual &&
917+
918+
git cat-file -p :2:two >expect &&
919+
git cat-file -p :3:two >other &&
920+
test_must_fail git merge-file \
921+
-L "HEAD" -L "" -L "B^0" \
922+
expect empty other &&
923+
test_cmp expect two &&
924+
925+
git cat-file -p :2:four >expect &&
926+
git cat-file -p :3:four >other &&
927+
test_must_fail git merge-file \
928+
-L "HEAD" -L "" -L "B^0" \
929+
expect empty other &&
930+
test_cmp expect four &&
931+
932+
git cat-file -p :2:six >expect &&
933+
git cat-file -p :3:six >other &&
934+
test_must_fail git merge-file \
935+
-L "HEAD" -L "" -L "B^0" \
936+
expect empty other &&
937+
test_cmp expect six
938+
)
939+
'
940+
696941
test_done

0 commit comments

Comments
 (0)