Commit c22e51e8 authored by Athar Hameed's avatar Athar Hameed Committed by Sean McGivern

Resolve "Automatically created MR uses wrong target branch (when branching from Tag)"

parent f068479e
...@@ -41,7 +41,9 @@ module MergeRequests ...@@ -41,7 +41,9 @@ module MergeRequests
end end
def ref def ref
@ref || project.default_branch || 'master' return @ref if project.repository.branch_exists?(@ref)
project.default_branch || 'master'
end end
def merge_request def merge_request
......
---
title: Set MR target branch to default branch if target branch is not valid
merge_request: 19067
author:
type: fixed
...@@ -125,9 +125,14 @@ describe MergeRequests::CreateFromIssueService do ...@@ -125,9 +125,14 @@ describe MergeRequests::CreateFromIssueService do
end end
context 'when ref branch does not exist' do context 'when ref branch does not exist' do
it 'does not create a merge request' do subject { described_class.new(project, user, issue_iid: issue.iid, ref: 'no-such-branch').execute }
expect { described_class.new(project, user, issue_iid: issue.iid, ref: 'nobr').execute }
.not_to change { project.merge_requests.count } it 'creates a merge request' do
expect { subject }.to change(project.merge_requests, :count).by(1)
end
it 'sets the merge request target branch to the project default branch' do
expect(subject[:merge_request].target_branch).to eq(project.default_branch)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment