BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
aaa887fe
Commit
aaa887fe
authored
Aug 14, 2017
by
Andrew Newdigate
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Client Implementation: RefService::RefExists
parent
6ed01ebf
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
95 additions
and
17 deletions
+95
-17
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
Gemfile
Gemfile
+1
-1
Gemfile.lock
Gemfile.lock
+2
-2
gitaly_ref_exists.yml
changelogs/unreleased/gitaly_ref_exists.yml
+4
-0
repository.rb
lib/gitlab/git/repository.rb
+42
-9
ref_service.rb
lib/gitlab/gitaly_client/ref_service.rb
+8
-0
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+20
-0
ref_service_spec.rb
spec/lib/gitlab/gitaly_client/ref_service_spec.rb
+17
-4
No files found.
GITALY_SERVER_VERSION
View file @
aaa887fe
0.3
1
.0
0.3
2
.0
Gemfile
View file @
aaa887fe
...
...
@@ -401,7 +401,7 @@ group :ed25519 do
end
# Gitaly GRPC client
gem
'
gitaly
'
,
'~> 0.2
7
.0'
gem
'
gitaly
'
,
'~> 0.2
9
.0'
gem
'
toml-rb
'
,
'~> 0.3.15'
,
require:
false
...
...
Gemfile.lock
View file @
aaa887fe
...
...
@@ -275,7 +275,7 @@ GEM
po_to_json (>= 1.0.0)
rails (>= 3.2.0)
gherkin-ruby (0.3.2)
gitaly (0.2
7
.0)
gitaly (0.2
9
.0)
google-protobuf (~> 3.1)
grpc (~> 1.0)
github-linguist (4.7.6)
...
...
@@ -1019,7 +1019,7 @@ DEPENDENCIES
gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0)
gitaly (~> 0.2
7
.0)
gitaly (~> 0.2
9
.0)
github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.5.1)
...
...
changelogs/unreleased/gitaly_ref_exists.yml
0 → 100644
View file @
aaa887fe
---
title
:
Implement the Gitaly RefService::RefExists endpoint
merge_request
:
13528
author
:
Andrew Newdigate
lib/gitlab/git/repository.rb
View file @
aaa887fe
...
...
@@ -204,21 +204,26 @@ module Gitlab
#
# name - The name of the tag as a String.
def
tag_exists?
(
name
)
!!
rugged
.
tags
[
name
]
gitaly_migrate
(
:ref_exists_tags
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_exists?
(
"refs/tags/
#{
name
}
"
)
else
rugged_tag_exists?
(
name
)
end
end
end
# Returns true if the given branch exists
#
# name - The name of the branch as a String.
def
branch_exists?
(
name
)
rugged
.
branches
.
exists?
(
name
)
# If the branch name is invalid (e.g. ".foo") Rugged will raise an error.
# Whatever code calls this method shouldn't have to deal with that so
# instead we just return `false` (which is true since a branch doesn't
# exist when it has an invalid name).
rescue
Rugged
::
ReferenceError
false
gitaly_migrate
(
:ref_exists_branches
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_exists?
(
"refs/heads/
#{
name
}
"
)
else
rugged_branch_exists?
(
name
)
end
end
end
# Returns an Array of branch and tag names
...
...
@@ -995,6 +1000,34 @@ module Gitlab
raw_output
.
compact
end
# Returns true if the given ref name exists
#
# Ref names must start with `refs/`.
def
gitaly_ref_exists?
(
ref_name
)
gitaly_ref_client
.
ref_exists?
(
ref_name
)
end
# Returns true if the given tag exists
#
# name - The name of the tag as a String.
def
rugged_tag_exists?
(
name
)
!!
rugged
.
tags
[
name
]
end
# Returns true if the given branch exists
#
# name - The name of the branch as a String.
def
rugged_branch_exists?
(
name
)
rugged
.
branches
.
exists?
(
name
)
# If the branch name is invalid (e.g. ".foo") Rugged will raise an error.
# Whatever code calls this method shouldn't have to deal with that so
# instead we just return `false` (which is true since a branch doesn't
# exist when it has an invalid name).
rescue
Rugged
::
ReferenceError
false
end
def
gitaly_copy_gitattributes
(
revision
)
gitaly_repository_client
.
apply_gitattributes
(
revision
)
end
...
...
lib/gitlab/gitaly_client/ref_service.rb
View file @
aaa887fe
...
...
@@ -70,6 +70,14 @@ module Gitlab
consume_tags_response
(
response
)
end
def
ref_exists?
(
ref_name
)
request
=
Gitaly
::
RefExistsRequest
.
new
(
repository:
@gitaly_repo
,
ref:
ref_name
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:ref_exists
,
request
)
response
.
value
rescue
GRPC
::
InvalidArgument
=>
e
raise
ArgumentError
,
e
.
message
end
private
def
consume_refs_response
(
response
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
aaa887fe
...
...
@@ -1098,6 +1098,7 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
describe
'#tag_exists?'
do
shared_examples
'checks the existence of tags'
do
it
'returns true for an existing tag'
do
tag
=
repository
.
tag_names
.
first
...
...
@@ -1109,7 +1110,17 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
context
'when Gitaly ref_exists_tags feature is enabled'
do
it_behaves_like
'checks the existence of tags'
end
context
'when Gitaly ref_exists_tags feature is disabled'
,
skip_gitaly_mock:
true
do
it_behaves_like
'checks the existence of tags'
end
end
describe
'#branch_exists?'
do
shared_examples
'checks the existence of branches'
do
it
'returns true for an existing branch'
do
expect
(
repository
.
branch_exists?
(
'master'
)).
to
eq
(
true
)
end
...
...
@@ -1123,6 +1134,15 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
context
'when Gitaly ref_exists_branches feature is enabled'
do
it_behaves_like
'checks the existence of branches'
end
context
'when Gitaly ref_exists_branches feature is disabled'
,
skip_gitaly_mock:
true
do
it_behaves_like
'checks the existence of branches'
end
end
describe
'#local_branches'
do
before
(
:all
)
do
@repo
=
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
File
.
join
(
TEST_MUTABLE_REPO_PATH
,
'.git'
))
...
...
spec/lib/gitlab/gitaly_client/ref_service_spec.rb
View file @
aaa887fe
require
'spec_helper'
describe
Gitlab
::
GitalyClient
::
RefService
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:storage_name
)
{
project
.
repository_storage
}
let
(
:relative_path
)
{
project
.
disk_path
+
'.git'
}
let
(
:client
)
{
described_class
.
new
(
project
.
repository
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:client
)
{
described_class
.
new
(
repository
)
}
describe
'#branches'
do
it
'sends a find_all_branches message'
do
...
...
@@ -84,11 +85,23 @@ describe Gitlab::GitalyClient::RefService do
end
describe
'#find_ref_name'
,
seed_helper:
true
do
let
(
:repository
)
{
Gitlab
::
Git
::
Repository
.
new
(
'default'
,
TEST_REPO_PATH
)
}
let
(
:client
)
{
described_class
.
new
(
repository
)
}
subject
{
client
.
find_ref_name
(
SeedRepo
::
Commit
::
ID
,
'refs/heads/master'
)
}
it
{
is_expected
.
to
be_utf8
}
it
{
is_expected
.
to
eq
(
'refs/heads/master'
)
}
end
describe
'#ref_exists?'
,
seed_helper:
true
do
it
'finds the master branch ref'
do
expect
(
client
.
ref_exists?
(
'refs/heads/master'
)).
to
eq
(
true
)
end
it
'returns false for an illegal tag name ref'
do
expect
(
client
.
ref_exists?
(
'refs/tags/.this-tag-name-is-illegal'
)).
to
eq
(
false
)
end
it
'raises an argument error if the ref name parameter does not start with refs/'
do
expect
{
client
.
ref_exists?
(
'reXXXXX'
)
}.
to
raise_error
(
ArgumentError
)
end
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