Commit d5b0c7e3 authored by Shinya Maeda's avatar Shinya Maeda

Fix MergeToRefService raises Gitlab::Git::CommandError

This commit fixes the problem that can disturb merge train
process.
parent 11cfef67
......@@ -60,7 +60,7 @@ module MergeRequests
def commit
repository.merge_to_ref(current_user, source, merge_request, target_ref, commit_message, first_parent_ref)
rescue Gitlab::Git::PreReceiveError => error
rescue Gitlab::Git::PreReceiveError, Gitlab::Git::CommandError => error
raise MergeError, error.message
end
end
......
---
title: Fix MergeToRefService raises Gitlab::Git::CommandError
merge_request: 26465
author:
type: fixed
......@@ -118,6 +118,18 @@ describe MergeTrains::CreatePipelineService do
let(:expected_reason) { '3:Invalid merge source' }
end
end
context 'when there is a conflict on merge ref creation' do
before do
allow(project.repository).to receive(:merge_to_ref) do
raise Gitlab::Git::CommandError.new('Failed to create merge commit')
end
end
it_behaves_like 'returns an error' do
let(:expected_reason) { 'Failed to create merge commit' }
end
end
end
context 'when previous_ref is nil' do
......
......@@ -91,6 +91,17 @@ describe MergeRequests::MergeToRefService do
it_behaves_like 'successfully evaluates pre-condition checks'
it 'returns an error when Gitlab::Git::CommandError is raised during merge' do
allow(project.repository).to receive(:merge_to_ref) do
raise Gitlab::Git::CommandError.new('Failed to create merge commit')
end
result = service.execute(merge_request)
expect(result[:status]).to eq(:error)
expect(result[:message]).to eq('Failed to create merge commit')
end
context 'commit history comparison with regular MergeService' do
before do
# The merge service needs an authorized user while merge-to-ref
......
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