Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
c60599b4
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,发现更多精彩内容 >>
提交
c60599b4
编写于
6月 30, 2013
作者:
J
Jingwen Owen Ou
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'remote_fix'
上级
cc4c4ed0
92b3a4e0
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
69 addition
and
13 deletion
+69
-13
commands/checkout.go
commands/checkout.go
+2
-2
commands/commands.go
commands/commands.go
+6
-0
commands/pull_request.go
commands/pull_request.go
+4
-1
commands/remote.go
commands/remote.go
+29
-6
commands/remote_test.go
commands/remote_test.go
+22
-0
gh.bash_completion.sh
gh.bash_completion.sh
+2
-1
gh.zsh_completion
gh.zsh_completion
+2
-1
github/github.go
github/github.go
+2
-2
未找到文件。
commands/checkout.go
浏览文件 @
c60599b4
...
...
@@ -17,8 +17,8 @@ var cmdCheckout = &Command{
/**
$ gh checkout https://github.com/jingweno/gh/pull/73
#
> git remote add -f -t feature git://github:com/foo/gh.git
#
> git checkout --track -B foo-feature foo/feature
> git remote add -f -t feature git://github:com/foo/gh.git
> git checkout --track -B foo-feature foo/feature
$ gh checkout https://github.com/jingweno/gh/pull/73 custom-branch-name
**/
...
...
commands/commands.go
浏览文件 @
c60599b4
...
...
@@ -8,6 +8,12 @@ import (
"strings"
)
var
(
NameRe
=
"[
\\
w.][
\\
w.-]*"
OwnerRe
=
"[a-zA-Z0-9][a-zA-Z0-9-]*"
NameWithOwnerRe
=
fmt
.
Sprintf
(
"/^(?:%s|%s
\\
/%s)$"
,
NameRe
,
OwnerRe
,
NameRe
)
)
type
Command
struct
{
Run
func
(
cmd
*
Command
,
args
*
Args
)
Flag
flag
.
FlagSet
...
...
commands/pull_request.go
浏览文件 @
c60599b4
...
...
@@ -66,6 +66,9 @@ func pullRequest(cmd *Command, args *Args) {
title
,
body
,
err
=
readTitleAndBody
(
messageFile
)
utils
.
Check
(
err
)
err
=
os
.
Remove
(
messageFile
)
utils
.
Check
(
err
)
}
if
title
==
""
&&
flagPullRequestIssue
==
""
{
...
...
commands/remote.go
浏览文件 @
c60599b4
package
commands
import
(
"fmt"
"github.com/jingweno/gh/github"
"regexp"
)
var
cmdRemote
=
&
Command
{
...
...
@@ -11,7 +13,7 @@ var cmdRemote = &Command{
Short
:
"View and manage a set of remote repositories"
,
}
/*
*
/*
$ gh remote add jingweno
> git remote add jingweno git://github.com/jingweno/THIS_REPO.git
...
...
@@ -19,9 +21,8 @@ var cmdRemote = &Command{
> git remote add jingweno git@github.com:jingweno/THIS_REPO.git
$ gh remote add origin
> git remote add origin
git://github.com/YOUR_LOGIN/THIS_REPO.git
**/
> git remote add origin git://github.com/YOUR_LOGIN/THIS_REPO.git
*/
func
remote
(
command
*
Command
,
args
*
Args
)
{
if
args
.
Size
()
>=
2
&&
(
args
.
First
()
==
"add"
||
args
.
First
()
==
"set-url"
)
{
transformRemoteArgs
(
args
)
...
...
@@ -29,15 +30,37 @@ func remote(command *Command, args *Args) {
}
func
transformRemoteArgs
(
args
*
Args
)
{
ownerWithName
:=
args
.
Last
()
owner
,
repo
,
match
:=
parseRepoNameOwner
(
ownerWithName
)
if
!
match
{
return
}
isPriavte
:=
parseRemotePrivateFlag
(
args
)
owner
:=
args
.
Last
()
gh
:=
github
.
New
()
url
:=
gh
.
ExpandRemoteUrl
(
owner
,
isPriavte
)
url
:=
gh
.
ExpandRemoteUrl
(
owner
,
repo
,
isPriavte
)
args
.
Append
(
url
)
}
func
parseRepoNameOwner
(
nameWithOwner
string
)
(
string
,
string
,
bool
)
{
ownerRe
:=
fmt
.
Sprintf
(
"^(%s)$"
,
OwnerRe
)
ownerRegexp
:=
regexp
.
MustCompile
(
ownerRe
)
if
ownerRegexp
.
MatchString
(
nameWithOwner
)
{
return
ownerRegexp
.
FindStringSubmatch
(
nameWithOwner
)[
1
],
""
,
true
}
nameWithOwnerRe
:=
fmt
.
Sprintf
(
"^(%s)
\\
/(%s)$"
,
OwnerRe
,
NameRe
)
nameWithOwnerRegexp
:=
regexp
.
MustCompile
(
nameWithOwnerRe
)
if
nameWithOwnerRegexp
.
MatchString
(
nameWithOwner
)
{
match
:=
nameWithOwnerRegexp
.
FindStringSubmatch
(
nameWithOwner
)
return
match
[
1
],
match
[
2
],
true
}
return
""
,
""
,
false
}
func
parseRemotePrivateFlag
(
args
*
Args
)
bool
{
if
i
:=
args
.
IndexOf
(
"-p"
);
i
!=
-
1
{
args
.
Remove
(
i
)
...
...
commands/remote_test.go
浏览文件 @
c60599b4
...
...
@@ -5,6 +5,20 @@ import (
"testing"
)
func
TestParseRepoNameOwner
(
t
*
testing
.
T
)
{
owner
,
repo
,
match
:=
parseRepoNameOwner
(
"jingweno"
)
assert
.
T
(
t
,
match
)
assert
.
Equal
(
t
,
"jingweno"
,
owner
)
assert
.
Equal
(
t
,
""
,
repo
)
owner
,
repo
,
match
=
parseRepoNameOwner
(
"jingweno/gh"
)
assert
.
T
(
t
,
match
)
assert
.
Equal
(
t
,
"jingweno"
,
owner
)
assert
.
Equal
(
t
,
"gh"
,
repo
)
}
func
TestTransformRemoteArgs
(
t
*
testing
.
T
)
{
args
:=
NewArgs
([]
string
{
"add"
,
"jingweno"
})
transformRemoteArgs
(
args
)
...
...
@@ -21,4 +35,12 @@ func TestTransformRemoteArgs(t *testing.T) {
assert
.
Equal
(
t
,
"add"
,
args
.
First
())
assert
.
Equal
(
t
,
"jingweno"
,
args
.
Get
(
1
))
assert
.
Equal
(
t
,
"git@github.com:jingweno/gh.git"
,
args
.
Get
(
2
))
args
=
NewArgs
([]
string
{
"add"
,
"jingweno"
,
"git@github.com:jingweno/gh.git"
})
transformRemoteArgs
(
args
)
assert
.
Equal
(
t
,
3
,
args
.
Size
())
assert
.
Equal
(
t
,
"add"
,
args
.
First
())
assert
.
Equal
(
t
,
"jingweno"
,
args
.
Get
(
1
))
assert
.
Equal
(
t
,
"git@github.com:jingweno/gh.git"
,
args
.
Get
(
2
))
}
gh.bash_completion.sh
浏览文件 @
c60599b4
...
...
@@ -11,8 +11,9 @@ if declare -F _git > /dev/null; then
__git_list_all_commands
()
{
cat
<<-
EOF
alias
p
r
p
ull-request
fork
ci-status
create
browse
compare
...
...
gh.zsh_completion
浏览文件 @
c60599b4
...
...
@@ -11,8 +11,9 @@ fi
if
declare
-f
_git_commands
>
/dev/null
;
then
_hub_commands
=(
'alias:show shell instructions for wrapping git'
'p
r
:open a pull request on GitHub'
'p
ull-request
:open a pull request on GitHub'
'fork:fork origin repo on GitHub'
'ci-status:show CI status of a commit'
'create:create new repo on GitHub for the current project'
'browse:browse the project on GitHub'
'compare:open GitHub compare view'
...
...
github/github.go
浏览文件 @
c60599b4
...
...
@@ -83,7 +83,7 @@ func (gh *GitHub) ForkRepository(name, owner string, noRemote bool) (newRemote s
return
}
func
(
gh
*
GitHub
)
ExpandRemoteUrl
(
owner
string
,
isSSH
bool
)
(
url
string
)
{
func
(
gh
*
GitHub
)
ExpandRemoteUrl
(
owner
,
name
string
,
isSSH
bool
)
(
url
string
)
{
project
:=
gh
.
Project
if
owner
==
"origin"
{
config
:=
gh
.
config
...
...
@@ -92,7 +92,7 @@ func (gh *GitHub) ExpandRemoteUrl(owner string, isSSH bool) (url string) {
project
.
Owner
=
owner
}
return
project
.
GitURL
(
""
,
owner
,
isSSH
)
return
project
.
GitURL
(
name
,
owner
,
isSSH
)
}
func
(
gh
*
GitHub
)
repo
()
octokat
.
Repo
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录