Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
695f5085
Commit
695f5085
authored
Jul 26, 2017
by
Sean McGivern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'zj-repo-exists-gitaly' into 'master'
Implement GRPC call to RepositoryService See merge request !13019
parents
121b90aa
acf4a36b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
14 deletions
+62
-14
app/models/repository.rb
app/models/repository.rb
+10
-3
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+6
-4
lib/gitlab/gitaly_client.rb
lib/gitlab/gitaly_client.rb
+1
-1
lib/gitlab/gitaly_client/repository_service.rb
lib/gitlab/gitaly_client/repository_service.rb
+16
-0
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
+19
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+10
-6
No files found.
app/models/repository.rb
View file @
695f5085
...
...
@@ -471,8 +471,17 @@ class Repository
end
cache_method
:root_ref
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/314
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
cache_method
:exists?
...
...
@@ -1095,8 +1104,6 @@ class Repository
end
def
refs_directory_exists?
return
false
unless
path_with_namespace
File
.
exist?
(
File
.
join
(
path_to_repo
,
'refs'
))
end
...
...
lib/gitlab/git/repository.rb
View file @
695f5085
...
...
@@ -45,6 +45,8 @@ module Gitlab
:bare?
,
to: :rugged
delegate
:exists?
,
to: :gitaly_repository_client
# Default branch in the repository
def
root_ref
@root_ref
||=
gitaly_migrate
(
:root_ref
)
do
|
is_enabled
|
...
...
@@ -208,10 +210,6 @@ module Gitlab
!
empty?
end
def
repo_exists?
!!
rugged
end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
...
...
@@ -815,6 +813,10 @@ module Gitlab
@gitaly_commit_client
||=
Gitlab
::
GitalyClient
::
CommitService
.
new
(
self
)
end
def
gitaly_repository_client
@gitaly_repository_client
||=
Gitlab
::
GitalyClient
::
RepositoryService
.
new
(
self
)
end
private
# Gitaly note: JV: Trying to get rid of the 'filter' option so we can implement this with 'git'.
...
...
lib/gitlab/gitaly_client.rb
View file @
695f5085
...
...
@@ -57,7 +57,7 @@ module Gitlab
metadata
=
yield
(
metadata
)
if
block_given?
stub
(
service
,
storage
).
send
(
rpc
,
request
,
metadata
)
end
def
self
.
request_metadata
(
storage
)
encoded_token
=
Base64
.
strict_encode64
(
token
(
storage
).
to_s
)
{
metadata:
{
'authorization'
=>
"Bearer
#{
encoded_token
}
"
}
}
...
...
lib/gitlab/gitaly_client/repository_service.rb
0 → 100644
View file @
695f5085
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
spec/lib/gitlab/gitaly_client/repository_service_spec.rb
0 → 100644
View file @
695f5085
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
spec/models/repository_spec.rb
View file @
695f5085
...
...
@@ -956,21 +956,25 @@ describe Repository, models: true do
end
end
describe
'#exists?
'
do
shared_examples
'repo exists check
'
do
it
'returns true when a repository exists'
do
expect
(
repository
.
exists?
).
to
eq
(
true
)
end
it
'returns false
when a repository does not exist
'
do
allow
(
repository
).
to
receive
(
:
refs_directory_exists?
).
and_return
(
false
)
it
'returns false
if no full path can be constructed
'
do
allow
(
repository
).
to
receive
(
:
path_with_namespace
).
and_return
(
nil
)
expect
(
repository
.
exists?
).
to
eq
(
false
)
end
end
it
'returns false when there is no namespace'
do
allow
(
repository
).
to
receive
(
:path_with_namespace
).
and_return
(
nil
)
describe
'#exists?'
do
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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment