Commit 3698d027 authored by Robert May's avatar Robert May

Propagate error on FF pre-receive failure

Ensure pre-receive hook errors are propagated to the GUI
when encountered on fast-forward merges.
parent 63432f37
......@@ -27,6 +27,7 @@ module MergeRequests
success
end
end
log_info("Merge process finished on JID #{merge_jid} with state #{state}")
rescue MergeError => e
handle_merge_error(log_message: e.message, save_message_on_model: true)
......@@ -89,7 +90,7 @@ module MergeRequests
repository.merge(current_user, source, merge_request, commit_message)
rescue Gitlab::Git::PreReceiveError => e
raise MergeError,
"Something went wrong during merge pre-receive hook. #{e.message}".strip
"GL-HOOK-ERR: Something went wrong during merge pre-receive hook. #{e.message}".strip
rescue => e
handle_merge_error(log_message: e.message)
raise_error('Something went wrong during merge')
......
---
title: Propagate error on FF pre-receive failure
merge_request: 35633
author:
type: fixed
......@@ -178,6 +178,10 @@ module Gitlab
timeout: GitalyClient.long_timeout
)
if response.pre_receive_error.present?
raise Gitlab::Git::PreReceiveError.new("GL-HOOK-ERR: pre-receive hook failed: #{response.pre_receive_error}")
end
Gitlab::Git::OperationService::BranchUpdate.from_gitaly(response.branch_update)
rescue GRPC::FailedPrecondition => e
raise Gitlab::Git::CommitError, e
......
......@@ -191,6 +191,20 @@ RSpec.describe Gitlab::GitalyClient::OperationService do
it { expect(subject).to be_nil }
end
context "when the pre-receive hook fails" do
let(:response) do
Gitaly::UserFFBranchResponse.new(
branch_update: nil,
pre_receive_error: "pre-receive hook error message\n"
)
end
it "raises the error" do
# the PreReceiveError class strips the GL-HOOK-ERR prefix from this error
expect { subject }.to raise_error(Gitlab::Git::PreReceiveError, "pre-receive hook failed: pre-receive hook error message")
end
end
end
shared_examples 'cherry pick and revert errors' do
......
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