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
eabf1a77
Commit
eabf1a77
authored
Jul 26, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
88235d38
55f99e93
Changes
5
Hide 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 @
eabf1a77
...
...
@@ -13,6 +13,8 @@ module SubmoduleHelper
end
def
submodule_links_for_url
(
submodule_item_id
,
url
,
repository
)
return
[
nil
,
nil
]
unless
url
if
url
==
'.'
||
url
==
'./'
url
=
File
.
join
(
Gitlab
.
config
.
gitlab
.
url
,
repository
.
project
.
full_path
)
end
...
...
changelogs/unreleased/dm-submodule-links-nil.yml
0 → 100644
View file @
eabf1a77
---
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 @
eabf1a77
...
...
@@ -9,7 +9,7 @@ module Gitlab
end
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
)
end
...
...
@@ -17,10 +17,15 @@ module Gitlab
attr_reader
:repository
def
submodule_url_for
(
sha
)
strong_memoize
(
:"submodule_
link
s_for_
#{
sha
}
"
)
do
def
submodule_url
s
_for
(
sha
)
strong_memoize
(
:"submodule_
url
s_for_
#{
sha
}
"
)
do
repository
.
submodule_urls_for
(
sha
)
end
end
def
submodule_url_for
(
sha
,
path
)
urls
=
submodule_urls_for
(
sha
)
urls
&&
urls
[
path
]
end
end
end
spec/helpers/submodule_helper_spec.rb
View file @
eabf1a77
...
...
@@ -229,6 +229,19 @@ describe SubmoduleHelper do
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
context
'as view helpers in view context'
do
...
...
spec/lib/gitlab/submodule_links_spec.rb
0 → 100644
View file @
eabf1a77
# 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