Commit 695f5085 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'zj-repo-exists-gitaly' into 'master'

Implement GRPC call to RepositoryService

See merge request !13019
parents 121b90aa acf4a36b
...@@ -471,8 +471,17 @@ class Repository ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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}" } }
......
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
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,21 +956,25 @@ describe Repository, models: true do ...@@ -956,21 +956,25 @@ 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) 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
it 'returns false when there is no namespace' do describe '#exists?' do
allow(repository).to receive(:path_with_namespace).and_return(nil) context 'when repository_exists is disabled' do
it_behaves_like 'repo exists check'
end
expect(repository.exists?).to eq(false) context 'when repository_exists is enabled', skip_gitaly_mock: true do
it_behaves_like 'repo exists check'
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