Commit caed61ad authored by Douwe Maan's avatar Douwe Maan

Use separate error class for cherry-pick and revert tree errors

parent 6cc4cf1e
...@@ -6,6 +6,7 @@ class Repository ...@@ -6,6 +6,7 @@ class Repository
attr_accessor :path_with_namespace, :project attr_accessor :path_with_namespace, :project
CommitError = Class.new(StandardError) CommitError = Class.new(StandardError)
CreateTreeError = Class.new(StandardError)
# Methods that cache data from the Git repository. # Methods that cache data from the Git repository.
# #
...@@ -871,7 +872,7 @@ class Repository ...@@ -871,7 +872,7 @@ class Repository
revert_tree_id = check_revert_content(commit, start_commit.sha) revert_tree_id = check_revert_content(commit, start_commit.sha)
unless revert_tree_id unless revert_tree_id
raise Repository::CommitError.new('Failed to revert commit') raise Repository::CreateTreeError.new('Failed to revert commit')
end end
committer = user_to_committer(user) committer = user_to_committer(user)
...@@ -895,7 +896,7 @@ class Repository ...@@ -895,7 +896,7 @@ class Repository
cherry_pick_tree_id = check_cherry_pick_content(commit, start_commit.sha) cherry_pick_tree_id = check_cherry_pick_content(commit, start_commit.sha)
unless cherry_pick_tree_id unless cherry_pick_tree_id
raise Repository::CommitError.new('Failed to cherry-pick commit') raise Repository::CreateTreeError.new('Failed to cherry-pick commit')
end end
committer = user_to_committer(user) committer = user_to_committer(user)
......
...@@ -37,14 +37,10 @@ module Commits ...@@ -37,14 +37,10 @@ module Commits
start_branch_name: @start_branch) start_branch_name: @start_branch)
success success
rescue Repository::CommitError => e rescue Repository::CreateTreeError => e
if e.message =~ /Failed to/
error_msg = "Sorry, we cannot #{action.to_s.dasherize} this #{@commit.change_type_title(current_user)} automatically. 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." 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 raise ChangeError, error_msg
else
raise
end
end end
def check_push_permissions def check_push_permissions
...@@ -58,8 +54,8 @@ module Commits ...@@ -58,8 +54,8 @@ module Commits
end end
def validate_target_branch def validate_target_branch
result = ValidateNewBranchService.new(@project, current_user). result = ValidateNewBranchService.new(@project, current_user)
execute(@target_branch) .execute(@target_branch)
if result[:status] == :error if result[:status] == :error
raise ChangeError, "There was an error creating the source branch: #{result[:message]}" raise ChangeError, "There was an error creating the source branch: #{result[:message]}"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment