Commit 24c079de authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'sh-improve-branch-creation-error' into 'master'

Log invalid branch name if creation fails

See merge request gitlab-org/gitlab!18789
parents 1799fc14 9028eb1a
......@@ -14,7 +14,7 @@ class CreateBranchService < BaseService
if new_branch
success(new_branch)
else
error('Invalid reference name')
error("Invalid reference name: #{branch_name}")
end
rescue Gitlab::Git::PreReceiveError => ex
error(ex.message)
......
......@@ -602,7 +602,7 @@ describe API::Branches do
post api(route, user), params: { branch: 'new_design3', ref: 'foo' }
expect(response).to have_gitlab_http_status(400)
expect(json_response['message']).to eq('Invalid reference name')
expect(json_response['message']).to eq('Invalid reference name: new_design3')
end
end
......
......@@ -22,5 +22,20 @@ describe CreateBranchService do
expect(project.repository.branch_exists?('my-feature')).to be_truthy
end
end
context 'when creating a branch fails' do
let(:project) { create(:project_empty_repo) }
before do
allow(project.repository).to receive(:add_branch).and_return(false)
end
it 'retruns an error with the branch name' do
result = service.execute('my-feature', 'master')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Invalid reference name: my-feature")
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