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
Now that FF-merge trains exists I think much of the implementation could also be re-used as follows (no Gitaly changes required):
1. Use `MergeRequests::CreateRefService` to create a merge candidate ref, for example `refs/merge-requests/:iid/rebase-merge`
2. Perform a fast-forward merge from `refs/merge-requests/:iid/rebase-merge` into the target branch. If the target branch has been updated in the meantime, this would gracefully fail (in which case we could retry or display an error to the user).
## Further details
* The importance of this feature is magnified by both the requirement for CI pipelines to pass before merging.
* There is appetite to merge immediately after the rebase is successful without running CI. While some feel this should not be the default, those folks would like to have the option to make that desicion.
* This will not solve contention between many merge requests with slow pipelines. See https://gitlab.com/groups/gitlab-org/-/epics/4911 for `Merge Trains with Fast Forward Merge support`
---
<details>
<summary>Old proposal</summary>
- For the two merge request methods (`merge commit with semi-linear history` and `fast-forward merge`), offer the ability to rebase and merge in a single action.
- Note: For below, ~~strikethrough~~ indicates existing functionality that will be removed and **bold** indicates new functionality.
1. No pipeline exists (No GitLab CI set up)
* MR needs a rebase
- MR is non-rebaseable
* ~~Merge button, and an error after clicking the button~~
* **Access to source branch: _Rebase locally_ button that shows instructions (**[**button**](/uploads/f526c1bbaa4899f4d11a9b117c581eee/non-rebaseable--action.png)**; **[**instructions modal**](/uploads/582ed608ebdaa33cf457e136247ceafc/non-rebaseable--modal.png)**)** If rebase succeeds, show message “Ready to be merged automatically. Ask someone with write access to this repository to merge this request.”
* **No access to source branch: No buttons, only message to ask MR author to rebase locally (**[**message**](/uploads/5b0e34012861a2c4942aa3fed7a5f557/non-rebaseable--message.png)**)**
- MR is rebaseable
* Access to only source branch: _Rebase_ button ([rebase](/uploads/1e05c7fb6534f9646858b97943a0d780/rebaseable--rebase.png)) If rebase succeeds, show message “Ready to be merged automatically. Ask someone with write access to this repository to merge this request.”
* **Access to source AND target branch: _Merge_ and _Rebase only_ buttons. _Merge_ will auto-rebase+merge immediately. (**[**merge or rebase only**](/uploads/c88b7b51caeaf25d0560c0178e57308c/rebaseable--actions.png)**)** If _Rebase only_, after it succeeds, show _Merge_ button.
* **No access to source branch: No buttons, only message to ask MR author to rebase (**[**message**](/uploads/5ade79def160dc95131cc47044c469e7/rebaseable--message.png)**)**
* MR does not need a rebase
- Merge button
1. Pipeline running
* MR needs a rebase
- MR is non-rebaseable
* ~~Merge button, and an error after clicking the button~~
* **Access to source branch: _Rebase locally_ button that shows instructions (**[**button**](/uploads/f526c1bbaa4899f4d11a9b117c581eee/non-rebaseable--action.png)**; **[**instructions modal**](/uploads/582ed608ebdaa33cf457e136247ceafc/non-rebaseable--modal.png)**)** If rebase succeeds, show message “Ready to be merged automatically. Ask someone with write access to this repository to merge this request.”
* **No access to source branch: No buttons, only message to ask MR author to rebase locally (**[**message**](/uploads/5b0e34012861a2c4942aa3fed7a5f557/non-rebaseable--message.png)**)**
- MR is rebaseable
* Access to only source branch: _Rebase_ button ([rebase](/uploads/1e05c7fb6534f9646858b97943a0d780/rebaseable--rebase.png)) If rebase succeeds, show message “Ready to be merged automatically. Ask someone with write access to this repository to merge this request.”
* **Access to source AND target branch: _Merge_ (blue button) and _Rebase only_ buttons. _Merge_ will auto-rebase+merge immediately. (**[**merge or rebase only**](/uploads/c88b7b51caeaf25d0560c0178e57308c/rebaseable--actions.png)**)** If _Rebase only_, after it succeeds, show _Merge_ (blue) and _Merge when pipeline succeeds_ (orange) buttons.
* **No access to source branch: No buttons, only message to ask MR author to rebase (**[**message**](/uploads/5ade79def160dc95131cc47044c469e7/rebaseable--message.png)**)**
* _Not in scope: Merge when pipeline succeeds button (blue) that will auto-rebase+merge when pipeline succeeds_
* MR does not need a rebase
- _Merge when pipeline succeeds_ button (blue)
- _Merge_ button (orange) to merge immediately
1. Pipeline passed
* Same as _1. No pipeline exists_, above
1. Pipeline failed
* _Pending discussion_
</details>
## 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
## Links / references
_This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc._
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
*This page may contain information related to upcoming products, features and functionality.
It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes.
Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.*
<!-- triage-serverless v3 PLEASE DO NOT REMOVE THIS SECTION -->
issue