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
cfef1e8e
Commit
cfef1e8e
authored
Jul 25, 2019
by
Douwe Maan
Committed by
Nick Thomas
Jul 26, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix error rendering submodules in MR diffs when there is no .gitmodules
Without this change, we get a NoMethodError on nil
parent
57aabe16
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
75 additions
and
3 deletions
+75
-3
app/helpers/submodule_helper.rb
app/helpers/submodule_helper.rb
+2
-0
changelogs/unreleased/dm-submodule-links-nil.yml
changelogs/unreleased/dm-submodule-links-nil.yml
+5
-0
lib/gitlab/submodule_links.rb
lib/gitlab/submodule_links.rb
+8
-3
spec/helpers/submodule_helper_spec.rb
spec/helpers/submodule_helper_spec.rb
+13
-0
spec/lib/gitlab/submodule_links_spec.rb
spec/lib/gitlab/submodule_links_spec.rb
+47
-0
No files found.
app/helpers/submodule_helper.rb
View file @
cfef1e8e
...
@@ -13,6 +13,8 @@ module SubmoduleHelper
...
@@ -13,6 +13,8 @@ module SubmoduleHelper
end
end
def
submodule_links_for_url
(
submodule_item_id
,
url
,
repository
)
def
submodule_links_for_url
(
submodule_item_id
,
url
,
repository
)
return
[
nil
,
nil
]
unless
url
if
url
==
'.'
||
url
==
'./'
if
url
==
'.'
||
url
==
'./'
url
=
File
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
repository
.
project
.
full_path
)
url
=
File
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
repository
.
project
.
full_path
)
end
end
...
...
changelogs/unreleased/dm-submodule-links-nil.yml
0 → 100644
View file @
cfef1e8e
---
title
:
Fix error rendering submodules in MR diffs when there is no .gitmodules
merge_request
:
31162
author
:
type
:
fixed
lib/gitlab/submodule_links.rb
View file @
cfef1e8e
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
end
end
def
for
(
submodule
,
sha
)
def
for
(
submodule
,
sha
)
submodule_url
=
submodule_url_for
(
sha
)[
submodule
.
path
]
submodule_url
=
submodule_url_for
(
sha
,
submodule
.
path
)
SubmoduleHelper
.
submodule_links_for_url
(
submodule
.
id
,
submodule_url
,
repository
)
SubmoduleHelper
.
submodule_links_for_url
(
submodule
.
id
,
submodule_url
,
repository
)
end
end
...
@@ -17,10 +17,15 @@ module Gitlab
...
@@ -17,10 +17,15 @@ module Gitlab
attr_reader
:repository
attr_reader
:repository
def
submodule_url_for
(
sha
)
def
submodule_url
s
_for
(
sha
)
strong_memoize
(
:"submodule_
link
s_for_
#{
sha
}
"
)
do
strong_memoize
(
:"submodule_
url
s_for_
#{
sha
}
"
)
do
repository
.
submodule_urls_for
(
sha
)
repository
.
submodule_urls_for
(
sha
)
end
end
end
end
def
submodule_url_for
(
sha
,
path
)
urls
=
submodule_urls_for
(
sha
)
urls
&&
urls
[
path
]
end
end
end
end
end
spec/helpers/submodule_helper_spec.rb
View file @
cfef1e8e
...
@@ -229,6 +229,19 @@ describe SubmoduleHelper do
...
@@ -229,6 +229,19 @@ describe SubmoduleHelper do
end
end
end
end
end
end
context
'unknown submodule'
do
before
do
# When there is no `.gitmodules` file, or if `.gitmodules` does not
# know the submodule at the specified path,
# `Repository#submodule_url_for` returns `nil`
stub_url
(
nil
)
end
it
'returns no links'
do
expect
(
subject
).
to
eq
([
nil
,
nil
])
end
end
end
end
context
'as view helpers in view context'
do
context
'as view helpers in view context'
do
...
...
spec/lib/gitlab/submodule_links_spec.rb
0 → 100644
View file @
cfef1e8e
# frozen_string_literal: true
require
'spec_helper'
describe
Gitlab
::
SubmoduleLinks
do
let
(
:submodule_item
)
{
double
(
id:
'hash'
,
path:
'gitlab-ce'
)
}
let
(
:repo
)
{
double
}
let
(
:links
)
{
described_class
.
new
(
repo
)
}
describe
'#for'
do
subject
{
links
.
for
(
submodule_item
,
'ref'
)
}
context
'when there is no .gitmodules file'
do
before
do
stub_urls
(
nil
)
end
it
'returns no links'
do
expect
(
subject
).
to
eq
([
nil
,
nil
])
end
end
context
'when the submodule is unknown'
do
before
do
stub_urls
({
'path'
=>
'url'
})
end
it
'returns no links'
do
expect
(
subject
).
to
eq
([
nil
,
nil
])
end
end
context
'when the submodule is known'
do
before
do
stub_urls
({
'gitlab-ce'
=>
'git@gitlab.com:gitlab-org/gitlab-ce.git'
})
end
it
'returns links'
do
expect
(
subject
).
to
eq
([
'https://gitlab.com/gitlab-org/gitlab-ce'
,
'https://gitlab.com/gitlab-org/gitlab-ce/tree/hash'
])
end
end
end
def
stub_urls
(
urls
)
allow
(
repo
).
to
receive
(
:submodule_urls_for
).
and_return
(
urls
)
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