summaryrefslogtreecommitdiff
path: root/lib/gitlab/diff/position_tracer.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/diff/position_tracer.rb')
-rw-r--r--lib/gitlab/diff/position_tracer.rb11
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/gitlab/diff/position_tracer.rb b/lib/gitlab/diff/position_tracer.rb
index 4d04f867268..e89ff238ec7 100644
--- a/lib/gitlab/diff/position_tracer.rb
+++ b/lib/gitlab/diff/position_tracer.rb
@@ -16,7 +16,7 @@ module Gitlab
end
def trace(old_position)
- return unless old_diff_refs.complete? && new_diff_refs.complete?
+ return unless old_diff_refs&.complete? && new_diff_refs&.complete?
return unless old_position.diff_refs == old_diff_refs
# Suppose we have an MR with source branch `feature` and target branch `master`.
@@ -82,7 +82,7 @@ module Gitlab
file_diff, old_line, new_line = results
- Position.new(
+ new_position = Position.new(
old_path: file_diff.old_path,
new_path: file_diff.new_path,
head_sha: new_diff_refs.head_sha,
@@ -91,6 +91,13 @@ module Gitlab
old_line: old_line,
new_line: new_line
)
+
+ # If a position is found, but is not actually contained in the diff, for example
+ # because it was an unchanged line in the context of a change that was undone,
+ # we cannot return this as a successful trace.
+ return unless new_position.diff_line(repository)
+
+ new_position
end
private