summaryrefslogtreecommitdiff
path: root/app/services
diff options
context:
space:
mode:
authorRubén Dávila <rdavila84@gmail.com>2016-02-10 16:05:04 -0500
committerRobert Speicher <rspeicher@gmail.com>2016-02-19 13:14:53 -0500
commit2ea5b37f2effacc98dd15e1d86386c40bc719200 (patch)
tree3cc551ea745d9b89f63744d30417f2de0a520573 /app/services
parent11345866d8ae3198c0f5523e8dee1e14cb21b3c7 (diff)
downloadgitlab-ce-2ea5b37f2effacc98dd15e1d86386c40bc719200.tar.gz
Some fixes and refactors for code related to forks.
Diffstat (limited to 'app/services')
-rw-r--r--app/services/commits/revert_service.rb29
1 files changed, 25 insertions, 4 deletions
diff --git a/app/services/commits/revert_service.rb b/app/services/commits/revert_service.rb
index 6e8a7f8eabb..d7720eaffda 100644
--- a/app/services/commits/revert_service.rb
+++ b/app/services/commits/revert_service.rb
@@ -14,9 +14,7 @@ module Commits
if commit
success
else
- error("Sorry, we cannot revert this #{params[:revert_type_title]} automatically.
- It may have already been reverted, or a more recent commit may
- have updated some of its content.")
+ custom_error
end
rescue Repository::CommitError, Gitlab::Git::Repository::InvalidBlobName, GitHooksService::PreReceiveError, ValidationError => ex
error(ex.message)
@@ -24,7 +22,11 @@ module Commits
def commit
if @create_merge_request
- repository.revert(current_user, @commit, @target_branch, @commit.revert_branch_name)
+ # Temporary branch exists and contains the revert commit
+ return true if repository.find_branch(@commit.revert_branch_name)
+ return false unless create_target_branch
+
+ repository.revert(current_user, @commit, @commit.revert_branch_name)
else
repository.revert(current_user, @commit, @target_branch)
end
@@ -32,6 +34,25 @@ module Commits
private
+ def custom_error
+ if @branch_error_msg
+ error("There was an error creating the source branch: #{@branch_error_msg}")
+ else
+ error("Sorry, we cannot revert this #{params[:revert_type_title]} automatically.
+ It may have already been reverted, or a more recent commit may
+ have updated some of its content.")
+ end
+ end
+
+ def create_target_branch
+ result = CreateBranchService.new(@project, current_user)
+ .execute(@commit.revert_branch_name, @target_branch, source_project: @source_project)
+
+ @branch_error_msg = result[:message]
+
+ result[:status] != :error
+ end
+
def raise_error(message)
raise ValidationError.new(message)
end