diff options
Diffstat (limited to 'app/services/commits/create_service.rb')
-rw-r--r-- | app/services/commits/create_service.rb | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/app/services/commits/create_service.rb b/app/services/commits/create_service.rb index a3b87c20761..bb34a3d3352 100644 --- a/app/services/commits/create_service.rb +++ b/app/services/commits/create_service.rb @@ -11,6 +11,7 @@ module Commits @start_project = params[:start_project] || @project @start_branch = params[:start_branch] @branch_name = params[:branch_name] + @force = params[:force] || false end def execute @@ -42,6 +43,10 @@ module Commits @start_branch != @branch_name || @start_project != @project end + def force? + !!@force + end + def validate! validate_permissions! validate_on_branch! @@ -65,13 +70,13 @@ module Commits end def validate_branch_existence! - if !project.empty_repo? && different_branch? && repository.branch_exists?(@branch_name) + if !project.empty_repo? && different_branch? && repository.branch_exists?(@branch_name) && !force? raise_error("A branch called '#{@branch_name}' already exists. Switch to that branch in order to make changes") end end def validate_new_branch_name! - result = ValidateNewBranchService.new(project, current_user).execute(@branch_name) + result = ValidateNewBranchService.new(project, current_user).execute(@branch_name, force: force?) if result[:status] == :error raise_error("Something went wrong when we tried to create '#{@branch_name}' for you: #{result[:message]}") |