Commit 4214e8b5 authored by Patrick Bajao's avatar Patrick Bajao

Fix conflict resolve to handle FailedPrecondition error correctly

Before this change, `Gitlab::Git::Conflict::Resolver#conflicts`
is meant to rescue `GRPC::FailedPrecondition` exception and re-raise
`Gitlab::Git::Conflict::Resolver::ConflictSideMissing`.

That wasn't working though as `wrapped_gitaly_errors` will rescue
it as a `GRPC::BadStatus` exception because that's the parent of
`GRPC::FailedPrecondition`.

That results to MR head diff not showing up when there are
conflicts with missing side.

This fix moves the rescue inside the `wrapped_gitaly_errors`
block so we can rescue appropriately.

Changelog: fixed
parent 7945d196
......@@ -18,9 +18,9 @@ module Gitlab
def conflicts
@conflicts ||= wrapped_gitaly_errors do
gitaly_conflicts_client(@target_repository).list_conflict_files.to_a
end
rescue GRPC::FailedPrecondition => e
raise Gitlab::Git::Conflict::Resolver::ConflictSideMissing, e.message
end
rescue GRPC::BadStatus => e
raise Gitlab::Git::CommandError, e
end
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Git::Conflict::Resolver do
let(:repository) { instance_double(Gitlab::Git::Repository) }
let(:our_commit_oid) { 'our-commit-oid' }
let(:their_commit_oid) { 'their-commit-oid' }
let(:gitaly_conflicts_client) { instance_double(Gitlab::GitalyClient::ConflictsService) }
subject(:resolver) { described_class.new(repository, our_commit_oid, their_commit_oid) }
describe '#conflicts' do
before do
allow(repository).to receive(:gitaly_conflicts_client).and_return(gitaly_conflicts_client)
end
it 'returns list of conflicts' do
conflicts = [double]
expect(gitaly_conflicts_client).to receive(:list_conflict_files).and_return(conflicts)
expect(resolver.conflicts).to eq(conflicts)
end
context 'when GRPC::FailedPrecondition is raised' do
it 'rescues and raises Gitlab::Git::Conflict::Resolver::ConflictSideMissing' do
expect(gitaly_conflicts_client).to receive(:list_conflict_files).and_raise(GRPC::FailedPrecondition)
expect { resolver.conflicts }.to raise_error(Gitlab::Git::Conflict::Resolver::ConflictSideMissing)
end
end
end
end
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