2016-11-14 20:02:10 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class ValidateNewBranchService < BaseService
|
|
|
|
def execute(branch_name)
|
|
|
|
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
|
|
|
|
|
|
|
|
unless valid_branch
|
|
|
|
return error('Branch name is invalid')
|
|
|
|
end
|
|
|
|
|
2017-04-20 00:37:44 +00:00
|
|
|
if project.repository.branch_exists?(branch_name)
|
2016-11-14 20:02:10 +00:00
|
|
|
return error('Branch already exists')
|
|
|
|
end
|
|
|
|
|
|
|
|
success
|
2017-08-22 12:18:09 +00:00
|
|
|
rescue Gitlab::Git::HooksService::PreReceiveError => ex
|
2016-11-14 20:02:10 +00:00
|
|
|
error(ex.message)
|
|
|
|
end
|
|
|
|
end
|