Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
馃М Use merge refs for diffs
<!-- 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 -->
## Problem to solve
Merge request diffs are currently calculated by `git diff target...source` which compares `HEAD` of `target` with the merge base of `target` and `source`. This works well until changes from the target branch are merged in to the source branch, creating a complete mess of the diff.
For example, a fix is added directly to master, then cherry picked in to the master branch, the cherry picked change will be visible in the merge request. (https://gitlab.com/jramsay-reproduce/ce-15140/merge_requests/1/diffs)
```
X---C' feature-a
/
A---B---C master
```
See https://gitlab.com/gitlab-org/gitlab-ce/issues/15140#note_11709832 for a detailed description of the current behavior.
Docs: https://docs.gitlab.com/ee/development/diffs.html#merge-request-diffs-against-the-head-of-the-target-branch
## Further details
We added merge refs to allow pipelines to run on the merge ref https://gitlab.com/groups/gitlab-org/-/epics/848. We should also use merge refs for calculating the diff in the merge request interface.
## Proposal
Add a new diff option **master (HEAD)**, and rename current option to **master (BASE)**. Only the latest version can be compared with **master (HEAD)**.

Challenges:
- computing new diffs every time target branch is changed
- handling exceptions
- merge conflict
- rebase required
## Implementation Notes
Currently (as of 2020-11-24), when `master (HEAD)` option is selected, we calculate the merge ref head diff. Even if we have a particular type of conflicts (both sides modified the same line), we show the merge ref head diff. If, for some reason, we can't calculate merge ref head diff (an unsupported type of conflicts happened), then we fallback to `master (base)` diff.
In the case of conflicts a message is displayed that there are conflicts and the diff _may_ be inaccurate. Additional work to address handling these conflict cases and being able to reliably use the merge ref method is in https://gitlab.com/groups/gitlab-org/-/epics/4893
## Rollout Status
| Date | Details |
| ---- | ---- |
| 2020-11-24 | Currently the work for merge ref diffs is completed and behind a feature flag `:default_merge_ref_for_diffs`. Rollout to the `gitlab-org` and `gitlab-com` groups will be started and tracked via https://gitlab.com/gitlab-org/gitlab/-/issues/276917 |
| 2020-12-07 | Rollout is paused while investigation into issues with versions continues. Additional details are in https://gitlab.com/gitlab-org/gitlab/-/issues/276917#note_459912859 |
| 2020-12-09 | Rollout has been moved to backlog while investigation takes place in to [support for batch diffs](https://gitlab.com/gitlab-org/gitlab/-/issues/292507). Batch diffs are a significant performance gain, so putting them back in place is critical for moving forward |
| 2020-02-10 | Rollout for all of GitLab.com has been enabled and testing continues to ensure no issues for release. |
| 2020-02-24 | Merge refs were released as default to on in the GitLab 13.9 release! |
## Customers
- https://gitlab.my.salesforce.com/00161000011zcMR
- https://gitlab.my.salesforce.com/0016100000NmdfL
- https://gitlab.my.salesforce.com/0016100000UsL6E
- https://gitlab.my.salesforce.com/00161000002ylPm
- https://gitlab.my.salesforce.com/00161000004yKzp
- https://gitlab.my.salesforce.com/00161000004bZPD
- https://gitlab.my.salesforce.com/0016100000hk13h
- https://gitlab.my.salesforce.com/0016100001RE5Ol
- https://gitlab.my.salesforce.com/0016100001VtfCT
- https://gitlab.my.salesforce.com/0016100000XMmes
epic