Commit b276cc04 authored by Vasilii Iakliushin's avatar Vasilii Iakliushin

Correct error message for branch creation service

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/216545

Currently we display a misleading error message when a branch cannot
be created because of the incorrect reference.

I change the error message to return a reference name rather than a new
branch name.
parent cd42cccf
......@@ -14,7 +14,7 @@ module Branches
if new_branch
success(new_branch)
else
error("Invalid reference name: #{branch_name}")
error("Invalid reference name: #{ref}")
end
rescue Gitlab::Git::PreReceiveError => ex
error(ex.message)
......
......@@ -623,7 +623,7 @@ describe API::Branches do
post api(route, user), params: { branch: 'new_design3', ref: 'foo' }
expect(response).to have_gitlab_http_status(:bad_request)
expect(json_response['message']).to eq('Invalid reference name: new_design3')
expect(json_response['message']).to eq('Invalid reference name: foo')
end
end
......
......@@ -38,7 +38,7 @@ describe 'Creation of a new branch' do
let(:ref) { 'unknown' }
it_behaves_like 'a mutation that returns errors in the response',
errors: ['Invalid reference name: new_branch']
errors: ['Invalid reference name: unknown']
end
end
end
......@@ -24,18 +24,29 @@ describe Branches::CreateService do
end
end
context 'when creating a branch fails' do
context 'when branch already exists' do
let(:project) { create(:project_empty_repo) }
it 'returns an error' do
result = service.execute('master', 'master')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Branch already exists')
end
end
context 'when incorrect reference is provided' do
let(:project) { create(:project_empty_repo) }
before do
allow(project.repository).to receive(:add_branch).and_return(false)
end
it 'returns an error with the branch name' do
result = service.execute('my-feature', 'master')
it 'returns an error with reference name' do
result = service.execute('my-feature', 'unknown')
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq("Invalid reference name: my-feature")
expect(result[:message]).to eq('Invalid reference name: unknown')
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