Skip to content

Highlight conflicts with the rest of the diff

Patrick Bajao requested to merge 365823-highlight-conflicts-with-diffs into master

What does this MR do and why?

Introduces a new Gitlab::Conflict::DiffLinesInjecter that is responsible for mixing in conflicting lines to the diff lines.

This is needed so we can show the conflicts along with the other changes on the same file.

The approach here differs with how we were doing it before as we are now highlighting the actual merge head diff wherein conflict markers are present. Before this change, we were getting the conflict file and highlight its lines but that doesn't highlight the other changes made on the file.

This is behind display_merge_conflicts_in_diff feature flag.

Screenshots or screen recordings

In a MR that has a diff like this:

diff --git a/CHANGE.md b/CHANGE.md
index 7f2d0650e6d0785a5eb0b5d19a2b1c634dd5035c..3997adaa696b31f15b1e90543f47d4b25b954345 100644
--- a/CHANGE.md
+++ b/CHANGE.md
@@ -1,2 +1,4 @@
+Change
 
+our
 end

And the our line conflicts with changes on the target branch. It'll look like this:

Before After
before after

In the After screenshot, you can see the Change line is being highlighted with the conflicts. Before, we aren't highlighting it.

How to set up and validate locally

  1. Enabled the display_merge_conflicts_in_diff feature flag:
    Feature.enable(:display_merge_conflicts_in_diff)
  2. Create a file.
  3. Update the file with multiple changes and open a MR.
  4. Update the file on the MR's target branch and make a change that will cause a conflict with the changes on the MR.
  5. View the MR and the conflicts should be shown on the page along with the other changes on the file.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #365823 (closed)

Edited by Patrick Bajao

Merge request reports