2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require_relative 'base_service'
|
|
|
|
|
|
|
|
class ValidateNewBranchService < BaseService
|
2019-07-07 11:18:12 +05:30
|
|
|
def execute(branch_name, force: false)
|
2017-08-17 22:00:37 +05:30
|
|
|
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
|
|
|
|
|
|
|
|
unless valid_branch
|
|
|
|
return error('Branch name is invalid')
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
if project.repository.branch_exists?(branch_name) && !force
|
2017-08-17 22:00:37 +05:30
|
|
|
return error('Branch already exists')
|
|
|
|
end
|
|
|
|
|
|
|
|
success
|
2018-11-08 19:23:39 +05:30
|
|
|
rescue Gitlab::Git::PreReceiveError => ex
|
2017-08-17 22:00:37 +05:30
|
|
|
error(ex.message)
|
|
|
|
end
|
|
|
|
end
|