summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-05-18 22:13:20 +0000
committerRobert Speicher <robert@gitlab.com>2017-05-18 22:13:20 +0000
commitbcc504d3c3ed0436935ca076d6be5db5ca10a664 (patch)
tree88abcddab66bde62a1177548c2f785dddf42282c
parente5cc8e0aa81c3012eff5303543b11931158478cf (diff)
parent7a7e9288d4dea50a9797b3f624bf8174fa7060d4 (diff)
downloadgitlab-ce-bcc504d3c3ed0436935ca076d6be5db5ca10a664.tar.gz
Merge branch 'dm-no-conflicts-when-branches-are-missing' into 'master'
Stop MR conflict code from blowing up when branches are missing Closes #32544 See merge request !11501
-rw-r--r--app/models/merge_request.rb2
-rw-r--r--app/services/merge_requests/conflicts/list_service.rb1
-rw-r--r--lib/gitlab/diff/position_tracer.rb2
-rw-r--r--spec/services/merge_requests/conflicts/list_service_spec.rb7
4 files changed, 11 insertions, 1 deletions
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index d7e7ae7a25f..9be00880438 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -293,6 +293,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
diff --git a/app/services/merge_requests/conflicts/list_service.rb b/app/services/merge_requests/conflicts/list_service.rb
index 9bf82518643..9835606812c 100644
--- a/app/services/merge_requests/conflicts/list_service.rb
+++ b/app/services/merge_requests/conflicts/list_service.rb
@@ -15,6 +15,7 @@ module MergeRequests
return @conflicts_can_be_resolved_in_ui = false unless merge_request.cannot_be_merged?
return @conflicts_can_be_resolved_in_ui = false unless merge_request.has_complete_diff_refs?
+ return @conflicts_can_be_resolved_in_ui = false if merge_request.branch_missing?
begin
# Try to parse each conflict. If the MR's mergeable status hasn't been
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/services/merge_requests/conflicts/list_service_spec.rb b/spec/services/merge_requests/conflicts/list_service_spec.rb
index e8a305d6130..23982b9e6e1 100644
--- a/spec/services/merge_requests/conflicts/list_service_spec.rb
+++ b/spec/services/merge_requests/conflicts/list_service_spec.rb
@@ -25,6 +25,13 @@ describe MergeRequests::Conflicts::ListService do
expect(conflicts_service(merge_request).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(conflicts_service(merge_request).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')
service = conflicts_service(merge_request)