Commit 185fd98f authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix-gitaly-not-found' into 'master'

Re-enable ref operations with gitaly after not-found fix

See merge request !10773
parents 2a73f0a6 5e0e5801
...@@ -45,17 +45,13 @@ module Gitlab ...@@ -45,17 +45,13 @@ module Gitlab
# Default branch in the repository # Default branch in the repository
def root_ref def root_ref
# NOTE: This feature is intentionally disabled until @root_ref ||= gitaly_migrate(:root_ref) do |is_enabled|
# https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved if is_enabled
# @root_ref ||= Gitlab::GitalyClient.migrate(:root_ref) do |is_enabled| gitaly_ref_client.default_branch_name
# if is_enabled else
# gitaly_ref_client.default_branch_name discover_default_branch
# else end
@root_ref ||= discover_default_branch end
# end
# end
rescue GRPC::BadStatus => e
raise CommandError.new(e)
end end
# Alias to old method for compatibility # Alias to old method for compatibility
...@@ -72,17 +68,13 @@ module Gitlab ...@@ -72,17 +68,13 @@ module Gitlab
# Returns an Array of branch names # Returns an Array of branch names
# sorted by name ASC # sorted by name ASC
def branch_names def branch_names
# Gitlab::GitalyClient.migrate(:branch_names) do |is_enabled| gitaly_migrate(:branch_names) do |is_enabled|
# NOTE: This feature is intentionally disabled until if is_enabled
# https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved gitaly_ref_client.branch_names
# if is_enabled else
# gitaly_ref_client.branch_names branches.map(&:name)
# else end
branches.map(&:name) end
# end
# end
rescue GRPC::BadStatus => e
raise CommandError.new(e)
end end
# Returns an Array of Branches # Returns an Array of Branches
...@@ -152,17 +144,13 @@ module Gitlab ...@@ -152,17 +144,13 @@ module Gitlab
# Returns an Array of tag names # Returns an Array of tag names
def tag_names def tag_names
# Gitlab::GitalyClient.migrate(:tag_names) do |is_enabled| gitaly_migrate(:tag_names) do |is_enabled|
# NOTE: This feature is intentionally disabled until if is_enabled
# https://gitlab.com/gitlab-org/gitaly/issues/179 is resolved gitaly_ref_client.tag_names
# if is_enabled else
# gitaly_ref_client.tag_names rugged.tags.map { |t| t.name }
# else end
rugged.tags.map { |t| t.name } end
# end
# end
rescue GRPC::BadStatus => e
raise CommandError.new(e)
end end
# Returns an Array of Tags # Returns an Array of Tags
...@@ -1294,6 +1282,14 @@ module Gitlab ...@@ -1294,6 +1282,14 @@ module Gitlab
@gitaly_commit_client ||= Gitlab::GitalyClient::Commit.new(self) @gitaly_commit_client ||= Gitlab::GitalyClient::Commit.new(self)
end end
def gitaly_migrate(method, &block)
Gitlab::GitalyClient.migrate(method, &block)
rescue GRPC::NotFound => e
raise NoRepository.new(e)
rescue GRPC::BadStatus => e
raise CommandError.new(e)
end
# Returns the `Rugged` sorting type constant for a given # Returns the `Rugged` sorting type constant for a given
# sort type key. Valid keys are `:none`, `:topo`, and `:date` # sort type key. Valid keys are `:none`, `:topo`, and `:date`
def rugged_sort_type(key) def rugged_sort_type(key)
......
...@@ -11,7 +11,9 @@ module Gitlab ...@@ -11,7 +11,9 @@ module Gitlab
def default_branch_name def default_branch_name
request = Gitaly::FindDefaultBranchNameRequest.new(repository: @gitaly_repo) request = Gitaly::FindDefaultBranchNameRequest.new(repository: @gitaly_repo)
stub.find_default_branch_name(request).name.gsub(/^refs\/heads\//, '') branch_name = stub.find_default_branch_name(request).name
Gitlab::Git.branch_name(branch_name)
end end
def branch_names def branch_names
......
...@@ -24,21 +24,26 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -24,21 +24,26 @@ describe Gitlab::Git::Repository, seed_helper: true do
end end
end end
# TODO: Uncomment when feature is reenabled context 'with gitaly enabled' do
# context 'with gitaly enabled' do before { stub_gitaly }
# before { stub_gitaly }
# it 'gets the branch name from GitalyClient' do
# it 'gets the branch name from GitalyClient' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name)
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name) repository.root_ref
# repository.root_ref end
# end
# it 'wraps GRPC not found' do
# it 'wraps GRPC exceptions' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name).
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name). and_raise(GRPC::NotFound)
# and_raise(GRPC::Unknown) expect { repository.root_ref }.to raise_error(Gitlab::Git::Repository::NoRepository)
# expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError) end
# end
# end it 'wraps GRPC exceptions' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:default_branch_name).
and_raise(GRPC::Unknown)
expect { repository.root_ref }.to raise_error(Gitlab::Git::CommandError)
end
end
end end
describe "#rugged" do describe "#rugged" do
...@@ -113,21 +118,26 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -113,21 +118,26 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.to include("master") } it { is_expected.to include("master") }
it { is_expected.not_to include("branch-from-space") } it { is_expected.not_to include("branch-from-space") }
# TODO: Uncomment when feature is reenabled context 'with gitaly enabled' do
# context 'with gitaly enabled' do before { stub_gitaly }
# before { stub_gitaly }
# it 'gets the branch names from GitalyClient' do
# it 'gets the branch names from GitalyClient' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names)
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names) subject
# subject end
# end
# it 'wraps GRPC not found' do
# it 'wraps GRPC exceptions' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names).
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names). and_raise(GRPC::NotFound)
# and_raise(GRPC::Unknown) expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository)
# expect { subject }.to raise_error(Gitlab::Git::CommandError) end
# end
# end it 'wraps GRPC other exceptions' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:branch_names).
and_raise(GRPC::Unknown)
expect { subject }.to raise_error(Gitlab::Git::CommandError)
end
end
end end
describe '#tag_names' do describe '#tag_names' do
...@@ -145,21 +155,26 @@ describe Gitlab::Git::Repository, seed_helper: true do ...@@ -145,21 +155,26 @@ describe Gitlab::Git::Repository, seed_helper: true do
it { is_expected.to include("v1.0.0") } it { is_expected.to include("v1.0.0") }
it { is_expected.not_to include("v5.0.0") } it { is_expected.not_to include("v5.0.0") }
# TODO: Uncomment when feature is reenabled context 'with gitaly enabled' do
# context 'with gitaly enabled' do before { stub_gitaly }
# before { stub_gitaly }
# it 'gets the tag names from GitalyClient' do
# it 'gets the tag names from GitalyClient' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names)
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names) subject
# subject end
# end
# it 'wraps GRPC not found' do
# it 'wraps GRPC exceptions' do expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names).
# expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names). and_raise(GRPC::NotFound)
# and_raise(GRPC::Unknown) expect { subject }.to raise_error(Gitlab::Git::Repository::NoRepository)
# expect { subject }.to raise_error(Gitlab::Git::CommandError) end
# end
# end it 'wraps GRPC exceptions' do
expect_any_instance_of(Gitlab::GitalyClient::Ref).to receive(:tag_names).
and_raise(GRPC::Unknown)
expect { subject }.to raise_error(Gitlab::Git::CommandError)
end
end
end end
shared_examples 'archive check' do |extenstion| shared_examples 'archive check' do |extenstion|
......
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