summaryrefslogtreecommitdiff
path: root/app/services/git_operation_service.rb
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2017-01-05 01:52:21 +0800
committerLin Jen-Shin <godfat@godfat.org>2017-01-05 01:52:21 +0800
commit99ac0935271b1e99f4512e496104219045f1018e (patch)
treee79085e860ecd2adf281519e3e0bd5c9441a6ae6 /app/services/git_operation_service.rb
parent05d742a047cca3ded10e6e3a545e211a3592c89c (diff)
downloadgitlab-ce-99ac0935271b1e99f4512e496104219045f1018e.tar.gz
Introduce Repository#with_repo_branch_commit
We merge repository checks inside it so we don't have to check it on the call site, and we could also load the commit for the caller. This greatly reduce code duplication. Feedback: https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7237#note_20572919
Diffstat (limited to 'app/services/git_operation_service.rb')
-rw-r--r--app/services/git_operation_service.rb18
1 files changed, 6 insertions, 12 deletions
diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb
index 00c85112873..ed9822cfee6 100644
--- a/app/services/git_operation_service.rb
+++ b/app/services/git_operation_service.rb
@@ -43,23 +43,17 @@ class GitOperationService
def with_branch(
branch_name,
source_branch_name: nil,
- source_project: repository.project)
+ source_project: repository.project,
+ &block)
check_with_branch_arguments!(
branch_name, source_branch_name, source_project)
- source_commit = source_project.repository.find_branch(
- source_branch_name || branch_name).try(:dereferenced_target)
-
update_branch_with_hooks(branch_name) do
- if repository.project == source_project
- yield(source_commit)
- else
- repository.with_tmp_ref(
- source_project.repository, source_branch_name) do
- yield(source_commit)
- end
- end
+ repository.with_repo_branch_commit(
+ source_project.repository,
+ source_branch_name || branch_name,
+ &block)
end
end