2018-07-05 10:18:17 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-11-14 20:02:10 +00:00
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class ValidateNewBranchService < BaseService
|
2019-03-06 10:44:59 +00:00
|
|
|
def execute(branch_name, force: false)
|
2016-11-14 20:02:10 +00:00
|
|
|
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
|
|
|
|
|
|
|
|
unless valid_branch
|
|
|
|
return error('Branch name is invalid')
|
|
|
|
end
|
|
|
|
|
2019-03-06 10:44:59 +00:00
|
|
|
if project.repository.branch_exists?(branch_name) && !force
|
2016-11-14 20:02:10 +00:00
|
|
|
return error('Branch already exists')
|
|
|
|
end
|
|
|
|
|
|
|
|
success
|
2018-06-11 10:42:09 +00:00
|
|
|
rescue Gitlab::Git::PreReceiveError => ex
|
2016-11-14 20:02:10 +00:00
|
|
|
error(ex.message)
|
|
|
|
end
|
|
|
|
end
|