summaryrefslogtreecommitdiff
path: root/app/services/git_operation_service.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/git_operation_service.rb')
-rw-r--r--app/services/git_operation_service.rb37
1 files changed, 9 insertions, 28 deletions
diff --git a/app/services/git_operation_service.rb b/app/services/git_operation_service.rb
index 27bcc047601..507e0a6680a 100644
--- a/app/services/git_operation_service.rb
+++ b/app/services/git_operation_service.rb
@@ -56,13 +56,14 @@ class GitOperationService
start_project: repository.project,
&block)
- check_with_branch_arguments!(
- branch_name, start_branch_name, start_project)
+ start_branch ||= branch_name
+
+ verify_start_branch_exists!(start_project.repository, start_branch_name)
update_branch_with_hooks(branch_name) do
repository.with_repo_branch_commit(
start_project.repository,
- start_branch_name || branch_name,
+ start_branch_name,
&block)
end
end
@@ -150,30 +151,10 @@ class GitOperationService
end
end
- def check_with_branch_arguments!(
- branch_name, start_branch_name, start_project)
- return if repository.branch_exists?(branch_name)
-
- if repository.project != start_project
- unless start_branch_name
- raise ArgumentError,
- 'Should also pass :start_branch_name if' +
- ' :start_project is different from current project'
- end
-
- unless start_project.repository.branch_exists?(start_branch_name)
- raise ArgumentError,
- "Cannot find branch #{branch_name} nor" \
- " #{start_branch_name} from" \
- " #{start_project.path_with_namespace}"
- end
- elsif start_branch_name
- unless repository.branch_exists?(start_branch_name)
- raise ArgumentError,
- "Cannot find branch #{branch_name} nor" \
- " #{start_branch_name} from" \
- " #{repository.project.path_with_namespace}"
- end
- end
+ def verify_start_branch_exists!(start_repository, start_branch_name)
+ return if start_repository.empty_repo?
+ return if start_repository.branch_exists?(start_branch_name)
+
+ raise ArgumentError, "Cannot find branch #{start_branch_name} in #{start_repository.path_with_namespace}"
end
end