Commit 261d47bc authored by Sean McGivern's avatar Sean McGivern Committed by Fatih Acet

Fix specs

- Add match line header to expected result for `File#sections`.
- Lowercase CSS colours.
- Remove unused `diff_refs` keyword argument.
- Rename `parent` -> `parent_file`, to be more explicit.
- Skip an iteration when highlighting.
parent 6f3501fe
$head_line: #EFFDEB; $head_line: #effdeb;
$head_gutter: #DAFACE; $head_gutter: #daface;
$selected_head_gutter: #B2EE9E; $selected_head_gutter: #b2ee9e;
$selected_head_line: #D4F5C9; $selected_head_line: #d4f5c9;
$origin_line: #F2F9FF; $origin_line: #f2f9ff;
$origin_gutter: #E0F0FF; $origin_gutter: #e0f0ff;
$selected_origin_gutter: #A3D3FF; $selected_origin_gutter: #a3d3ff;
$selected_origin_line: #CEE4F9; $selected_origin_line: #cee4f9;
$unselected_gutter: #EEEEEE; $unselected_gutter: #eeeeee;
$unselected_line: #F8F8F8; $unselected_line: #f8f8f8;
#conflicts { #conflicts {
......
...@@ -6,14 +6,12 @@ module Gitlab ...@@ -6,14 +6,12 @@ module Gitlab
CONTEXT_LINES = 3 CONTEXT_LINES = 3
attr_reader :merge_file_result, :their_path, :their_ref, :our_path, :our_ref, :repository attr_reader :merge_file_result, :their_path, :our_path, :repository
def initialize(merge_file_result, conflict, diff_refs:, repository:) def initialize(merge_file_result, conflict, repository:)
@merge_file_result = merge_file_result @merge_file_result = merge_file_result
@their_path = conflict[:theirs][:path] @their_path = conflict[:theirs][:path]
@our_path = conflict[:ours][:path] @our_path = conflict[:ours][:path]
@their_ref = diff_refs.start_sha
@our_ref = diff_refs.head_sha
@repository = repository @repository = repository
end end
...@@ -22,7 +20,7 @@ module Gitlab ...@@ -22,7 +20,7 @@ module Gitlab
@lines ||= Gitlab::Conflict::Parser.new.parse(merge_file_result[:data], @lines ||= Gitlab::Conflict::Parser.new.parse(merge_file_result[:data],
our_path: our_path, our_path: our_path,
their_path: their_path, their_path: their_path,
parent: self) parent_file: self)
end end
def resolve!(resolution, index:, rugged:) def resolve!(resolution, index:, rugged:)
...@@ -62,14 +60,14 @@ module Gitlab ...@@ -62,14 +60,14 @@ module Gitlab
their_file = lines.reject { |line| line.type == 'new' }.map(&:text).join("\n") their_file = lines.reject { |line| line.type == 'new' }.map(&:text).join("\n")
our_file = lines.reject { |line| line.type == 'old' }.map(&:text).join("\n") our_file = lines.reject { |line| line.type == 'old' }.map(&:text).join("\n")
their_highlight = Gitlab::Highlight.highlight(their_path, their_file, repository: repository).lines.map(&:html_safe) their_highlight = Gitlab::Highlight.highlight(their_path, their_file, repository: repository).lines
our_highlight = Gitlab::Highlight.highlight(our_path, our_file, repository: repository).lines.map(&:html_safe) our_highlight = Gitlab::Highlight.highlight(our_path, our_file, repository: repository).lines
lines.each do |line| lines.each do |line|
if line.type == 'old' if line.type == 'old'
line.rich_text = their_highlight[line.old_line - 1] line.rich_text = their_highlight[line.old_line - 1].html_safe
else else
line.rich_text = our_highlight[line.new_line - 1] line.rich_text = our_highlight[line.new_line - 1].html_safe
end end
end end
end end
...@@ -82,8 +80,6 @@ module Gitlab ...@@ -82,8 +80,6 @@ module Gitlab
end end
chunked_lines = lines.chunk { |line| line.type.nil? } chunked_lines = lines.chunk { |line| line.type.nil? }
last_candidate_match_header = nil
match_line_header = nil
match_line = nil match_line = nil
@sections = chunked_lines.flat_map.with_index do |(no_conflict, lines), i| @sections = chunked_lines.flat_map.with_index do |(no_conflict, lines), i|
......
...@@ -46,7 +46,6 @@ module Gitlab ...@@ -46,7 +46,6 @@ module Gitlab
Gitlab::Conflict::File.new(merge_index.merge_file(conflict[:ours][:path]), Gitlab::Conflict::File.new(merge_index.merge_file(conflict[:ours][:path]),
conflict, conflict,
diff_refs: merge_request.diff_refs,
repository: repository) repository: repository)
end end
end end
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
class UnmergeableFile < ParserError class UnmergeableFile < ParserError
end end
def parse(text, our_path:, their_path:, parent: nil) def parse(text, our_path:, their_path:, parent_file: nil)
raise UnmergeableFile if text.blank? # Typically a binary file raise UnmergeableFile if text.blank? # Typically a binary file
raise UnmergeableFile if text.length > 102400 raise UnmergeableFile if text.length > 102400
...@@ -43,9 +43,9 @@ module Gitlab ...@@ -43,9 +43,9 @@ module Gitlab
type = nil type = nil
elsif line[0] == '\\' elsif line[0] == '\\'
type = 'nonewline' type = 'nonewline'
lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent: parent) lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: parent_file)
else else
lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent: parent) lines << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: parent_file)
line_old += 1 if type != 'new' line_old += 1 if type != 'new'
line_new += 1 if type != 'old' line_new += 1 if type != 'old'
......
...@@ -5,10 +5,10 @@ module Gitlab ...@@ -5,10 +5,10 @@ module Gitlab
attr_writer :rich_text attr_writer :rich_text
attr_accessor :text attr_accessor :text
def initialize(text, type, index, old_pos, new_pos, parent: nil) def initialize(text, type, index, old_pos, new_pos, parent_file: nil)
@text, @type, @index = text, type, index @text, @type, @index = text, type, index
@old_pos, @new_pos = old_pos, new_pos @old_pos, @new_pos = old_pos, new_pos
@parent = parent @parent_file = parent_file
end end
def self.init_from_hash(hash) def self.init_from_hash(hash)
...@@ -46,7 +46,7 @@ module Gitlab ...@@ -46,7 +46,7 @@ module Gitlab
end end
def rich_text def rich_text
@parent.highlight_lines! if @parent && !@rich_text @parent_file.highlight_lines! if @parent_file && !@rich_text
@rich_text @rich_text
end end
......
...@@ -5,12 +5,11 @@ describe Gitlab::Conflict::File, lib: true do ...@@ -5,12 +5,11 @@ describe Gitlab::Conflict::File, lib: true do
let(:repository) { project.repository } let(:repository) { project.repository }
let(:rugged) { repository.rugged } let(:rugged) { repository.rugged }
let(:their_commit) { rugged.branches['conflict-a'].target } let(:their_commit) { rugged.branches['conflict-a'].target }
let(:diff_refs) { Gitlab::Diff::DiffRefs.new(base_sha: their_commit.oid, head_sha: our_commit.oid) }
let(:our_commit) { rugged.branches['conflict-b'].target } let(:our_commit) { rugged.branches['conflict-b'].target }
let(:index) { rugged.merge_commits(our_commit, their_commit) } let(:index) { rugged.merge_commits(our_commit, their_commit) }
let(:conflict) { index.conflicts.last } let(:conflict) { index.conflicts.last }
let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') } let(:merge_file_result) { index.merge_file('files/ruby/regex.rb') }
let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, diff_refs: diff_refs, repository: repository) } let(:conflict_file) { Gitlab::Conflict::File.new(merge_file_result, conflict, repository: repository) }
describe '#resolve_lines' do describe '#resolve_lines' do
let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact } let(:section_keys) { conflict_file.sections.map { |section| section[:id] }.compact }
...@@ -92,7 +91,7 @@ describe Gitlab::Conflict::File, lib: true do ...@@ -92,7 +91,7 @@ describe Gitlab::Conflict::File, lib: true do
expect(section[:conflict]).to be_falsey expect(section[:conflict]).to be_falsey
expect(match_line.type).to eq('match') expect(match_line.type).to eq('match')
expect(match_line.text).to eq('@@ -46,53 +46,53 @@') expect(match_line.text).to eq('@@ -46,53 +46,53 @@ module Gitlab')
end end
it 'does not return match lines when there is no gap between sections' do it 'does not return match lines when there is no gap between sections' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment