diff options
author | Patrick Bajao <ebajao@gitlab.com> | 2019-03-06 10:44:59 +0000 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-03-06 10:44:59 +0000 |
commit | de5aef3bbda9217e32fc91c24280f78869c9c9c1 (patch) | |
tree | 1c2a7468e0b7f31134ee7b6e9f537b798fdf724e /app/services/commits | |
parent | c9e5ce8dbd25203484b43c48f0a55a5d7bf396e8 (diff) | |
download | gitlab-ce-de5aef3bbda9217e32fc91c24280f78869c9c9c1.tar.gz |
Accept force option on commit via API
When `force` is set to `true` and `start_branch` is set, the
branch will be ovewritten with the new commit based on the
`HEAD` of the `start_branch`.
This commit includes changes to update the `gitaly-proto` gem.
Diffstat (limited to 'app/services/commits')
-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]}") |