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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
7a07eceb
Commit
7a07eceb
authored
Jun 08, 2017
by
Kim Carlbäcker
Committed by
Douwe Maan
Jun 08, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nil-check Repository::is_ancestor?
parent
27f68edd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
8 deletions
+34
-8
app/models/repository.rb
app/models/repository.rb
+2
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+32
-8
No files found.
app/models/repository.rb
View file @
7a07eceb
...
...
@@ -946,6 +946,8 @@ class Repository
end
def
is_ancestor?
(
ancestor_id
,
descendant_id
)
return
false
if
ancestor_id
.
nil?
||
descendant_id
.
nil?
Gitlab
::
GitalyClient
.
migrate
(
:is_ancestor
)
do
|
is_enabled
|
if
is_enabled
raw_repository
.
is_ancestor?
(
ancestor_id
,
descendant_id
)
...
...
spec/models/repository_spec.rb
View file @
7a07eceb
...
...
@@ -1905,19 +1905,43 @@ describe Repository, models: true do
end
describe
'#is_ancestor?'
do
context
'Gitaly is_ancestor feature enabled'
do
let
(
:commit
)
{
repository
.
commit
}
let
(
:ancestor
)
{
commit
.
parents
.
first
}
let
(
:commit
)
{
repository
.
commit
}
let
(
:ancestor
)
{
commit
.
parents
.
first
}
context
'with Gitaly enabled'
do
it
'it is an ancestor'
do
expect
(
repository
.
is_ancestor?
(
ancestor
.
id
,
commit
.
id
)).
to
eq
(
true
)
end
it
'it is not an ancestor'
do
expect
(
repository
.
is_ancestor?
(
commit
.
id
,
ancestor
.
id
)).
to
eq
(
false
)
end
it
'returns false on nil-values'
do
expect
(
repository
.
is_ancestor?
(
nil
,
commit
.
id
)).
to
eq
(
false
)
expect
(
repository
.
is_ancestor?
(
ancestor
.
id
,
nil
)).
to
eq
(
false
)
expect
(
repository
.
is_ancestor?
(
nil
,
nil
)).
to
eq
(
false
)
end
end
context
'with Gitaly disabled'
do
before
do
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:enabled?
).
and_return
(
tru
e
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
with
(
:is_ancestor
).
and_return
(
tru
e
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:enabled?
).
and_return
(
fals
e
)
allow
(
Gitlab
::
GitalyClient
).
to
receive
(
:feature_enabled?
).
with
(
:is_ancestor
).
and_return
(
fals
e
)
end
it
"asks Gitaly server if it's an ancestor"
do
expect_any_instance_of
(
Gitlab
::
GitalyClient
::
Commit
).
to
receive
(
:is_ancestor
).
with
(
ancestor
.
id
,
commit
.
id
)
it
'it is an ancestor'
do
expect
(
repository
.
is_ancestor?
(
ancestor
.
id
,
commit
.
id
)).
to
eq
(
true
)
end
it
'it is not an ancestor'
do
expect
(
repository
.
is_ancestor?
(
commit
.
id
,
ancestor
.
id
)).
to
eq
(
false
)
end
repository
.
is_ancestor?
(
ancestor
.
id
,
commit
.
id
)
it
'returns false on nil-values'
do
expect
(
repository
.
is_ancestor?
(
nil
,
commit
.
id
)).
to
eq
(
false
)
expect
(
repository
.
is_ancestor?
(
ancestor
.
id
,
nil
)).
to
eq
(
false
)
expect
(
repository
.
is_ancestor?
(
nil
,
nil
)).
to
eq
(
false
)
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