52
test_merge P O --no-ff &&
53
git switch main &&
54
55
+ git switch --orphan unrelated &&
56
+ test_commit unrelated-root &&
57
+
58
git switch -c conflict B &&
56
- test_commit C.conflict C.t conflict
59
+ test_commit C.conflict C.t conflict &&
60
+ git branch -D unrelated &&
61
+
62
+ git switch -c divergent-x main &&
63
+ test_commit X &&
64
+ git switch -c divergent-y main &&
65
+ test_commit Y &&
66
+ git switch divergent-x &&
67
+ test_merge Z divergent-y --no-ff
68
'
69
70
test_expect_success 'setup bare' '
576
test_grep "cannot be used with multiple revision ranges" err
577
'
578
579
+test_expect_success 'replay to rebase merge commit with --linearize' '
580
+ git replay --ref-action=print --linearize \
581
+ --onto main I..topic-with-merge >result &&
582
+
583
+ test_line_count = 1 result &&
584
+
585
+ git log --format=%s $(cut -f 3 -d " " result) >actual &&
586
+ test_write_lines O N J M L B A >expect &&
587
+ test_cmp expect actual
588
+'
589
+
590
+test_expect_success 'replay to rebase merge commit with --linearize down to the root commit' '
591
+ git replay --ref-action=print --linearize \
592
+ --onto unrelated-root topic-with-merge >result &&
593
+
594
+ test_line_count = 1 result &&
595
+
596
+ git log --format=%s $(cut -f 3 -d " " result) >actual &&
597
+ test_write_lines O N J I B A unrelated-root >expect &&
598
+ test_cmp expect actual
599
+'
600
+
601
+test_expect_success 'replay to cherry-pick merge commit with --linearize' '
602
+ git replay --ref-action=print --linearize \
603
+ --advance main I..topic-with-merge >result &&
604
+
605
+ test_line_count = 1 result &&
606
+
607
+ git log --format=%s $(cut -f 3 -d " " result) >actual &&
608
+ test_write_lines O N J M L B A >expect &&
609
+ test_cmp expect actual &&
610
+
611
+ printf "update refs/heads/main " >expect &&
612
+ printf "%s " $(cut -f 3 -d " " result) >>expect &&
613
+ git rev-parse main >>expect &&
614
+ test_cmp expect result
615
+'
616
+
617
+test_expect_success 'replay --linearize produces the same patches' '
618
+ git replay --ref-action=print --linearize \
619
+ --onto main I..topic-with-merge >result &&
620
+
621
+ test_line_count = 1 result &&
622
+ tip=$(cut -f 3 -d " " result) &&
623
+
624
+ # range-diff does not care about the dropped merge,
625
+ # so the original commits (I..topic-with-merge)
626
+ # and the replayed chain (main..tip) must produce identical patches.
627
+ git range-diff I..topic-with-merge main..$tip >out &&
628
+ test_file_not_empty out &&
629
+ test_grep ! -v "=" out &&
630
+
631
+ git log --oneline main..$tip >out &&
632
+ test_line_count = 3 out
633
+'
634
+
635
+test_expect_success '--linearize rejects multiple revision ranges' '
636
+ test_must_fail git replay --ref-action=print --linearize \
637
+ --onto main ^B topic2 topic3 topic4 2>err &&
638
+ test_grep "cannot be used with multiple revision ranges" err
639
+'
640
+
641
+test_expect_success 'replay with --linearize of a divergent merge keeps both sides' '
642
+ git replay --ref-action=print --linearize \
643
+ --onto main main..divergent-x >result &&
644
+ test_line_count = 1 result &&
645
+ tip=$(cut -f 3 -d " " result) &&
646
+
647
+ # The merge Z is dropped, but both X and Y are linearized onto main;
648
+ # neither side is lost.
649
+ git log --format=%s main..$tip >actual &&
650
+ test_write_lines Y X >expect &&
651
+ test_cmp expect actual
652
+'
653
+
654
+test_expect_success '--linearize and --contained cannot be used together' '
655
+ test_must_fail git replay --ref-action=print --linearize --contained \
656
+ --onto main ^B topic-with-merge 2>err &&
657
+ test_grep "cannot be used together" err
658
+'
659
+
660
+test_expect_success 'replay --revert with --linearize reverts a range containing a merge' '
661
+ git replay --ref-action=print --revert=divergent-x --linearize \
662
+ main..divergent-x >result &&
663
+ test_line_count = 1 result &&
664
+ tip=$(cut -f 3 -d " " result) &&
665
+
666
+ git log --format=%s $tip >actual &&
667
+ test_write_lines \
668
+ "Revert \"X\"" "Revert \"Y\"" Z Y X M L B A >expect &&
669
+ test_cmp expect actual &&
670
+
671
+ test_must_fail git cat-file -e $tip:X.t &&
672
+ test_must_fail git cat-file -e $tip:Y.t
673
+'
674
+
675
test_done