Skip to content

Support Merging the merge train ref directly

Max Fan requested to merge 413104-allow-merges-from-train-ref into master

What does this MR do and why?

Adds a new merge strategy FromTrainRef that enables fast-forward merges from merge train refs. Unlike the existing FromSourceBranch merge strategy, no new commits are created during such a merge (they were all generated as part of the train ref).

The idea is that for Fast-Forward merges, the train ref will have all the changes as well as be rebased on top of the preceding car's changes. This way, when the pipeline passes for a merge train, it can be automatically merged without any additional git operations. With this change, we have working fast-forward merge trains (disabled behind a feature flag!) with a few known caveats:

  • The merge commit message is not yet correct, so only fast-forward merges are viable: #422197 (closed), #421588 (closed)
  • Non-squashed fast-forward merges are not linked back to a merge request: #418822 (closed)
  • The commit SHAs that do get linked can be incorrect if preferences have changed between ref creation and the eventual merge: #422483 (closed)
  • After the first merge of a 2+ car train, the UI warns about not being mergable even when a merge is viable (because the train automatically rebases internally): #420000 (closed)

Screenshots or screen recordings

Not yet...

Before After

How to set up and validate locally

  1. Enable the following three feature flags (Feature.enable(...) in a rails console):
    • refactor_merge_service: Required for the code added in this MR to be reachable at all (it depends on the refactoring)
    • merge_trains_create_ref_service: Required for the merge train ref to be properly constructed
    • fast_forward_merge_trains_support: Required for the new merge strategy to be used when merging fast-forward merge trains
  2. In a project of your choice, enable Merge Trains and set the merge method to Fast-Forward
  3. Add a .gitlab-ci.yml file with merge request pipelines to avoid duplicate pipelines:
    include:
    - template: 'Workflows/MergeRequest-Pipelines.gitlab-ci.yml'
    
    test:
      script: echo hi
  4. Create two or more merge requests. Merge them in sequence so that they create a merge train
  5. Verify that all the merge requests get merged, and that the target branch has the expected commit history

MR acceptance checklist

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

Related to #413104 (closed)

Edited by Hordur Freyr Yngvason

Merge request reports