Merge commit
1137fddf4079a49c28b7735f4216e02737257cf0
Merge branch 'en/midx-missing-pack-fallback'
The object lookup machinery has been taught to gracefully recover when a multi-pack-index points to an owning pack that was removed during a concurrent geometric repack, and 'git replay' has been fixed to not segfault when reading such missing objects. * en/midx-missing-pack-fallback: packfile: recover when a multi-pack-index names a removed pack mktree: do not use OBJECT_INFO_QUICK when checking objects mktree: plug per-tree leak in --batch mode replay: fail gracefully when a merge input is unreadable
Junio C Hamano <gitster@pobox.com> · 2026-09-10 12:36 UTC
Combined diff: only what this merge did beyond taking one side. Added lines are colored by the parent they came from; bold lines came from none of them; removed lines are red.
1 file changed,
+130
−0
modified t/t3650-replay-basics.sh
| @@@ -576,100 -565,38 +576,134 @@@ test_expect_success '--onto with --ref | ||
| 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 branches' ' |
| 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 branches" 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_expect_success 'replay fails without segfault when objects are missing' ' |
| 676 | + | test_when_finished "rm -fr unreadable" && |
| 677 | + | git init unreadable && |
| 678 | + | ( |
| 679 | + | cd unreadable && |
| 680 | + | |
| 681 | + | test_write_lines l1 l2 l3 l4 l5 l6 l7 l8 >f && |
| 682 | + | git add f && |
| 683 | + | git commit -m base && |
| 684 | + | git branch base && |
| 685 | + | |
| 686 | + | test_write_lines l1 l2 l3 l4 l5 l6 l7 CHANGED >f && |
| 687 | + | git commit -am side && |
| 688 | + | git branch side && |
| 689 | + | |
| 690 | + | git switch -c onto base && |
| 691 | + | test_write_lines CHANGED l2 l3 l4 l5 l6 l7 l8 >f && |
| 692 | + | git commit -am onto && |
| 693 | + | |
| 694 | + | # The replay works while every object is readable. |
| 695 | + | git replay --onto onto base..side && |
| 696 | + | |
| 697 | + | # Removing the onto tree makes parse_tree() fail during the |
| 698 | + | # incore merge, driving clean < 0 with a NULL result tree. |
| 699 | + | onto_tree=$(git rev-parse onto^{tree}) && |
| 700 | + | obj=$(test_oid_to_path "$onto_tree") && |
| 701 | + | mv .git/objects/${obj} saved-tree && |
| 702 | + | |
| 703 | + | # Ensure replay gracefully handles the missing object |
| 704 | + | test_must_fail git replay --onto onto base..side 2>err && |
| 705 | + | test_grep -e "Could not read" -e "collecting merge info failed" err |
| 706 | + | ) |
| 707 | + | ' |
| 708 | + | |
| 709 | test_done | |