diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-10-16 10:36:06 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-10-16 10:36:06 +0000 |
commit | b2553840e88bed82bad45712e2696de83fac1230 (patch) | |
tree | 0218a658d703f7fe09a67e5d82058c608cb55073 /app | |
parent | 3a7623fc010832c337e0ba0eb8650d7f6fca3562 (diff) | |
parent | 9fdde3693b3b49e929b7c80ccbec4abe412edb7f (diff) | |
download | gitlab-ce-b2553840e88bed82bad45712e2696de83fac1230.tar.gz |
Merge branch 'conflict-resolution-refactor' into 'master'
Conflict resolution refactor
See merge request gitlab-org/gitlab-ce!14747
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/merge_requests/conflicts_controller.rb | 2 | ||||
-rw-r--r-- | app/models/repository.rb | 12 | ||||
-rw-r--r-- | app/services/merge_requests/conflicts/list_service.rb | 4 | ||||
-rw-r--r-- | app/services/merge_requests/conflicts/resolve_service.rb | 48 |
4 files changed, 6 insertions, 60 deletions
diff --git a/app/controllers/projects/merge_requests/conflicts_controller.rb b/app/controllers/projects/merge_requests/conflicts_controller.rb index 28afef101a9..366524b0783 100644 --- a/app/controllers/projects/merge_requests/conflicts_controller.rb +++ b/app/controllers/projects/merge_requests/conflicts_controller.rb @@ -53,7 +53,7 @@ class Projects::MergeRequests::ConflictsController < Projects::MergeRequests::Ap flash[:notice] = 'All merge conflicts were resolved. The merge request can now be merged.' render json: { redirect_to: project_merge_request_url(@project, @merge_request, resolved_conflicts: true) } - rescue Gitlab::Conflict::ResolutionError => e + rescue Gitlab::Git::Conflict::Resolver::ResolutionError => e render status: :bad_request, json: { message: e.message } end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 43521a0ddd3..4324ea46aac 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -468,9 +468,7 @@ class Repository end def blob_at(sha, path) - unless Gitlab::Git.blank_ref?(sha) - Blob.decorate(Gitlab::Git::Blob.find(self, sha, path), project) - end + Blob.decorate(raw_repository.blob_at(sha, path), project) rescue Gitlab::Git::Repository::NoRepository nil end @@ -914,14 +912,6 @@ class Repository end end - def resolve_conflicts(user, branch_name, params) - with_branch(user, branch_name) do - committer = user_to_committer(user) - - create_commit(params.merge(author: committer, committer: committer)) - end - end - def merged_to_root_ref?(branch_name) branch_commit = commit(branch_name) root_ref_commit = commit(root_ref) diff --git a/app/services/merge_requests/conflicts/list_service.rb b/app/services/merge_requests/conflicts/list_service.rb index 9835606812c..0f677a996f7 100644 --- a/app/services/merge_requests/conflicts/list_service.rb +++ b/app/services/merge_requests/conflicts/list_service.rb @@ -23,13 +23,13 @@ module MergeRequests # when there are no conflict files. conflicts.files.each(&:lines) @conflicts_can_be_resolved_in_ui = conflicts.files.length > 0 - rescue Rugged::OdbError, Gitlab::Conflict::Parser::UnresolvableError, Gitlab::Conflict::FileCollection::ConflictSideMissing + rescue Rugged::OdbError, Gitlab::Git::Conflict::Parser::UnresolvableError, Gitlab::Git::Conflict::Resolver::ConflictSideMissing @conflicts_can_be_resolved_in_ui = false end end def conflicts - @conflicts ||= Gitlab::Conflict::FileCollection.read_only(merge_request) + @conflicts ||= Gitlab::Conflict::FileCollection.new(merge_request) end end end diff --git a/app/services/merge_requests/conflicts/resolve_service.rb b/app/services/merge_requests/conflicts/resolve_service.rb index 6b6e231f4f9..27cafd2d7d9 100644 --- a/app/services/merge_requests/conflicts/resolve_service.rb +++ b/app/services/merge_requests/conflicts/resolve_service.rb @@ -1,54 +1,10 @@ module MergeRequests module Conflicts class ResolveService < MergeRequests::Conflicts::BaseService - MissingFiles = Class.new(Gitlab::Conflict::ResolutionError) - def execute(current_user, params) - rugged = merge_request.source_project.repository.rugged - - Gitlab::Conflict::FileCollection.for_resolution(merge_request) do |conflicts_for_resolution| - merge_index = conflicts_for_resolution.merge_index - - params[:files].each do |file_params| - conflict_file = conflicts_for_resolution.file_for_path(file_params[:old_path], file_params[:new_path]) - - write_resolved_file_to_index(merge_index, rugged, conflict_file, file_params) - end - - unless merge_index.conflicts.empty? - missing_files = merge_index.conflicts.map { |file| file[:ours][:path] } - - raise MissingFiles, "Missing resolutions for the following files: #{missing_files.join(', ')}" - end - - commit_params = { - message: params[:commit_message] || conflicts_for_resolution.default_commit_message, - parents: [conflicts_for_resolution.our_commit, conflicts_for_resolution.their_commit].map(&:oid), - tree: merge_index.write_tree(rugged) - } - - conflicts_for_resolution - .project - .repository - .resolve_conflicts(current_user, merge_request.source_branch, commit_params) - end - end - - private - - def write_resolved_file_to_index(merge_index, rugged, file, params) - if params[:sections] - new_file = file.resolve_lines(params[:sections]).map(&:text).join("\n") - - new_file << "\n" if file.our_blob.data.ends_with?("\n") - elsif params[:content] - new_file = file.resolve_content(params[:content]) - end - - our_path = file.our_path + conflicts = Gitlab::Conflict::FileCollection.new(merge_request) - merge_index.add(path: our_path, oid: rugged.write(new_file, :blob), mode: file.our_mode) - merge_index.conflict_remove(our_path) + conflicts.resolve(current_user, params[:commit_message], params[:files]) end end end |