Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
cfef1e8e
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
cfef1e8e
编写于
7月 25, 2019
作者:
D
Douwe Maan
提交者:
Nick Thomas
7月 26, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix error rendering submodules in MR diffs when there is no .gitmodules
Without this change, we get a NoMethodError on nil
上级
57aabe16
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
75 addition
and
3 deletion
+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
未找到文件。
app/helpers/submodule_helper.rb
浏览文件 @
cfef1e8e
...
...
@@ -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
浏览文件 @
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
浏览文件 @
cfef1e8e
...
...
@@ -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
浏览文件 @
cfef1e8e
...
...
@@ -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
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录