summaryrefslogtreecommitdiff
path: root/lib/gitlab/conflict/file_collection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/conflict/file_collection.rb')
-rw-r--r--lib/gitlab/conflict/file_collection.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/gitlab/conflict/file_collection.rb b/lib/gitlab/conflict/file_collection.rb
index a3035a5c3e6..a4a1505bb7d 100644
--- a/lib/gitlab/conflict/file_collection.rb
+++ b/lib/gitlab/conflict/file_collection.rb
@@ -17,6 +17,26 @@ module Gitlab
@merge_index ||= repository.rugged.merge_commits(our_commit, their_commit)
end
+ def resolve_conflicts!(resolutions, commit_message, user:)
+ rugged = repository.rugged
+ committer = repository.user_to_committer(user)
+ commit_message ||= default_commit_message
+
+ files.each do |file|
+ file.resolve!(resolutions, index: merge_index, rugged: rugged)
+ end
+
+ new_tree = merge_index.write_tree(rugged)
+
+ Rugged::Commit.create(rugged,
+ author: committer,
+ committer: committer,
+ tree: new_tree,
+ message: commit_message,
+ parents: [our_commit, their_commit],
+ update_ref: Gitlab::Git::BRANCH_REF_PREFIX + merge_request.source_branch)
+ end
+
def files
@files ||= merge_index.conflicts.map do |conflict|
their_path = conflict[:theirs][:path]