debian-mirror-gitlab/app/services/create_branch_service.rb

37 lines
784 B
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
class CreateBranchService < BaseService
2017-08-17 22:00:37 +05:30
def execute(branch_name, ref)
create_master_branch if project.empty_repo?
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
result = ValidateNewBranchService.new(project, current_user)
.execute(branch_name)
2015-04-26 12:48:37 +05:30
2017-08-17 22:00:37 +05:30
return result if result[:status] == :error
2016-09-13 17:45:13 +05:30
2017-08-17 22:00:37 +05:30
new_branch = repository.add_branch(current_user, branch_name, ref)
2014-09-02 18:07:02 +05:30
if new_branch
2015-04-26 12:48:37 +05:30
success(new_branch)
else
error('Invalid reference name')
2014-09-02 18:07:02 +05:30
end
2018-03-17 18:26:18 +05:30
rescue Gitlab::Git::HooksService::PreReceiveError => ex
2016-08-24 12:49:21 +05:30
error(ex.message)
2015-04-26 12:48:37 +05:30
end
def success(branch)
2016-08-24 12:49:21 +05:30
super().merge(branch: branch)
2015-04-26 12:48:37 +05:30
end
2017-08-17 22:00:37 +05:30
private
def create_master_branch
project.repository.create_file(
current_user,
'/README.md',
'',
message: 'Add README.md',
branch_name: 'master'
)
end
2014-09-02 18:07:02 +05:30
end