Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2017-02-17 03:24:56 +0300
committerDouwe Maan <douwe@selenight.nl>2017-03-03 02:41:05 +0300
commit6cc4cf1e151fb8da16796d7bbab16bc8a1ac08b6 (patch)
treedbc7105aa4ecd6498a9354ad6d9c141fb93d277f /app/services/commits
parentefff35e96873bd3bea0afceb1d3cd102280813f5 (diff)
Fix cherry-picking or reverting through an MR
Diffstat (limited to 'app/services/commits')
-rw-r--r--app/services/commits/change_service.rb52
1 files changed, 22 insertions, 30 deletions
diff --git a/app/services/commits/change_service.rb b/app/services/commits/change_service.rb
index 8a9bcd2d053..3051ebf5e52 100644
--- a/app/services/commits/change_service.rb
+++ b/app/services/commits/change_service.rb
@@ -8,9 +8,9 @@ module Commits
@start_branch = params[:start_branch]
@target_branch = params[:target_branch]
@commit = params[:commit]
- @create_merge_request = params[:create_merge_request].present?
- check_push_permissions unless @create_merge_request
+ check_push_permissions
+
commit
rescue Repository::CommitError, Gitlab::Git::Repository::InvalidBlobName, GitHooksService::PreReceiveError,
ValidationError, ChangeError => ex
@@ -26,33 +26,24 @@ module Commits
def commit_change(action)
raise NotImplementedError unless repository.respond_to?(action)
- if @create_merge_request
- into = @commit.public_send("#{action}_branch_name")
- tree_branch = @start_branch
- else
- into = tree_branch = @target_branch
- end
-
- tree_id = repository.public_send(
- "check_#{action}_content", @commit, tree_branch)
-
- if tree_id
- validate_target_branch(into) if @create_merge_request
+ validate_target_branch if different_branch?
- repository.public_send(
- action,
- current_user,
- @commit,
- into,
- tree_id,
- start_project: @start_project,
- start_branch_name: @start_branch)
+ repository.public_send(
+ action,
+ current_user,
+ @commit,
+ @target_branch,
+ start_project: @start_project,
+ start_branch_name: @start_branch)
- success
- else
+ success
+ rescue Repository::CommitError => e
+ if e.message =~ /Failed to/
error_msg = "Sorry, we cannot #{action.to_s.dasherize} this #{@commit.change_type_title(current_user)} automatically.
A #{action.to_s.dasherize} may have already been performed with this #{@commit.change_type_title(current_user)}, or a more recent commit may have updated some of its content."
raise ChangeError, error_msg
+ else
+ raise
end
end
@@ -66,16 +57,17 @@ module Commits
true
end
- def validate_target_branch(new_branch)
- # Temporary branch exists and contains the change commit
- return if repository.find_branch(new_branch)
-
- result = ValidateNewBranchService.new(@project, current_user)
- .execute(new_branch)
+ def validate_target_branch
+ result = ValidateNewBranchService.new(@project, current_user).
+ execute(@target_branch)
if result[:status] == :error
raise ChangeError, "There was an error creating the source branch: #{result[:message]}"
end
end
+
+ def different_branch?
+ @start_branch != @target_branch || @start_project != @project
+ end
end
end