Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
f3d909bb
H
hub
项目概览
github
/
hub
10 个月 前同步成功
通知
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,体验更适合开发者的 AI 搜索 >>
提交
f3d909bb
编写于
10月 03, 2016
作者:
M
Mislav Marohnić
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'checkout-reuse-remote'
上级
a7eb9026
e1ef66ab
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
11 deletion
+75
-11
commands/checkout.go
commands/checkout.go
+23
-11
features/checkout.feature
features/checkout.feature
+52
-0
未找到文件。
commands/checkout.go
浏览文件 @
f3d909bb
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"regexp"
"github.com/github/hub/git"
"github.com/github/hub/github"
"github.com/github/hub/utils"
)
...
...
@@ -16,8 +17,8 @@ var cmdCheckout = &Command{
## Examples:
$ hub checkout https://github.com/jingweno/gh/pull/73
> git
remote add -f --no-tags -t feature git://github:com/jingweno/gh.git
> git checkout
--track -B jingweno-feature jingweno/
feature
> git
fetch origin pull/73/head:jingweno-feature
> git checkout
jingweno-
feature
## See also:
...
...
@@ -83,21 +84,33 @@ func transformCheckoutArgs(args *Args) error {
return
err
}
r
emote
,
err
:=
repo
.
RemoteForRepo
(
pullRequest
.
Base
.
Repo
)
baseR
emote
,
err
:=
repo
.
RemoteForRepo
(
pullRequest
.
Base
.
Repo
)
if
err
!=
nil
{
return
err
}
var
refSpec
string
var
headRemote
*
github
.
Remote
if
pullRequest
.
IsSameRepo
()
{
headRemote
=
baseRemote
}
else
{
headRemote
,
_
=
repo
.
RemoteForRepo
(
pullRequest
.
Head
.
Repo
)
}
var
newArgs
[]
string
if
pullRequest
.
IsSameRepo
()
{
if
headRemote
!=
nil
{
if
newBranchName
==
""
{
newBranchName
=
pullRequest
.
Head
.
Ref
}
remoteBranch
:=
fmt
.
Sprintf
(
"%s/%s"
,
remote
.
Name
,
pullRequest
.
Head
.
Ref
)
refSpec
=
fmt
.
Sprintf
(
"+refs/heads/%s:refs/remotes/%s"
,
pullRequest
.
Head
.
Ref
,
remoteBranch
)
newArgs
=
append
(
newArgs
,
"-b"
,
newBranchName
,
"--track"
,
remoteBranch
)
remoteBranch
:=
fmt
.
Sprintf
(
"%s/%s"
,
headRemote
.
Name
,
pullRequest
.
Head
.
Ref
)
refSpec
:=
fmt
.
Sprintf
(
"+refs/heads/%s:refs/remotes/%s"
,
pullRequest
.
Head
.
Ref
,
remoteBranch
)
if
git
.
HasFile
(
"refs"
,
"heads"
,
newBranchName
)
{
newArgs
=
append
(
newArgs
,
newBranchName
)
args
.
After
(
"git"
,
"merge"
,
"--ff-only"
,
fmt
.
Sprintf
(
"refs/remotes/%s"
,
remoteBranch
))
}
else
{
newArgs
=
append
(
newArgs
,
"-b"
,
newBranchName
,
"--track"
,
remoteBranch
)
}
args
.
Before
(
"git"
,
"fetch"
,
headRemote
.
Name
,
refSpec
)
}
else
{
if
newBranchName
==
""
{
if
pullRequest
.
Head
.
Repo
==
nil
{
...
...
@@ -106,11 +119,10 @@ func transformCheckoutArgs(args *Args) error {
newBranchName
=
fmt
.
Sprintf
(
"%s-%s"
,
pullRequest
.
Head
.
Repo
.
Owner
.
Login
,
pullRequest
.
Head
.
Ref
)
}
}
refSpec
=
fmt
.
Sprintf
(
"refs/pull/%s/head:%s"
,
id
,
newBranchName
)
refSpec
:
=
fmt
.
Sprintf
(
"refs/pull/%s/head:%s"
,
id
,
newBranchName
)
newArgs
=
append
(
newArgs
,
newBranchName
)
args
.
Before
(
"git"
,
"fetch"
,
baseRemote
.
Name
,
refSpec
)
}
args
.
Before
(
"git"
,
"fetch"
,
remote
.
Name
,
refSpec
)
replaceCheckoutParam
(
args
,
checkoutURL
,
newArgs
...
)
return
nil
}
...
...
features/checkout.feature
浏览文件 @
f3d909bb
...
...
@@ -140,3 +140,55 @@ Feature: hub checkout <PULLREQ-URL>
When I run `hub checkout https
:
//github.com/mojombo/jekyll/pull/77`
Then "git fetch origin refs/pull/77/head
:
pr-77"
should
be
run
And
"git checkout pr-77"
should be run
Scenario
:
Reuse existing remote for head branch
Given the GitHub API server
:
"""
get('/repos/mojombo/jekyll/pulls/77') {
json :head => {
:ref => "fixes",
:repo => {
:owner => { :login => "mislav" },
:name => "jekyll",
:private => false
}
}, :base => {
:repo => {
:name => 'jekyll',
:html_url => 'https://github.com/mojombo/jekyll',
:owner => { :login => "mojombo" },
}
}
}
"""
And the "mislav" remote has url "git
:
//github.com/mislav/jekyll.git"
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch mislav +refs/heads/fixes
:
refs/remotes/mislav/fixes"
should
be
run
And
"git checkout -f -b fixes --track mislav/fixes -q"
should be run
Scenario
:
Reuse existing remote and branch
Given the GitHub API server
:
"""
get('/repos/mojombo/jekyll/pulls/77') {
json :head => {
:ref => "fixes",
:repo => {
:owner => { :login => "mislav" },
:name => "jekyll",
:private => false
}
}, :base => {
:repo => {
:name => 'jekyll',
:html_url => 'https://github.com/mojombo/jekyll',
:owner => { :login => "mojombo" },
}
}
}
"""
And the "mislav" remote has url "git
:
//github.com/mislav/jekyll.git"
And
I am on the
"fixes"
branch
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch mislav +refs/heads/fixes
:
refs/remotes/mislav/fixes"
should
be
run
And
"git checkout -f fixes -q"
should be run
And
"git merge --ff-only refs/remotes/mislav/fixes"
should be run
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录