Extract MergeService strategies into its own class
What does this MR do and why?
Currently MergeRequests::MergeService
is bloated, handling multiple responsibilities and relying on circular monkey patching inheritance. This makes it hard to expand and add new features.
This MR splits out the responsibility for the git merge operation into a class MergeRequests::MergeStrategies::FromSourceBranch
. This class is responsible for preparing the source for merge (including an optional squash), and performing the git merge operation (including determining whether a fast-forward or merge commit is needed). This leaves MergeRequests::MergeService
exclusively responsible for the reusable application logic associated with a merge, such as updating database models and triggering any post-merge actions.
The strategy for a merge is configurable, but currently FromSourceBranch
is the only available strategy. As a follow-up, we will add a FromTrainRef
strategy, which merges from a fully prepared commit SHA associated with a successful pipeline on a merge train.
This change is behind a Feature Flag.
Screenshots or screen recordings
N/A - refactoring, merge requests should still work
Before | After |
---|---|
How to set up and validate locally
- In a rails console, enable the feature flag:
Feature.enable(:refactor_merge_service)
- Pick a project for testing
- With standard merge commits enabled, merge a merge request
- With fast-forward merges enabled, merge a merge request
- With semi-linear merges enabled, merge a merge requst
- With a merge method of your choice, merge a merge request with a squash merge
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #420668 (closed)