summaryrefslogtreecommitdiff
path: root/app/services/merge_requests/merge_to_ref_service.rb
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 15:17:23 +0700
commitf6ea904a1cb99410fb99e59de769e7f062e1c4f6 (patch)
tree6d232bd534e35e54bcc6540c0a08a9f4dbc4cb99 /app/services/merge_requests/merge_to_ref_service.rb
parent9414a41f8390511005702ab4fec99239b6c3c6dd (diff)
downloadgitlab-ce-f6ea904a1cb99410fb99e59de769e7f062e1c4f6.tar.gz
Extend MergeToRefService for creating merge ref from the other refcreate-merge-train-ref-ce
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/merge_to_ref_service.rb')
-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