summaryrefslogtreecommitdiff
path: root/app/services/merge_requests
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2019-06-20 19:45:46 +0700
committerShinya Maeda <shinya@gitlab.com>2019-07-05 17:15:10 +0700
commit48307fac1ec7cd207fbd53762fd1226a9d6fb1a2 (patch)
tree92b3d9b65dd6e541dd09acda541e5c291448fb09 /app/services/merge_requests
parent9414a41f8390511005702ab4fec99239b6c3c6dd (diff)
downloadgitlab-ce-48307fac1ec7cd207fbd53762fd1226a9d6fb1a2.tar.gz
Extend MergeToRefService for creating merge ref from the other ref
Currently, MergeToRefService is specifically designed for createing merge commits from source branch and target branch of merge reqeusts. We extend this behavior to source branch and any target ref paths.
Diffstat (limited to 'app/services/merge_requests')
-rw-r--r--app/services/merge_requests/merge_to_ref_service.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/app/services/merge_requests/merge_to_ref_service.rb b/app/services/merge_requests/merge_to_ref_service.rb
index efe4dcd6255..0ea50a5dbf5 100644
--- a/app/services/merge_requests/merge_to_ref_service.rb
+++ b/app/services/merge_requests/merge_to_ref_service.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module MergeRequests
- # Performs the merge between source SHA and the target branch. Instead
+ # Performs the merge between source SHA and the target branch or the specified first parent ref. Instead
# of writing the result to the MR target branch, it targets the `target_ref`.
#
# Ideally this should leave the `target_ref` state with the same state the
@@ -56,12 +56,22 @@ module MergeRequests
raise_error(error) if error
end
+ ##
+ # The parameter `target_ref` is where the merge result will be written.
+ # Default is the merge ref i.e. `refs/merge-requests/:iid/merge`.
def target_ref
- merge_request.merge_ref_path
+ params[:target_ref] || merge_request.merge_ref_path
+ end
+
+ ##
+ # The parameter `first_parent_ref` is the main line of the merge commit.
+ # Default is the target branch ref of the merge request.
+ def first_parent_ref
+ params[:first_parent_ref] || merge_request.target_branch_ref
end
def commit
- repository.merge_to_ref(current_user, source, merge_request, target_ref, commit_message)
+ repository.merge_to_ref(current_user, source, merge_request, target_ref, commit_message, first_parent_ref)
rescue Gitlab::Git::PreReceiveError => error
raise MergeError, error.message
end