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
fb49c94e
Commit
fb49c94e
authored
Aug 24, 2017
by
Andrew Newdigate
Committed by
Sean McGivern
Aug 24, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Delegate Repository::branch_exists? and ref_exists? to Gitlab::Git
parent
7ab4efa8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
65 additions
and
7 deletions
+65
-7
repository.rb
app/models/repository.rb
+10
-3
repository.rb
lib/gitlab/git/repository.rb
+23
-0
ref_service.rb
lib/gitlab/gitaly_client/ref_service.rb
+1
-1
calendar_spec.rb
spec/features/calendar_spec.rb
+1
-1
activity_spec.rb
spec/features/dashboard/activity_spec.rb
+1
-1
repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+28
-0
user_spec.rb
spec/models/user_spec.rb
+1
-1
No files found.
app/models/repository.rb
View file @
fb49c94e
...
...
@@ -206,12 +206,18 @@ class Repository
end
def
branch_exists?
(
branch_name
)
branch_names
.
include?
(
branch_name
)
return
false
unless
raw_repository
@branch_exists_memo
||=
Hash
.
new
do
|
hash
,
key
|
hash
[
key
]
=
raw_repository
.
branch_exists?
(
key
)
end
@branch_exists_memo
[
branch_name
]
end
def
ref_exists?
(
ref
)
rugged
.
references
.
exist
?
(
ref
)
rescue
Rugged
::
Reference
Error
!!
raw_repository
&
.
ref_exists
?
(
ref
)
rescue
Argument
Error
false
end
...
...
@@ -266,6 +272,7 @@ class Repository
def
expire_branches_cache
expire_method_caches
(
%i(branch_names branch_count)
)
@local_branches
=
nil
@branch_exists_memo
=
nil
end
def
expire_statistics_caches
...
...
lib/gitlab/git/repository.rb
View file @
fb49c94e
...
...
@@ -201,6 +201,19 @@ module Gitlab
end
end
# Returns true if the given ref name exists
#
# Ref names must start with `refs/`.
def
ref_exists?
(
ref_name
)
gitaly_migrate
(
:ref_exists
)
do
|
is_enabled
|
if
is_enabled
gitaly_ref_exists?
(
ref_name
)
else
rugged_ref_exists?
(
ref_name
)
end
end
end
# Returns true if the given tag exists
#
# name - The name of the tag as a String.
...
...
@@ -992,6 +1005,16 @@ module Gitlab
# Returns true if the given ref name exists
#
# Ref names must start with `refs/`.
def
rugged_ref_exists?
(
ref_name
)
raise
ArgumentError
,
'invalid refname'
unless
ref_name
.
start_with?
(
'refs/'
)
rugged
.
references
.
exist?
(
ref_name
)
rescue
Rugged
::
ReferenceError
false
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
...
...
lib/gitlab/gitaly_client/ref_service.rb
View file @
fb49c94e
...
...
@@ -71,7 +71,7 @@ module Gitlab
end
def
ref_exists?
(
ref_name
)
request
=
Gitaly
::
RefExistsRequest
.
new
(
repository:
@gitaly_repo
,
ref:
ref_name
)
request
=
Gitaly
::
RefExistsRequest
.
new
(
repository:
@gitaly_repo
,
ref:
GitalyClient
.
encode
(
ref_name
)
)
response
=
GitalyClient
.
call
(
@storage
,
:ref_service
,
:ref_exists
,
request
)
response
.
value
rescue
GRPC
::
InvalidArgument
=>
e
...
...
spec/features/calendar_spec.rb
View file @
fb49c94e
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
feature
'Contributions Calendar'
,
:js
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:contributed_project
)
{
create
(
:project
,
:public
)
}
let
(
:contributed_project
)
{
create
(
:project
,
:public
,
:repository
)
}
let
(
:issue_note
)
{
create
(
:note
,
project:
contributed_project
)
}
# Ex/ Sunday Jan 1, 2016
...
...
spec/features/dashboard/activity_spec.rb
View file @
fb49c94e
...
...
@@ -17,7 +17,7 @@ feature 'Dashboard > Activity' do
end
context
'event filters'
,
:js
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:merge_request
)
do
create
(
:merge_request
,
author:
user
,
source_project:
project
,
target_project:
project
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
fb49c94e
...
...
@@ -1110,6 +1110,34 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
'#ref_exists?'
do
shared_examples
'checks the existence of refs'
do
it
'returns true for an existing tag'
do
expect
(
repository
.
ref_exists?
(
'refs/heads/master'
)).
to
eq
(
true
)
end
it
'returns false for a non-existing tag'
do
expect
(
repository
.
ref_exists?
(
'refs/tags/THIS_TAG_DOES_NOT_EXIST'
)).
to
eq
(
false
)
end
it
'raises an ArgumentError for an empty string'
do
expect
{
repository
.
ref_exists?
(
''
)
}.
to
raise_error
(
ArgumentError
)
end
it
'raises an ArgumentError for an invalid ref'
do
expect
{
repository
.
ref_exists?
(
'INVALID'
)
}.
to
raise_error
(
ArgumentError
)
end
end
context
'when Gitaly ref_exists feature is enabled'
do
it_behaves_like
'checks the existence of refs'
end
context
'when Gitaly ref_exists feature is disabled'
,
skip_gitaly_mock:
true
do
it_behaves_like
'checks the existence of refs'
end
end
describe
'#tag_exists?'
do
shared_examples
'checks the existence of tags'
do
it
'returns true for an existing tag'
do
...
...
spec/models/user_spec.rb
View file @
fb49c94e
...
...
@@ -1356,7 +1356,7 @@ describe User do
end
it
"excludes push event if branch has been deleted"
do
allow_any_instance_of
(
Repository
).
to
receive
(
:branch_
names
).
and_return
([
'foo'
]
)
allow_any_instance_of
(
Repository
).
to
receive
(
:branch_
exists?
).
with
(
'master'
).
and_return
(
false
)
expect
(
subject
.
recent_push
).
to
eq
(
nil
)
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