diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 2edd76de4c4f80eb783517ea25c6ed79194d0c57..9d3a2addcde221a5ec1ce3eb3b2fc9ad65435bee 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -135,7 +135,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController format.html { define_discussion_vars } format.json do - if @merge_request.can_resolve_conflicts_in_ui? + if @merge_request.conflicts_can_be_resolved_in_ui? render json: @merge_request.conflicts else render json: { diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 630d31a5d5c6ba50e96b309d3af37d64b020efd0..b41d3b6891a31a19307c274ebaa3c87b38c3feb0 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -720,14 +720,16 @@ class MergeRequest < ActiveRecord::Base @conflicts ||= Gitlab::Conflict::FileCollection.new(self) end - def can_resolve_conflicts_in_ui? - return false unless cannot_be_merged? - return false unless has_complete_diff_refs? + def conflicts_can_be_resolved_in_ui? + return @conflicts_can_be_resolved_in_ui if defined?(@conflicts_can_be_resolved_in_ui) + + 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? begin - conflicts.files.each(&:lines) + @conflicts_can_be_resolved_in_ui = conflicts.files.each(&:lines) rescue Gitlab::Conflict::Parser::ParserError, Gitlab::Conflict::FileCollection::ConflictSideMissing - false + @conflicts_can_be_resolved_in_ui = false end end end diff --git a/app/views/projects/merge_requests/widget/open/_conflicts.html.haml b/app/views/projects/merge_requests/widget/open/_conflicts.html.haml index 582a82c7a7154e34c0db6ddc2d244b774c2b1f7d..bedf45fb89d8aae5990fbafe8142d38ecef4f4b2 100644 --- a/app/views/projects/merge_requests/widget/open/_conflicts.html.haml +++ b/app/views/projects/merge_requests/widget/open/_conflicts.html.haml @@ -4,7 +4,7 @@ %p Please - - if @merge_request.can_resolve_conflicts_in_ui? + - if @merge_request.conflicts_can_be_resolved_in_ui? = link_to "resolve these conflicts", conflicts_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) or - if @merge_request.can_be_merged_via_command_line_by?(current_user) diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index b4741bd3bcb01dcfedd1f76e403822d2619a612d..a9d8081656d6c78b9fe8a8882b53799a58d22ec4 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -742,7 +742,7 @@ describe MergeRequest, models: true do end end - describe '#can_resolve_conflicts_in_ui?' do + describe '#conflicts_can_be_resolved_in_ui?' do def create_merge_request(source_branch) create(:merge_request, source_branch: source_branch, target_branch: 'conflict-start') do |mr| mr.mark_as_unmergeable @@ -753,44 +753,44 @@ describe MergeRequest, models: true do merge_request = create_merge_request('master') merge_request.mark_as_mergeable - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a falsey value when the MR does not support new diff notes' do merge_request = create_merge_request('conflict-resolvable') merge_request.merge_request_diff.update_attributes(start_commit_sha: nil) - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a falsey value when the conflicts contain a large file' do merge_request = create_merge_request('conflict-too-large') - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a falsey value when the conflicts contain a binary file' do merge_request = create_merge_request('conflict-binary-file') - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a falsey value when the conflicts contain a file with ambiguous conflict markers' do merge_request = create_merge_request('conflict-contains-conflict-markers') - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a falsey value when the conflicts contain a file edited in one branch and deleted in another' do merge_request = create_merge_request('conflict-missing-side') - expect(merge_request.can_resolve_conflicts_in_ui?).to be_falsey + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_falsey end it 'returns a truthy value when the conflicts are resolvable in the UI' do merge_request = create_merge_request('conflict-resolvable') - expect(merge_request.can_resolve_conflicts_in_ui?).to be_truthy + expect(merge_request.conflicts_can_be_resolved_in_ui?).to be_truthy end end end