diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-12-18 12:03:34 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-12-18 12:03:34 +0300 |
commit | d9c82d679fd622aead99aeb90369361a05e02a36 (patch) | |
tree | 6bc7986aafad7e0a3998c0a026573e9baf0cc032 /app/services/create_branch_service.rb | |
parent | 110a5f9c96457ac314f30630735dd827d9d96a4c (diff) |
Automatically fork a project when not allowed to edit a file.
Diffstat (limited to 'app/services/create_branch_service.rb')
-rw-r--r-- | app/services/create_branch_service.rb | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb index de18f3bc556..84e141f5fd8 100644 --- a/app/services/create_branch_service.rb +++ b/app/services/create_branch_service.rb @@ -1,7 +1,7 @@ require_relative 'base_service' class CreateBranchService < BaseService - def execute(branch_name, ref) + def execute(branch_name, ref, source_project: @project) valid_branch = Gitlab::GitRefValidator.validate(branch_name) if valid_branch == false return error('Branch name invalid') @@ -13,7 +13,20 @@ class CreateBranchService < BaseService return error('Branch already exists') end - new_branch = repository.add_branch(current_user, branch_name, ref) + new_branch = nil + if source_project != @project + repository.with_tmp_ref do |tmp_ref| + repository.fetch_ref( + source_project.repository.path_to_repo, + "refs/heads/#{ref}", + tmp_ref + ) + + new_branch = repository.add_branch(current_user, branch_name, tmp_ref) + end + else + new_branch = repository.add_branch(current_user, branch_name, ref) + end if new_branch push_data = build_push_data(project, current_user, new_branch) |