Don't display comment on unchanged line on both sides in parallel diff
This commit is contained in:
parent
c0c3942628
commit
5e8aca2152
|
|
@ -66,12 +66,12 @@ module DiffHelper
|
|||
|
||||
discussions_left = discussions_right = nil
|
||||
|
||||
if left && (left.unchanged? || left.discussable?)
|
||||
if left && left.discussable? && (left.unchanged? || left.removed?)
|
||||
line_code = diff_file.line_code(left)
|
||||
discussions_left = @grouped_diff_discussions[line_code]
|
||||
end
|
||||
|
||||
if right&.discussable?
|
||||
if right && right.discussable? && right.added?
|
||||
line_code = diff_file.line_code(right)
|
||||
discussions_right = @grouped_diff_discussions[line_code]
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class LegacyDiffNote < Note
|
|||
end
|
||||
|
||||
def for_line?(line)
|
||||
!line.meta? && diff_file.line_code(line) == self.line_code
|
||||
line.discussable? && diff_file.line_code(line) == self.line_code
|
||||
end
|
||||
|
||||
def original_line_code
|
||||
|
|
|
|||
|
|
@ -42,11 +42,19 @@ module Gitlab
|
|||
end
|
||||
|
||||
def added?
|
||||
type == 'new' || type == 'new-nonewline'
|
||||
%w[new new-nonewline].include?(type)
|
||||
end
|
||||
|
||||
def removed?
|
||||
type == 'old' || type == 'old-nonewline'
|
||||
%w[old old-nonewline].include?(type)
|
||||
end
|
||||
|
||||
def meta?
|
||||
%w[match new-nonewline old-nonewline].include?(type)
|
||||
end
|
||||
|
||||
def discussable?
|
||||
!meta?
|
||||
end
|
||||
|
||||
def rich_text
|
||||
|
|
@ -55,14 +63,6 @@ module Gitlab
|
|||
@rich_text
|
||||
end
|
||||
|
||||
def meta?
|
||||
type == 'match'
|
||||
end
|
||||
|
||||
def discussable?
|
||||
!['match', 'new-nonewline', 'old-nonewline'].include?(type)
|
||||
end
|
||||
|
||||
def as_json(opts = nil)
|
||||
{
|
||||
type: type,
|
||||
|
|
|
|||
|
|
@ -14,16 +14,7 @@ module Gitlab
|
|||
lines = []
|
||||
highlighted_diff_lines = diff_file.highlighted_diff_lines
|
||||
highlighted_diff_lines.each do |line|
|
||||
if line.meta? || line.unchanged?
|
||||
# line in the right panel is the same as in the left one
|
||||
lines << {
|
||||
left: line,
|
||||
right: line
|
||||
}
|
||||
|
||||
free_right_index = nil
|
||||
i += 1
|
||||
elsif line.removed?
|
||||
if line.removed?
|
||||
lines << {
|
||||
left: line,
|
||||
right: nil
|
||||
|
|
@ -51,6 +42,15 @@ module Gitlab
|
|||
free_right_index = nil
|
||||
i += 1
|
||||
end
|
||||
elsif line.meta? || line.unchanged?
|
||||
# line in the right panel is the same as in the left one
|
||||
lines << {
|
||||
left: line,
|
||||
right: line
|
||||
}
|
||||
|
||||
free_right_index = nil
|
||||
i += 1
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -148,12 +148,21 @@ describe DiffHelper do
|
|||
|
||||
it 'puts comments on added lines' do
|
||||
left = Gitlab::Diff::Line.new('\\nonewline', 'old-nonewline', 3, 3, 3)
|
||||
right = Gitlab::Diff::Line.new('new line', 'add', 3, 3, 3)
|
||||
right = Gitlab::Diff::Line.new('new line', 'new', 3, 3, 3)
|
||||
|
||||
result = helper.parallel_diff_discussions(left, right, diff_file)
|
||||
|
||||
expect(result).to eq([nil, 'comment'])
|
||||
end
|
||||
|
||||
it 'puts comments on unchanged lines' do
|
||||
left = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3)
|
||||
right = Gitlab::Diff::Line.new('unchanged line', nil, 3, 3, 3)
|
||||
|
||||
result = helper.parallel_diff_discussions(left, right, diff_file)
|
||||
|
||||
expect(result).to eq(['comment', nil])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#diff_match_line" do
|
||||
|
|
|
|||
Loading…
Reference in New Issue