diff options
author | Sean McGivern <sean@gitlab.com> | 2016-08-04 10:31:44 +0100 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2016-08-12 23:24:48 +0300 |
commit | 427e724698185169536d68e95873415038286849 (patch) | |
tree | 8a114686469f751c6aef02361b8a83fa344f1f54 /app | |
parent | 5277239c3e2d843f04397dce572a647f3bd79bdf (diff) | |
download | gitlab-ce-427e724698185169536d68e95873415038286849.tar.gz |
Don't allow resolving invalid conflicts
An MR can only be resolved in the UI if:
- It has conflicts.
- It has valid diff_refs (in other words, it supports new diff notes).
- It has no conflicts with one side missing.
- It has no conflicts in binary files.
- It has no conflicts in files too large to display.
- It has no conflicts containing invalid conflict markers.
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/merge_requests_controller.rb | 10 | ||||
-rw-r--r-- | app/models/diff_note.rb | 2 | ||||
-rw-r--r-- | app/models/merge_request.rb | 23 | ||||
-rw-r--r-- | app/views/projects/merge_requests/widget/open/_conflicts.html.haml | 6 |
4 files changed, 27 insertions, 14 deletions
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 42dc0bb4a43..040dceff142 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -132,15 +132,13 @@ class Projects::MergeRequestsController < Projects::ApplicationController end def conflicts - return render_404 unless @merge_request.cannot_be_merged? - respond_to do |format| format.html { define_discussion_vars } format.json do - begin - render json: Gitlab::Conflict::FileCollection.new(@merge_request) - rescue Gitlab::Conflict::Parser::ParserError, Gitlab::Conflict::FileCollection::ConflictSideMissing + if @merge_request.can_resolve_conflicts_in_ui? + render json: @merge_request.conflicts + else render json: { message: 'Unable to resolve conflicts in the web interface for this merge request', type: 'error' @@ -452,7 +450,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController noteable_id: @merge_request.id } - @use_legacy_diff_notes = !@merge_request.support_new_diff_notes? + @use_legacy_diff_notes = !@merge_request.has_complete_diff_refs? @grouped_diff_discussions = @merge_request.notes.inc_author_project_award_emoji.grouped_diff_discussions Banzai::NoteRenderer.render( diff --git a/app/models/diff_note.rb b/app/models/diff_note.rb index c816deb4e0c..e02a3d54c36 100644 --- a/app/models/diff_note.rb +++ b/app/models/diff_note.rb @@ -75,7 +75,7 @@ class DiffNote < Note private def supported? - !self.for_merge_request? || self.noteable.support_new_diff_notes? + !self.for_merge_request? || self.noteable.has_complete_diff_refs? end def noteable_diff_refs diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index e87ce322098..630d31a5d5c 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -204,7 +204,7 @@ class MergeRequest < ActiveRecord::Base def diff_start_commit if persisted? - merge_request_diff.start_commit || target_branch_head + merge_request_diff.start_commit else target_branch_head end @@ -212,7 +212,7 @@ class MergeRequest < ActiveRecord::Base def diff_head_commit if persisted? - merge_request_diff.head_commit || source_branch_head + merge_request_diff.head_commit else source_branch_head end @@ -682,12 +682,12 @@ class MergeRequest < ActiveRecord::Base merge_commit end - def support_new_diff_notes? + def has_complete_diff_refs? diff_sha_refs && diff_sha_refs.complete? end def update_diff_notes_positions(old_diff_refs:, new_diff_refs:) - return unless support_new_diff_notes? + return unless has_complete_diff_refs? return if new_diff_refs == old_diff_refs active_diff_notes = self.notes.diff_notes.select do |note| @@ -715,4 +715,19 @@ class MergeRequest < ActiveRecord::Base def keep_around_commit project.repository.keep_around(self.merge_commit_sha) end + + def conflicts + @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? + + begin + conflicts.files.each(&:lines) + rescue Gitlab::Conflict::Parser::ParserError, Gitlab::Conflict::FileCollection::ConflictSideMissing + 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 6bdbbb94f09..582a82c7a71 100644 --- a/app/views/projects/merge_requests/widget/open/_conflicts.html.haml +++ b/app/views/projects/merge_requests/widget/open/_conflicts.html.haml @@ -4,9 +4,9 @@ %p Please - = link_to conflicts_namespace_project_merge_request_path(@project.namespace, @project, @merge_request) do - resolve these conflicts - or + - if @merge_request.can_resolve_conflicts_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) #{link_to "merge this request manually", "#modal_merge_info", class: "how_to_merge_link vlink", "data-toggle" => "modal"}. - else |