gitlab-org--gitlab-foss/app/services/validate_new_branch_service.rb

20 lines
444 B
Ruby
Raw Normal View History

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-19 20:37:44 -04:00
if project.repository.branch_exists?(branch_name)
return error('Branch already exists')
end
success
rescue Gitlab::Git::PreReceiveError => ex
error(ex.message)
end
end