Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
dadc26d2
H
hub
项目概览
github
/
hub
大约 1 年 前同步成功
通知
3
Star
22523
Fork
2406
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
dadc26d2
编写于
3月 18, 2019
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow repository names that start with a dash character
These are allowed on GitHub.
上级
e820f9da
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
32 addition
and
24 deletion
+32
-24
commands/commands.go
commands/commands.go
+2
-2
commands/commands_test.go
commands/commands_test.go
+21
-0
commands/remote.go
commands/remote.go
+9
-12
commands/remote_test.go
commands/remote_test.go
+0
-10
未找到文件。
commands/commands.go
浏览文件 @
dadc26d2
...
...
@@ -9,9 +9,9 @@ import (
)
var
(
NameRe
=
"[
\\
w.][
\\
w.-]*"
NameRe
=
`[\w.-]+`
OwnerRe
=
"[a-zA-Z0-9][a-zA-Z0-9-]*"
NameWithOwnerRe
=
fmt
.
Sprintf
(
"^(?:%s|%s
\\
/%s)$"
,
NameRe
,
OwnerRe
,
NameRe
)
NameWithOwnerRe
=
fmt
.
Sprintf
(
`^(%s/)?%s$`
,
OwnerRe
,
NameRe
)
CmdRunner
=
NewRunner
()
)
...
...
commands/commands_test.go
浏览文件 @
dadc26d2
...
...
@@ -3,6 +3,7 @@ package commands
import
(
"io/ioutil"
"os"
"regexp"
"testing"
"github.com/bmizerany/assert"
...
...
@@ -123,3 +124,23 @@ func TestSubCommandCall(t *testing.T) {
c
.
Call
(
args
)
assert
.
Equal
(
t
,
"baz"
,
result
)
}
func
Test_NameWithOwnerRe
(
t
*
testing
.
T
)
{
re
:=
regexp
.
MustCompile
(
NameWithOwnerRe
)
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
"o/n"
))
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
"own-er/my-project.git"
))
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
"my-project.git"
))
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
"my_project"
))
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
"-dash"
))
assert
.
Equal
(
t
,
true
,
re
.
MatchString
(
".dotfiles"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
""
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"/"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
" "
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"owner/na me"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"owner/na/me"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"own.er/name"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"own_er/name"
))
assert
.
Equal
(
t
,
false
,
re
.
MatchString
(
"-owner/name"
))
}
commands/remote.go
浏览文件 @
dadc26d2
...
...
@@ -56,10 +56,17 @@ func remote(command *Command, args *Args) {
func
transformRemoteArgs
(
args
*
Args
)
{
ownerWithName
:=
args
.
LastParam
()
owner
,
name
:=
parseRepoNameOwner
(
ownerWithName
)
if
owner
==
""
{
re
:=
regexp
.
MustCompile
(
fmt
.
Sprintf
(
`^%s(/%s)?$`
,
OwnerRe
,
NameRe
))
if
!
re
.
MatchString
(
ownerWithName
)
{
return
}
owner
:=
ownerWithName
name
:=
""
if
strings
.
Contains
(
ownerWithName
,
"/"
)
{
parts
:=
strings
.
SplitN
(
ownerWithName
,
"/"
,
2
)
owner
,
name
=
parts
[
0
],
parts
[
1
]
}
localRepo
,
err
:=
github
.
LocalRepo
()
utils
.
Check
(
err
)
...
...
@@ -141,13 +148,3 @@ func parseRemotePrivateFlag(args *Args) bool {
return
false
}
func
parseRepoNameOwner
(
nameWithOwner
string
)
(
owner
,
name
string
)
{
nameWithOwnerRe
:=
fmt
.
Sprintf
(
"^(%s)(?:
\\
/(%s))?$"
,
OwnerRe
,
NameRe
)
nameWithOwnerRegexp
:=
regexp
.
MustCompile
(
nameWithOwnerRe
)
if
nameWithOwnerRegexp
.
MatchString
(
nameWithOwner
)
{
result
:=
nameWithOwnerRegexp
.
FindStringSubmatch
(
nameWithOwner
)
owner
,
name
=
result
[
1
],
result
[
2
]
}
return
}
commands/remote_test.go
浏览文件 @
dadc26d2
...
...
@@ -10,16 +10,6 @@ import (
"github.com/github/hub/github"
)
func
TestParseRepoNameOwner
(
t
*
testing
.
T
)
{
owner
,
repo
:=
parseRepoNameOwner
(
"jingweno"
)
assert
.
Equal
(
t
,
"jingweno"
,
owner
)
assert
.
Equal
(
t
,
""
,
repo
)
owner
,
repo
=
parseRepoNameOwner
(
"jingweno/gh"
)
assert
.
Equal
(
t
,
"jingweno"
,
owner
)
assert
.
Equal
(
t
,
"gh"
,
repo
)
}
func
TestTransformRemoteArgs
(
t
*
testing
.
T
)
{
repo
:=
fixtures
.
SetupTestRepo
()
defer
repo
.
TearDown
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录