Merge branch 'zj-repo-exists-gitaly' into 'master'
Implement GRPC call to RepositoryService See merge request !13019
This commit is contained in:
commit
695f5085a1
|
@ -471,8 +471,17 @@ class Repository
|
||||||
end
|
end
|
||||||
cache_method :root_ref
|
cache_method :root_ref
|
||||||
|
|
||||||
|
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/314
|
||||||
def exists?
|
def exists?
|
||||||
refs_directory_exists?
|
return false unless path_with_namespace
|
||||||
|
|
||||||
|
Gitlab::GitalyClient.migrate(:repository_exists) do |enabled|
|
||||||
|
if enabled
|
||||||
|
raw_repository.exists?
|
||||||
|
else
|
||||||
|
refs_directory_exists?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
cache_method :exists?
|
cache_method :exists?
|
||||||
|
|
||||||
|
@ -1095,8 +1104,6 @@ class Repository
|
||||||
end
|
end
|
||||||
|
|
||||||
def refs_directory_exists?
|
def refs_directory_exists?
|
||||||
return false unless path_with_namespace
|
|
||||||
|
|
||||||
File.exist?(File.join(path_to_repo, 'refs'))
|
File.exist?(File.join(path_to_repo, 'refs'))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ module Gitlab
|
||||||
:bare?,
|
:bare?,
|
||||||
to: :rugged
|
to: :rugged
|
||||||
|
|
||||||
|
delegate :exists?, to: :gitaly_repository_client
|
||||||
|
|
||||||
# Default branch in the repository
|
# Default branch in the repository
|
||||||
def root_ref
|
def root_ref
|
||||||
@root_ref ||= gitaly_migrate(:root_ref) do |is_enabled|
|
@root_ref ||= gitaly_migrate(:root_ref) do |is_enabled|
|
||||||
|
@ -208,10 +210,6 @@ module Gitlab
|
||||||
!empty?
|
!empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def repo_exists?
|
|
||||||
!!rugged
|
|
||||||
end
|
|
||||||
|
|
||||||
# Discovers the default branch based on the repository's available branches
|
# Discovers the default branch based on the repository's available branches
|
||||||
#
|
#
|
||||||
# - If no branches are present, returns nil
|
# - If no branches are present, returns nil
|
||||||
|
@ -815,6 +813,10 @@ module Gitlab
|
||||||
@gitaly_commit_client ||= Gitlab::GitalyClient::CommitService.new(self)
|
@gitaly_commit_client ||= Gitlab::GitalyClient::CommitService.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def gitaly_repository_client
|
||||||
|
@gitaly_repository_client ||= Gitlab::GitalyClient::RepositoryService.new(self)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Gitaly note: JV: Trying to get rid of the 'filter' option so we can implement this with 'git'.
|
# Gitaly note: JV: Trying to get rid of the 'filter' option so we can implement this with 'git'.
|
||||||
|
|
|
@ -57,7 +57,7 @@ module Gitlab
|
||||||
metadata = yield(metadata) if block_given?
|
metadata = yield(metadata) if block_given?
|
||||||
stub(service, storage).send(rpc, request, metadata)
|
stub(service, storage).send(rpc, request, metadata)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.request_metadata(storage)
|
def self.request_metadata(storage)
|
||||||
encoded_token = Base64.strict_encode64(token(storage).to_s)
|
encoded_token = Base64.strict_encode64(token(storage).to_s)
|
||||||
{ metadata: { 'authorization' => "Bearer #{encoded_token}" } }
|
{ metadata: { 'authorization' => "Bearer #{encoded_token}" } }
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
module Gitlab
|
||||||
|
module GitalyClient
|
||||||
|
class RepositoryService
|
||||||
|
def initialize(repository)
|
||||||
|
@repository = repository
|
||||||
|
@gitaly_repo = repository.gitaly_repository
|
||||||
|
end
|
||||||
|
|
||||||
|
def exists?
|
||||||
|
request = Gitaly::RepositoryExistsRequest.new(repository: @gitaly_repo)
|
||||||
|
|
||||||
|
GitalyClient.call(@repository.storage, :repository_service, :exists, request).exists
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,19 @@
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Gitlab::GitalyClient::RepositoryService do
|
||||||
|
set(:project) { create(:empty_project) }
|
||||||
|
let(:storage_name) { project.repository_storage }
|
||||||
|
let(:relative_path) { project.path_with_namespace + '.git' }
|
||||||
|
let(:client) { described_class.new(project.repository) }
|
||||||
|
|
||||||
|
describe '#exists?' do
|
||||||
|
it 'sends an exists message' do
|
||||||
|
expect_any_instance_of(Gitaly::RepositoryService::Stub)
|
||||||
|
.to receive(:exists)
|
||||||
|
.with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash))
|
||||||
|
.and_call_original
|
||||||
|
|
||||||
|
client.exists?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -956,24 +956,28 @@ describe Repository, models: true do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#exists?' do
|
shared_examples 'repo exists check' do
|
||||||
it 'returns true when a repository exists' do
|
it 'returns true when a repository exists' do
|
||||||
expect(repository.exists?).to eq(true)
|
expect(repository.exists?).to eq(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns false when a repository does not exist' do
|
it 'returns false if no full path can be constructed' do
|
||||||
allow(repository).to receive(:refs_directory_exists?).and_return(false)
|
|
||||||
|
|
||||||
expect(repository.exists?).to eq(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'returns false when there is no namespace' do
|
|
||||||
allow(repository).to receive(:path_with_namespace).and_return(nil)
|
allow(repository).to receive(:path_with_namespace).and_return(nil)
|
||||||
|
|
||||||
expect(repository.exists?).to eq(false)
|
expect(repository.exists?).to eq(false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#exists?' do
|
||||||
|
context 'when repository_exists is disabled' do
|
||||||
|
it_behaves_like 'repo exists check'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when repository_exists is enabled', skip_gitaly_mock: true do
|
||||||
|
it_behaves_like 'repo exists check'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#has_visible_content?' do
|
describe '#has_visible_content?' do
|
||||||
subject { repository.has_visible_content? }
|
subject { repository.has_visible_content? }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue