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
24d68225
Commit
24d68225
authored
Nov 20, 2018
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move Project#resolve_ref to Repository
parent
d12bc3bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
65 additions
and
67 deletions
+65
-67
app/models/project.rb
app/models/project.rb
+1
-16
app/models/repository.rb
app/models/repository.rb
+15
-0
lib/gitlab/ci/pipeline/chain/validate/repository.rb
lib/gitlab/ci/pipeline/chain/validate/repository.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+1
-50
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+47
-0
No files found.
app/models/project.rb
View file @
24d68225
...
@@ -1160,21 +1160,6 @@ class Project < ActiveRecord::Base
...
@@ -1160,21 +1160,6 @@ class Project < ActiveRecord::Base
end
end
end
end
def
resolve_ref
(
ref
)
tag_exists
=
repository
.
tag_exists?
(
ref
)
branch_exists
=
repository
.
branch_exists?
(
ref
)
if
tag_exists
&&
branch_exists
nil
elsif
tag_exists
Gitlab
::
Git
::
TAG_REF_PREFIX
+
ref
elsif
branch_exists
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
else
ref
end
end
def
root_ref?
(
branch
)
def
root_ref?
(
branch
)
repository
.
root_ref
==
branch
repository
.
root_ref
==
branch
end
end
...
@@ -1752,7 +1737,7 @@ class Project < ActiveRecord::Base
...
@@ -1752,7 +1737,7 @@ class Project < ActiveRecord::Base
end
end
def
protected_for?
(
ref
)
def
protected_for?
(
ref
)
resolved_ref
=
resolve_ref
(
ref
)
resolved_ref
=
re
pository
.
re
solve_ref
(
ref
)
return
false
unless
resolved_ref
return
false
unless
resolved_ref
ref_name
=
Gitlab
::
Git
.
ref_name
(
resolved_ref
)
ref_name
=
Gitlab
::
Git
.
ref_name
(
resolved_ref
)
...
...
app/models/repository.rb
View file @
24d68225
...
@@ -182,6 +182,21 @@ class Repository
...
@@ -182,6 +182,21 @@ class Repository
tags
.
find
{
|
tag
|
tag
.
name
==
name
}
tags
.
find
{
|
tag
|
tag
.
name
==
name
}
end
end
def
resolve_ref
(
ref
)
tag_exists
=
tag_exists?
(
ref
)
branch_exists
=
branch_exists?
(
ref
)
if
tag_exists
&&
branch_exists
nil
elsif
tag_exists
Gitlab
::
Git
::
TAG_REF_PREFIX
+
ref
elsif
branch_exists
Gitlab
::
Git
::
BRANCH_REF_PREFIX
+
ref
else
ref
end
end
def
add_branch
(
user
,
branch_name
,
ref
)
def
add_branch
(
user
,
branch_name
,
ref
)
branch
=
raw_repository
.
add_branch
(
branch_name
,
user:
user
,
target:
ref
)
branch
=
raw_repository
.
add_branch
(
branch_name
,
user:
user
,
target:
ref
)
...
...
lib/gitlab/ci/pipeline/chain/validate/repository.rb
View file @
24d68225
...
@@ -17,7 +17,7 @@ module Gitlab
...
@@ -17,7 +17,7 @@ module Gitlab
return
error
(
'Commit not found'
)
return
error
(
'Commit not found'
)
end
end
unless
@command
.
project
.
resolve_ref
(
@command
.
origin_ref
)
unless
@command
.
project
.
re
pository
.
re
solve_ref
(
@command
.
origin_ref
)
return
error
(
'Ref is ambiguous'
)
return
error
(
'Ref is ambiguous'
)
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
24d68225
...
@@ -2568,7 +2568,7 @@ describe Project do
...
@@ -2568,7 +2568,7 @@ describe Project do
subject
{
project
.
protected_for?
(
'ref'
)
}
subject
{
project
.
protected_for?
(
'ref'
)
}
before
do
before
do
allow
(
project
).
to
receive
(
:resolve_ref
).
and_return
(
ref
)
allow
(
project
.
repository
).
to
receive
(
:resolve_ref
).
and_return
(
ref
)
end
end
context
'when ref is ambiguous'
do
context
'when ref is ambiguous'
do
...
@@ -2796,55 +2796,6 @@ describe Project do
...
@@ -2796,55 +2796,6 @@ describe Project do
end
end
end
end
describe
'#resolve_ref'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
subject
{
project
.
resolve_ref
(
ref
)
}
context
'when ref is full ref'
do
let
(
:ref
)
{
'refs/heads/master'
}
it
'returns the ref'
do
is_expected
.
to
eq
(
ref
)
end
end
context
'when ref is a tag or branch name'
do
let
(
:ref
)
{
'ref'
}
context
'when ref is ambiguous'
do
before
do
project
.
repository
.
add_tag
(
project
.
creator
,
ref
,
'master'
)
project
.
repository
.
add_branch
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns nil'
do
is_expected
.
to
eq
(
nil
)
end
end
context
'when ref is tag name'
do
before
do
project
.
repository
.
add_tag
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns the tag ref'
do
is_expected
.
to
eq
(
"refs/tags/
#{
ref
}
"
)
end
end
context
'when ref is branch name'
do
before
do
project
.
repository
.
add_branch
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns the branch ref'
do
is_expected
.
to
eq
(
"refs/heads/
#{
ref
}
"
)
end
end
end
end
describe
'#http_url_to_repo'
do
describe
'#http_url_to_repo'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/models/repository_spec.rb
View file @
24d68225
...
@@ -1005,6 +1005,53 @@ describe Repository do
...
@@ -1005,6 +1005,53 @@ describe Repository do
end
end
end
end
describe
'#resolve_ref'
do
subject
{
repository
.
resolve_ref
(
ref
)
}
context
'when ref is full ref'
do
let
(
:ref
)
{
'refs/heads/master'
}
it
'returns the ref'
do
is_expected
.
to
eq
(
ref
)
end
end
context
'when ref is a tag or branch name'
do
let
(
:ref
)
{
'ref'
}
context
'when ref is ambiguous'
do
before
do
repository
.
add_tag
(
project
.
creator
,
ref
,
'master'
)
repository
.
add_branch
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns nil'
do
is_expected
.
to
eq
(
nil
)
end
end
context
'when ref is tag name'
do
before
do
repository
.
add_tag
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns the tag ref'
do
is_expected
.
to
eq
(
"refs/tags/
#{
ref
}
"
)
end
end
context
'when ref is branch name'
do
before
do
repository
.
add_branch
(
project
.
creator
,
ref
,
'master'
)
end
it
'returns the branch ref'
do
is_expected
.
to
eq
(
"refs/heads/
#{
ref
}
"
)
end
end
end
end
describe
'#add_branch'
do
describe
'#add_branch'
do
let
(
:branch_name
)
{
'new_feature'
}
let
(
:branch_name
)
{
'new_feature'
}
let
(
:target
)
{
'master'
}
let
(
:target
)
{
'master'
}
...
...
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