diff options
-rw-r--r-- | app/models/merge_request.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/diff/position_tracer.rb | 2 | ||||
-rw-r--r-- | spec/models/merge_request_spec.rb | 7 |
3 files changed, 11 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 1b6904aa077..e88a86ea0f0 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -299,6 +299,8 @@ class MergeRequest < ActiveRecord::Base attr_writer :target_branch_sha, :source_branch_sha def source_branch_head + return unless source_project + source_branch_ref = @source_branch_sha || source_branch source_project.repository.commit(source_branch_ref) if source_branch_ref end @@ -919,6 +921,7 @@ class MergeRequest < ActiveRecord::Base return @conflicts_can_be_resolved_in_ui = false unless cannot_be_merged? return @conflicts_can_be_resolved_in_ui = false unless has_complete_diff_refs? + return @conflicts_can_be_resolved_in_ui = false if branch_missing? begin # Try to parse each conflict. If the MR's mergeable status hasn't been updated, diff --git a/lib/gitlab/diff/position_tracer.rb b/lib/gitlab/diff/position_tracer.rb index c7542a8fabc..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`. diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 6cf3dd30ead..a6fd89c8e5d 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -1335,6 +1335,13 @@ describe MergeRequest, models: true do expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end + it 'returns a falsey value when one of the MR branches is missing' do + merge_request = create_merge_request('conflict-resolvable') + merge_request.project.repository.rm_branch(merge_request.author, 'conflict-resolvable') + + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey + end + it 'returns a falsey value when the MR has a missing ref after a force push' do merge_request = create_merge_request('conflict-resolvable') allow(merge_request.conflicts).to receive(:merge_index).and_raise(Rugged::OdbError) |