Skip to content

Git push options to create a merge request, set target_branch and set merge when pipeline succeeds

Luke Duncalfe requested to merge 43263-git-push-option-to-create-mr into master

What does this MR do?

Adds the ability to perform the following with git push options:

  • create a merge request
  • set the target branch of a merge request
  • set merge request to merge when its pipeline succeeds

Merge request creation

To create a new merge request:

git push -u origin -o merge_request.create

To create a new merge request, set its target branch, and set it to merge when its pipeline succeeds:

git push -u origin -o merge_request.create \
  -o \
  -o merge_request.merge_when_pipeline_succeeds

Updating existing merge requests

When pushing branches with an existing open merge request, target and merge_when_pipeline_succeeds can be used to update the merge request.


A new Gitlab::PushOptions class handles parsing and validating the push options array. This can be the start of the standard of GitLab accepting push options that follow namespacing rules. Rules are discussed in

E.g. these push options:

-o merge_request.create -o

Become parsed by the Gitlab::PushOptions class as:

  merge_request: {
    create: true,
    target: '123',

And are fetched with the class via:

push_options.get(:merge_request, :create)
push_options.get(:merge_request, :target)

A new MergeRequests::PushOptionsHandlerService takes the merge_request namespaced push options and handles creating and updating merge requests.

Any errors encountered are passed to the existing output Hash in Api::Internal's post_receive endpoint, and passed to gitlab-shell where they're output to the user.

What are the relevant issue numbers?

Does this MR meet the acceptance criteria?

Closes #43263 (closed)


Edited by Luke Duncalfe

Merge request reports