summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2016-11-15 07:22:50 +0800
committerLin Jen-Shin <godfat@godfat.org>2016-11-15 07:51:09 +0800
commitd8fe2fac7e681ddbff3c7a5338f939eb2d540e38 (patch)
tree505a78a33a4c7840c14dff78f40ca3617da91065 /app
parent5de74551ace7b6df9fdb2a3c8aa30c836d693728 (diff)
downloadgitlab-ce-d8fe2fac7e681ddbff3c7a5338f939eb2d540e38.tar.gz
Make sure we have the branch on the other project
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb11
-rw-r--r--app/services/create_branch_service.rb10
-rw-r--r--app/services/files/base_service.rb10
3 files changed, 21 insertions, 10 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 94aabafce20..1208e5da6fa 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -988,6 +988,17 @@ class Project < ActiveRecord::Base
Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path)
end
+ def fetch_ref(source_project, branch_name, ref)
+ repository.fetch_ref(
+ source_project.repository.path_to_repo,
+ "refs/heads/#{ref}",
+ "refs/heads/#{branch_name}"
+ )
+
+ repository.after_create_branch
+ repository.find_branch(branch_name)
+ end
+
# Expires various caches before a project is renamed.
def expire_caches_before_rename(old_path)
repo = Repository.new(old_path, self)
diff --git a/app/services/create_branch_service.rb b/app/services/create_branch_service.rb
index f4270a09928..ecb5994fab8 100644
--- a/app/services/create_branch_service.rb
+++ b/app/services/create_branch_service.rb
@@ -7,15 +7,7 @@ class CreateBranchService < BaseService
return failure if failure
new_branch = if source_project != @project
- repository.fetch_ref(
- source_project.repository.path_to_repo,
- "refs/heads/#{ref}",
- "refs/heads/#{branch_name}"
- )
-
- repository.after_create_branch
-
- repository.find_branch(branch_name)
+ @project.fetch_ref(source_project, branch_name, ref)
else
repository.add_branch(current_user, branch_name, ref)
end
diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb
index 6779bd2818a..fd62246eddb 100644
--- a/app/services/files/base_service.rb
+++ b/app/services/files/base_service.rb
@@ -23,7 +23,7 @@ module Files
validate
# Create new branch if it different from source_branch
- validate_target_branch if different_branch?
+ ensure_target_branch if different_branch?
result = commit
if result
@@ -71,6 +71,14 @@ module Files
end
end
+ def ensure_target_branch
+ validate_target_branch
+
+ if @source_project != project
+ @project.fetch_ref(@source_project, @target_branch, @source_branch)
+ end
+ end
+
def validate_target_branch
result = ValidateNewBranchService.new(project, current_user).
execute(@target_branch)