Commit eb25d62e authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'fix-merge-to-ref-service-raise-command-error' into 'master'

Fix MergeToRefService raises Gitlab::Git::CommandError

Closes #208913

See merge request gitlab-org/gitlab!26465
parents e3bb6031 d5b0c7e3
......@@ -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