Fix merge immediately allowing outdated branches with semi-linear history
What does this MR do and why?
Fixes #573986
The should_be_rebased? method in ee/app/models/ee/merge_request.rb was incorrectly returning false for projects using merge trains with fast-forward merge strategy. This guard was added because merge trains rebase automatically, but this assumption does not hold for the "merge immediately" functionality.
Problem
When a project has:
- Merge method set to "Merge commit with semi-linear history"
- Merge trains enabled
- "Allow skipping the merge train" setting disabled
The "Merge immediately" button was still available even when the source branch was outdated and needed to be rebased. This violates the semi-linear history requirement.
Solution
This MR removes the guard that checks MergeTrains::Train.project_using_ff?(target_project) from the should_be_rebased? method. The check for whether an MR is on a fast-forward train (merge_train_car&.on_ff_train?) is preserved to handle the case where the MR is actively on the train.
How to set up and validate locally
- Create a project with:
- Merge method: "Merge commit with semi-linear history"
- Enable merge trains
- Disable "Allow skipping the merge train"
- Create a merge request
- Make changes to the target branch so the MR becomes outdated
- Verify that "Merge immediately" is not available (or shows a rebase requirement)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.