diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-03-01 21:08:51 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-03-01 21:25:21 +0300 |
commit | 80543e0abd65a575bcc43f2482279af3980f4acc (patch) | |
tree | a9ca8ff8543f565bfd3a41a949f57ef39593b2b7 /app/services/git_operation_service.rb | |
parent | 981c730fdb3da1ada8d1b44d21e75a11175b3026 (diff) |
Fix creating a file in an empty repo using the API
Diffstat (limited to 'app/services/git_operation_service.rb')
-rw-r--r-- | app/services/git_operation_service.rb | 37 |
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 |