Rebase and Merge with One Click
## Problem When using **merge commit with semi-linear history** and **fast-forward merge** methods, if the target branch has changed since the source branch was created or last rebased, the source branch will need to be rebased before merging in order to merge according to the selected merge method. Currently, if GitLab detects a rebase is required, the users can click the **Rebase** button. Once the rebase is completed the **Merge** button will become available. This require more time as I have to return to MR to check when rebase is done and then merge. ## Proposal ### Auto rebase feature details When `Merge commit with semi-linear history` and `Fast-forward merge` merge methods are enabled, the source branch is automatically rebased prior to merging into the target branch. We will add a setting on the backend to toggle the above feature on and off. This is done to support some projects that may want to enforce that commit signatures are preserved. The setting will be enabled by default, and controlled by a checkbox on the frontend. ### Additional details We don't have to wait for pipelines to pass, since merging without an updated source branch is already allowed. We don't need to make any additional changes to handle auto rebase with merge trains. This has already been implemented here: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/136232 Currently, if squashing is required and fast-forward merge is selected as the merge method in a project's settings, adding auto rebase will fulfill the requirements for [Squash merge MRs without merge commit](https://gitlab.com/gitlab-org/gitlab/-/issues/1822). ### Implementation details Within `FromSourceBranch` we'll need to create an ephemeral commit in the same [way merge trains do](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/services/merge_trains/create_pipeline_service.rb#L28). After the ephemeral commit is created, do a `ff_merge` with the ephemeral commit as the source. Use `ff_merge` instead of `rebase` for safety (ff_merge uses `expected_old_oid` to ensure that the tip of the target branch is the same prior and after preparing the ephemeral commit) Within FromSourceBranch, we'll need to surface errors from CreateRefService (when creating the ephemeral commit fails), as well as when `ff_merge` fails (file conflict, history conflict). ### Issue breakdown @j.seto and I have broken this down into implementation issues in the parent epic. We've assigned them initial weights according to source code backend's weighting guidelines. Feel free to re-assign weights since code review will be doing the actual implementation. ## Customers * https://gitlab.my.salesforce.com/00161000002xBfL * https://gitlab.my.salesforce.com/0014M00001nHkqA * https://gitlab.my.salesforce.com/00161000004zrG3 * https://gitlab.my.salesforce.com/00161000004yLEy * https://gitlab.my.salesforce.com/0016100000fdr2y * https://gitlab.my.salesforce.com/00161000005cxCt * https://gitlab.my.salesforce.com/00161000002xBao ### Internal Roadmap Details <!-- start roadmap:details --> https://gitlab.com/groups/gitlab-org/-/epics/16803#note_2951739880 <!-- end roadmap:details -->
epic