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
d7950bbf
Commit
d7950bbf
authored
Jul 13, 2018
by
Mario de la Ossa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SubmoduleHelper - Project is not always available as an instance variable
parent
6717643c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
17 deletions
+12
-17
app/helpers/submodule_helper.rb
app/helpers/submodule_helper.rb
+4
-4
spec/helpers/submodule_helper_spec.rb
spec/helpers/submodule_helper_spec.rb
+8
-13
No files found.
app/helpers/submodule_helper.rb
View file @
d7950bbf
...
@@ -8,7 +8,7 @@ module SubmoduleHelper
...
@@ -8,7 +8,7 @@ module SubmoduleHelper
url
=
repository
.
submodule_url_for
(
ref
,
submodule_item
.
path
)
url
=
repository
.
submodule_url_for
(
ref
,
submodule_item
.
path
)
if
url
==
'.'
||
url
==
'./'
if
url
==
'.'
||
url
==
'./'
url
=
File
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
@
project
.
full_path
)
url
=
File
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
repository
.
project
.
full_path
)
end
end
if
url
=~
%r{([^/:]+)/([^/]+(?:
\.
git)?)
\Z
}
if
url
=~
%r{([^/:]+)/([^/]+(?:
\.
git)?)
\Z
}
...
@@ -31,7 +31,7 @@ module SubmoduleHelper
...
@@ -31,7 +31,7 @@ module SubmoduleHelper
[
namespace_project_path
(
namespace
,
project
),
[
namespace_project_path
(
namespace
,
project
),
namespace_project_tree_path
(
namespace
,
project
,
submodule_item
.
id
)]
namespace_project_tree_path
(
namespace
,
project
,
submodule_item
.
id
)]
elsif
relative_self_url?
(
url
)
elsif
relative_self_url?
(
url
)
relative_self_links
(
url
,
submodule_item
.
id
)
relative_self_links
(
url
,
submodule_item
.
id
,
repository
.
project
)
elsif
github_dot_com_url?
(
url
)
elsif
github_dot_com_url?
(
url
)
standard_links
(
'github.com'
,
namespace
,
project
,
submodule_item
.
id
)
standard_links
(
'github.com'
,
namespace
,
project
,
submodule_item
.
id
)
elsif
gitlab_dot_com_url?
(
url
)
elsif
gitlab_dot_com_url?
(
url
)
...
@@ -73,7 +73,7 @@ module SubmoduleHelper
...
@@ -73,7 +73,7 @@ module SubmoduleHelper
[
base
,
[
base
,
'/tree/'
,
commit
].
join
(
''
)]
[
base
,
[
base
,
'/tree/'
,
commit
].
join
(
''
)]
end
end
def
relative_self_links
(
url
,
commit
)
def
relative_self_links
(
url
,
commit
,
project
)
url
.
rstrip!
url
.
rstrip!
# Map relative links to a namespace and project
# Map relative links to a namespace and project
# For example:
# For example:
...
@@ -85,7 +85,7 @@ module SubmoduleHelper
...
@@ -85,7 +85,7 @@ module SubmoduleHelper
namespace
=
components
.
pop
.
gsub
(
/^\.\.$/
,
''
)
namespace
=
components
.
pop
.
gsub
(
/^\.\.$/
,
''
)
if
namespace
.
empty?
if
namespace
.
empty?
namespace
=
@
project
.
namespace
.
full_path
namespace
=
project
.
namespace
.
full_path
end
end
begin
begin
...
...
spec/helpers/submodule_helper_spec.rb
View file @
d7950bbf
...
@@ -92,11 +92,10 @@ describe SubmoduleHelper do
...
@@ -92,11 +92,10 @@ describe SubmoduleHelper do
context
'in-repository submodule'
do
context
'in-repository submodule'
do
let
(
:group
)
{
create
(
:group
,
name:
"Master Project"
,
path:
"master-project"
)
}
let
(
:group
)
{
create
(
:group
,
name:
"Master Project"
,
path:
"master-project"
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
before
do
self
.
instance_variable_set
(
:@project
,
project
)
end
it
'in-repository'
do
it
'in-repository'
do
allow
(
repo
).
to
receive
(
:project
).
and_return
(
project
)
stub_url
(
'./'
)
stub_url
(
'./'
)
expect
(
submodule_links
(
submodule_item
)).
to
eq
([
"/master-project/
#{
project
.
path
}
"
,
"/master-project/
#{
project
.
path
}
/tree/hash"
])
expect
(
submodule_links
(
submodule_item
)).
to
eq
([
"/master-project/
#{
project
.
path
}
"
,
"/master-project/
#{
project
.
path
}
/tree/hash"
])
end
end
...
@@ -167,32 +166,28 @@ describe SubmoduleHelper do
...
@@ -167,32 +166,28 @@ describe SubmoduleHelper do
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
let
(
:commit_id
)
{
sample_commit
[
:id
]
}
let
(
:commit_id
)
{
sample_commit
[
:id
]
}
before
do
self
.
instance_variable_set
(
:@project
,
project
)
end
it
'one level down'
do
it
'one level down'
do
result
=
relative_self_links
(
'../test.git'
,
commit_id
)
result
=
relative_self_links
(
'../test.git'
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
end
end
it
'with trailing whitespace'
do
it
'with trailing whitespace'
do
result
=
relative_self_links
(
'../test.git '
,
commit_id
)
result
=
relative_self_links
(
'../test.git '
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
end
end
it
'two levels down'
do
it
'two levels down'
do
result
=
relative_self_links
(
'../../test.git'
,
commit_id
)
result
=
relative_self_links
(
'../../test.git'
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/
#{
group
.
path
}
/test"
,
"/
#{
group
.
path
}
/test/tree/
#{
commit_id
}
"
])
end
end
it
'one level down with namespace and repo'
do
it
'one level down with namespace and repo'
do
result
=
relative_self_links
(
'../foobar/test.git'
,
commit_id
)
result
=
relative_self_links
(
'../foobar/test.git'
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/foobar/test"
,
"/foobar/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/foobar/test"
,
"/foobar/test/tree/
#{
commit_id
}
"
])
end
end
it
'two levels down with namespace and repo'
do
it
'two levels down with namespace and repo'
do
result
=
relative_self_links
(
'../foobar/baz/test.git'
,
commit_id
)
result
=
relative_self_links
(
'../foobar/baz/test.git'
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/baz/test"
,
"/baz/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/baz/test"
,
"/baz/test/tree/
#{
commit_id
}
"
])
end
end
...
@@ -201,7 +196,7 @@ describe SubmoduleHelper do
...
@@ -201,7 +196,7 @@ describe SubmoduleHelper do
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
it
'one level down with personal project'
do
it
'one level down with personal project'
do
result
=
relative_self_links
(
'../test.git'
,
commit_id
)
result
=
relative_self_links
(
'../test.git'
,
commit_id
,
project
)
expect
(
result
).
to
eq
([
"/
#{
user
.
username
}
/test"
,
"/
#{
user
.
username
}
/test/tree/
#{
commit_id
}
"
])
expect
(
result
).
to
eq
([
"/
#{
user
.
username
}
/test"
,
"/
#{
user
.
username
}
/test/tree/
#{
commit_id
}
"
])
end
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