gitlab-org--gitlab-foss/app/services/validate_new_branch_service.rb
Patrick Bajao de5aef3bbd Accept force option on commit via API
When `force` is set to `true` and `start_branch` is set, the
branch will be ovewritten with the new commit based on the
`HEAD` of the `start_branch`.

This commit includes changes to update the `gitaly-proto` gem.
2019-03-06 10:44:59 +00:00

21 lines
499 B
Ruby

# frozen_string_literal: true
require_relative 'base_service'
class ValidateNewBranchService < BaseService
def execute(branch_name, force: false)
valid_branch = Gitlab::GitRefValidator.validate(branch_name)
unless valid_branch
return error('Branch name is invalid')
end
if project.repository.branch_exists?(branch_name) && !force
return error('Branch already exists')
end
success
rescue Gitlab::Git::PreReceiveError => ex
error(ex.message)
end
end