Skip to content

Commit 9c266d4

Browse files
committed
Add more descriptive error message when create branch with invalid name
1 parent 76642d7 commit 9c266d4

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

app/services/create_branch_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class CreateBranchService < BaseService
44
def execute(branch_name, ref)
55
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
66
if valid_branch == false
7-
return error('Branch name invalid')
7+
return error("Branch name can't contains space, '~', '^', ':', '?', '*', '[', '\', '..', '@{', and consecutive slashes, start with '/' or '.' or end in '/' or '.' or '.lock'")
88
end
99

1010
repository = project.repository

app/views/projects/branches/new.html.haml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
= label_tag :branch_name, nil, class: 'control-label'
1515
.col-sm-10
1616
= text_field_tag :branch_name, params[:branch_name], required: true, tabindex: 1, autofocus: true, class: 'form-control'
17+
.help-block Can't contains space, '~', '^', ':', '?', '*', '[', '\', '..', '@{', and consecutive slashes, start with '/' or '.' or end in '/' or '.' or '.lock'
1718
.form-group
1819
= label_tag :ref, 'Create from', class: 'control-label'
1920
.col-sm-10

features/steps/project/commits/branches.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Spinach::Features::ProjectCommitsBranches < Spinach::FeatureSteps
6161
end
6262

6363
step 'I should see new an error that branch is invalid' do
64-
expect(page).to have_content 'Branch name invalid'
64+
expect(page).to have_content "Branch name can't contains space, '~', '^', ':', '?', '*', '[', '\', '..', '@{', and consecutive slashes, start with '/' or '.' or end in '/' or '.' or '.lock'"
6565
end
6666

6767
step 'I should see new an error that ref is invalid' do

0 commit comments

Comments
 (0)