2018-07-05 06:18:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 15:02:10 -05: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-19 20:37:44 -04:00
|
|
|
if project.repository.branch_exists?(branch_name)
|
2016-11-14 15:02:10 -05:00
|
|
|
return error('Branch already exists')
|
|
|
|
end
|
|
|
|
|
|
|
|
success
|
2018-06-11 06:42:09 -04:00
|
|
|
rescue Gitlab::Git::PreReceiveError => ex
|
2016-11-14 15:02:10 -05:00
|
|
|
error(ex.message)
|
|
|
|
end
|
|
|
|
end
|