Skip to content

Add service that can squash and rebase into merge request refs

What does this MR do and why?

Extracted from !122961 (closed) and improved upon.

The existing MergeRequests::MergeToRefService can only create merge commits. For merge trains and pipelines for merged results, we need a service that can prepare the ref to be exactly as the target branch would be if merged. This means that they need both squash and rebase support. To do so, we introduce a new service MergeRequests::CreateRefService, that combines a new RPC, UserRebaseToRef, with existing RPCs to create a merge request ref according to the project's merge preferences.

MergeRequests::CreateRefService provides a strict superset of the functionality in MergeRequests::MergeToRefService behind a uniform set of parameters. It should be able to eventually supersede MergeRequests::MergeToRefService entirely. In this MR, we introduce a feature flag that uses CreateRefService for merge trains, but we should presumably also do the same later for merged result pipelines.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. Check out this branch
  2. In a rails console, run
    Feature.enable(:merge_trains_create_ref_service)
  3. In a project, enable merge trains and allow squash merges
  4. For each available merge method, perform the following actions:
    1. Change to that merge method
    2. Create a merge request in this project
    3. Start a merge train. Arbitrarily decide whether to squash or not. Just don't do the same thing each time.
    4. Check the pipelines page. There should be a merge train for your merge request. Click the commit ref for this merge request.
    5. Verify that the commit message is what you expected.
    6. Change the /commit/ portion of the URL to /commits/ (plural) to browse the commit history
    7. Verify that the commit history is as expected for the given merge method.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hordur Freyr Yngvason

Merge request reports