@@ -11,14 +11,13 @@ test_description="remember regular & dir renames in sequence of merges"
1111# sure that we are triggering rename caching rather than rename
1212# bypassing.
1313#
14- # NOTE 2: this testfile uses 'test-tool fast-rebase' instead of either
15- # cherry-pick or rebase. sequencer.c is only superficially
16- # integrated with merge-ort; it calls merge_switch_to_result()
17- # after EACH merge, which updates the index and working copy AND
18- # throws away the cached results (because merge_switch_to_result()
19- # is only supposed to be called at the end of the sequence).
20- # Integrating them more deeply is a big task, so for now the tests
21- # use 'test-tool fast-rebase'.
14+ # NOTE 2: this testfile uses replay instead of either cherry-pick or rebase.
15+ # sequencer.c is only superficially integrated with merge-ort; it
16+ # calls merge_switch_to_result() after EACH merge, which updates the
17+ # index and working copy AND throws away the cached results (because
18+ # merge_switch_to_result() is only supposed to be called at the end
19+ # of the sequence). Integrating them more deeply is a big task, so
20+ # for now the tests use 'git replay'.
2221#
2322
2423
@@ -769,4 +768,82 @@ test_expect_success 'avoid assuming we detected renames' '
769768 )
770769'
771770
771+ #
772+ # In the following testcase:
773+ # Base: olddir/{valuesX_1, valuesY_1, valuesZ_1}
774+ # other/content
775+ # Upstream: rename olddir/valuesX_1 -> newdir/valuesX_2
776+ # Topic_1: modify olddir/valuesX_1 -> olddir/valuesX_3
777+ # Topic_2: modify olddir/valuesY,
778+ # modify other/content
779+ # Expected Pick1: olddir/{valuesY, valuesZ}, newdir/valuesX, other/content
780+ # Expected Pick2: olddir/{valuesY, valuesZ}, newdir/valuesX, other/content
781+ #
782+ # This testcase presents no problems for git traditionally, but the fact that
783+ # olddir/valuesX -> newdir/valuesX
784+ # gets cached after the first pick presents a problem for the second commit to
785+ # be replayed, because it appears to be an irrelevant rename, so the trivial
786+ # directory resolution will resolve newdir/ without recursing into it, giving
787+ # us no way to apply the cached rename to anything.
788+ #
789+ test_expect_success ' rename a file, use it on first pick, but irrelevant on second' '
790+ git init rename_a_file_use_it_once_irrelevant_on_second &&
791+ (
792+ cd rename_a_file_use_it_once_irrelevant_on_second &&
793+
794+ mkdir olddir/ other/ &&
795+ test_seq 3 8 >olddir/valuesX &&
796+ test_seq 3 8 >olddir/valuesY &&
797+ test_seq 3 8 >olddir/valuesZ &&
798+ printf "%s\n" A B C D E F G >other/content &&
799+ git add olddir other &&
800+ git commit -m orig &&
801+
802+ git branch upstream &&
803+ git branch topic &&
804+
805+ git switch upstream &&
806+ test_seq 1 8 >olddir/valuesX &&
807+ git add olddir &&
808+ mkdir newdir &&
809+ git mv olddir/valuesX newdir &&
810+ git commit -m "Renamed (and modified) olddir/valuesX into newdir/" &&
811+
812+ git switch topic &&
813+
814+ test_seq 3 10 >olddir/valuesX &&
815+ git add olddir &&
816+ git commit -m A &&
817+
818+ test_seq 1 8 >olddir/valuesY &&
819+ printf "%s\n" A B C D E F G H I >other/content &&
820+ git add olddir/valuesY other &&
821+ git commit -m B &&
822+
823+ #
824+ # Actual testing; mostly we want to verify that we do not hit
825+ # git: merge-ort.c:3032: process_renames: Assertion `newinfo && !newinfo->merged.clean` failed.
826+ #
827+
828+ git switch upstream &&
829+ git config merge.directoryRenames true &&
830+
831+ git replay --onto HEAD upstream~1..topic >out &&
832+
833+ #
834+ # ...but we may as well check that the replay gave us a reasonable result
835+ #
836+
837+ git update-ref --stdin <out &&
838+ git checkout topic &&
839+
840+ git ls-files >tracked &&
841+ test_line_count = 4 tracked &&
842+ test_path_is_file newdir/valuesX &&
843+ test_path_is_file olddir/valuesY &&
844+ test_path_is_file olddir/valuesZ &&
845+ test_path_is_file other/content
846+ )
847+ '
848+
772849test_done
0 commit comments