diff options
author | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2021-01-20 22:34:23 +0300 |
commit | 6438df3a1e0fb944485cebf07976160184697d72 (patch) | |
tree | 00b09bfd170e77ae9391b1a2f5a93ef6839f2597 /lib/gitlab/conflict | |
parent | 42bcd54d971da7ef2854b896a7b34f4ef8601067 (diff) |
Add latest changes from gitlab-org/gitlab@13-8-stable-eev13.8.0-rc42
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r-- | lib/gitlab/conflict/file.rb | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/gitlab/conflict/file.rb b/lib/gitlab/conflict/file.rb index 4d7590a8e38..fbf021345ca 100644 --- a/lib/gitlab/conflict/file.rb +++ b/lib/gitlab/conflict/file.rb @@ -9,9 +9,13 @@ module Gitlab CONTEXT_LINES = 3 + CONFLICT_MARKER_OUR = 'conflict_marker_our' + CONFLICT_MARKER_THEIR = 'conflict_marker_their' + CONFLICT_MARKER_SEPARATOR = 'conflict_marker' + CONFLICT_TYPES = { - "old" => "conflict_marker_their", - "new" => "conflict_marker_our" + "old" => "conflict_their", + "new" => "conflict_our" }.freeze attr_reader :merge_request @@ -59,18 +63,25 @@ module Gitlab if section[:conflict] lines = [] - initial_type = nil + lines << create_separator_line(section[:lines].first, CONFLICT_MARKER_OUR) + + current_type = section[:lines].first.type section[:lines].each do |line| - if line.type != initial_type - lines << create_separator_line(line) - initial_type = line.type + if line.type != current_type # insert a separator between our changes and theirs + lines << create_separator_line(line, CONFLICT_MARKER_SEPARATOR) + current_type = line.type end line.type = CONFLICT_TYPES[line.type] + + # Swap the positions around due to conflicts/diffs display inconsistency + # https://gitlab.com/gitlab-org/gitlab/-/issues/291989 + line.old_pos, line.new_pos = line.new_pos, line.old_pos + lines << line end - lines << create_separator_line(lines.last) + lines << create_separator_line(lines.last, CONFLICT_MARKER_THEIR) lines else @@ -156,8 +167,8 @@ module Gitlab Gitlab::Diff::Line.new('', 'match', line.index, line.old_pos, line.new_pos) end - def create_separator_line(line) - Gitlab::Diff::Line.new('', 'conflict_marker', line.index, nil, nil) + def create_separator_line(line, type) + Gitlab::Diff::Line.new('', type, line.index, nil, nil) end # Any line beginning with a letter, an underscore, or a dollar can be used in a |