Commit 87c504e5 authored by Pavel Shutsin's avatar Pavel Shutsin

Merge branch 'sh-show-rebase-pre-receive-error' into 'master'

Show rebase pre-receive error to user

See merge request gitlab-org/gitlab!75496
parents a9a8dd14 67249980
......@@ -4,7 +4,7 @@ module MergeRequests
class RebaseService < MergeRequests::BaseService
REBASE_ERROR = 'Rebase failed. Please rebase locally'
attr_reader :merge_request
attr_reader :merge_request, :rebase_error
def execute(merge_request, skip_ci: false)
@merge_request = merge_request
......@@ -13,7 +13,7 @@ module MergeRequests
if rebase
success
else
error(REBASE_ERROR)
error(rebase_error)
end
end
......@@ -22,11 +22,23 @@ module MergeRequests
true
rescue StandardError => e
log_error(exception: e, message: REBASE_ERROR, save_message_on_model: true)
set_rebase_error(e)
log_error(exception: e, message: rebase_error, save_message_on_model: true)
false
ensure
merge_request.update_column(:rebase_jid, nil)
end
private
def set_rebase_error(exception)
@rebase_error =
if exception.is_a?(Gitlab::Git::PreReceiveError)
"Something went wrong during the rebase pre-receive hook: #{exception.message}."
else
REBASE_ERROR
end
end
end
end
......@@ -80,6 +80,27 @@ RSpec.describe MergeRequests::RebaseService do
end
end
context 'with a pre-receive failure' do
let(:pre_receive_error) { "Commit message does not follow the pattern 'ACME'" }
let(:merge_error) { "Something went wrong during the rebase pre-receive hook: #{pre_receive_error}." }
before do
allow(repository).to receive(:gitaly_operation_client).and_raise(Gitlab::Git::PreReceiveError, "GitLab: #{pre_receive_error}")
end
it 'saves a specific message' do
subject.execute(merge_request)
expect(merge_request.reload.merge_error).to eq merge_error
end
it 'returns an error' do
expect(service.execute(merge_request)).to match(
status: :error,
message: merge_error)
end
end
context 'with git command failure' do
before do
allow(repository).to receive(:gitaly_operation_client).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong')
......
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