Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
github
hub
提交
678eff36
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 搜索 >>
未验证
提交
678eff36
编写于
2月 24, 2019
作者:
M
Mislav Marohnić
提交者:
GitHub
2月 24, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2057 from github/checkout-track-fix
Make `checkout` work independently of remote refspec
上级
cbbb778f
7a4c893a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
48 addition
and
22 deletion
+48
-22
commands/checkout.go
commands/checkout.go
+5
-3
features/checkout.feature
features/checkout.feature
+16
-13
features/pr-checkout.feature
features/pr-checkout.feature
+5
-4
features/support/fakebin/git
features/support/fakebin/git
+22
-2
未找到文件。
commands/checkout.go
浏览文件 @
678eff36
...
...
@@ -101,7 +101,9 @@ func transformCheckoutArgs(args *Args, pullRequest *github.PullRequest, newBranc
newArgs
=
append
(
newArgs
,
newBranchName
)
args
.
After
(
"git"
,
"merge"
,
"--ff-only"
,
fmt
.
Sprintf
(
"refs/remotes/%s"
,
remoteBranch
))
}
else
{
newArgs
=
append
(
newArgs
,
"-b"
,
newBranchName
,
"--track"
,
remoteBranch
)
newArgs
=
append
(
newArgs
,
"-b"
,
newBranchName
,
"--no-track"
,
remoteBranch
)
args
.
After
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.remote"
,
newBranchName
),
headRemote
.
Name
)
args
.
After
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.merge"
,
newBranchName
),
"refs/heads/"
+
pullRequest
.
Head
.
Ref
)
}
args
.
Before
(
"git"
,
"fetch"
,
headRemote
.
Name
,
refSpec
)
}
else
{
...
...
@@ -128,8 +130,8 @@ func transformCheckoutArgs(args *Args, pullRequest *github.PullRequest, newBranc
remote
=
project
.
GitURL
(
""
,
""
,
true
)
mergeRef
=
fmt
.
Sprintf
(
"refs/heads/%s"
,
pullRequest
.
Head
.
Ref
)
}
args
.
Before
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.remote"
,
newBranchName
),
remote
)
args
.
Before
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.merge"
,
newBranchName
),
mergeRef
)
args
.
After
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.remote"
,
newBranchName
),
remote
)
args
.
After
(
"git"
,
"config"
,
fmt
.
Sprintf
(
"branch.%s.merge"
,
newBranchName
),
mergeRef
)
}
return
}
...
...
features/checkout.feature
浏览文件 @
678eff36
...
...
@@ -28,7 +28,7 @@ Feature: hub checkout <PULLREQ-URL>
}, :maintainer_can_modify => false
}
"""
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
When I
successfully
run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch origin refs/pull/77/head
:
fixes"
should
be
run
And
"git checkout -f fixes -q"
should be run
And
"fixes"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -54,7 +54,7 @@ Feature: hub checkout <PULLREQ-URL>
}, :maintainer_can_modify => false
}
"""
When I run `hub checkout https
:
//github.com/mojombo/jekyll/pull/77`
When I
successfully
run `hub checkout https
:
//github.com/mojombo/jekyll/pull/77`
Then "git fetch origin refs/pull/77/head
:
mislav-master"
should
be
run
And
"git checkout mislav-master"
should be run
And
"mislav-master"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -98,7 +98,7 @@ Feature: hub checkout <PULLREQ-URL>
}, :maintainer_can_modify => false
}
"""
When I run `hub checkout https
:
//github.com/mojombo/jekyll/pull/7
7
fixes-from-mislav`
When I
successfully
run `hub checkout https
:
//github.com/mojombo/jekyll/pull/7
7
fixes-from-mislav`
Then "git fetch origin refs/pull/77/head
:
fixes-from-mislav"
should
be
run
And
"git checkout fixes-from-mislav"
should be run
And
"fixes-from-mislav"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -122,9 +122,10 @@ Feature: hub checkout <PULLREQ-URL>
}
}
"""
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
When I
successfully
run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch origin +refs/heads/fixes
:
refs/remotes/origin/fixes"
should
be
run
And
"git checkout -f -b fixes --track origin/fixes -q"
should be run
And
"git checkout -f -b fixes --no-track origin/fixes -q"
should be run
And
"fixes"
should merge
"refs/heads/fixes"
from remote
"origin"
Scenario
:
Same-repo with custom branch name
Given the GitHub API server
:
...
...
@@ -145,9 +146,10 @@ Feature: hub checkout <PULLREQ-URL>
}
}
"""
When I run `hub checkout https
:
//github.com/mojombo/jekyll/pull/7
7
mycustombranch`
When I
successfully
run `hub checkout https
:
//github.com/mojombo/jekyll/pull/7
7
mycustombranch`
Then "git fetch origin +refs/heads/fixes
:
refs/remotes/origin/fixes"
should
be
run
And
"git checkout -b mycustombranch --track origin/fixes"
should be run
And
"git checkout -b mycustombranch --no-track origin/fixes"
should be run
And
"mycustombranch"
should merge
"refs/heads/fixes"
from remote
"origin"
Scenario
:
Unavailable fork
Given the GitHub API server
:
...
...
@@ -165,7 +167,7 @@ Feature: hub checkout <PULLREQ-URL>
}
}
"""
When I run `hub checkout https
:
//github.com/mojombo/jekyll/pull/77`
When I
successfully
run `hub checkout https
:
//github.com/mojombo/jekyll/pull/77`
Then "git fetch origin refs/pull/77/head
:
fixes"
should
be
run
And
"git checkout fixes"
should be run
And
"fixes"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -191,9 +193,10 @@ Feature: hub checkout <PULLREQ-URL>
}
"""
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`
When I
successfully
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
And
"git checkout -f -b fixes --no-track mislav/fixes -q"
should be run
And
"fixes"
should merge
"refs/heads/fixes"
from remote
"mislav"
Scenario
:
Reuse existing remote and branch
Given the GitHub API server
:
...
...
@@ -217,7 +220,7 @@ Feature: hub checkout <PULLREQ-URL>
"""
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`
When I
successfully
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
...
...
@@ -243,7 +246,7 @@ Feature: hub checkout <PULLREQ-URL>
}, :maintainer_can_modify => true
}
"""
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
When I
successfully
run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch origin refs/pull/77/head
:
fixes"
should
be
run
And
"git checkout -f fixes -q"
should be run
And "fixes" should merge "refs/heads/fixes" from remote "git@github.com
:
mislav/jekyll.git"
...
...
@@ -270,7 +273,7 @@ Feature: hub checkout <PULLREQ-URL>
}
"""
And
HTTPS is preferred
When I run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
When I
successfully
run `hub checkout -f https
:
//github.com/mojombo/jekyll/pull/7
7
-q`
Then "git fetch origin refs/pull/77/head
:
fixes"
should
be
run
And
"git checkout -f fixes -q"
should be run
And "fixes" should merge "refs/heads/fixes" from remote "https
:
//github.com/mislav/jekyll.git"
features/pr-checkout.feature
浏览文件 @
678eff36
...
...
@@ -25,7 +25,7 @@ Feature: hub pr checkout <PULLREQ-NUMBER>
:html_url => 'https://github.com/mojombo/jekyll/pull/77'
}
"""
When
I run `hub pr checkout 77`
When
I
successfully
run `hub pr checkout 77`
Then "git fetch origin refs/pull/77/head
:
fixes"
should
be
run
And
"git checkout fixes"
should be run
And
"fixes"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -51,7 +51,7 @@ Feature: hub pr checkout <PULLREQ-NUMBER>
:html_url => 'https://github.com/mojombo/jekyll/pull/77'
}
"""
When
I run `hub pr checkout 77 fixes-from-mislav`
When
I
successfully
run `hub pr checkout 77 fixes-from-mislav`
Then "git fetch origin refs/pull/77/head
:
fixes-from-mislav"
should
be
run
And
"git checkout fixes-from-mislav"
should be run
And
"fixes-from-mislav"
should merge
"refs/pull/77/head"
from remote
"origin"
...
...
@@ -76,6 +76,7 @@ Feature: hub pr checkout <PULLREQ-NUMBER>
:html_url => 'https://github.com/mojombo/jekyll/pull/77'
}
"""
When
I run `hub pr checkout 77`
When
I
successfully
run `hub pr checkout 77`
Then "git fetch origin +refs/heads/fixes
:
refs/remotes/origin/fixes"
should
be
run
And
"git checkout -b fixes --track origin/fixes"
should be run
And
"git checkout -b fixes --no-track origin/fixes"
should be run
And
"fixes"
should merge
"refs/heads/fixes"
from remote
"origin"
features/support/fakebin/git
浏览文件 @
678eff36
...
...
@@ -2,6 +2,7 @@
# A wrapper for system git that prevents commands such as `clone` or `fetch` to be
# executed in testing. It logs commands to "~/.history" so afterwards it can be
# asserted that they ran.
set
-e
command
=
"
$1
"
[
"
$command
"
=
"config"
]
||
echo
git
"
$@
"
>>
"
$HOME
"
/.history
...
...
@@ -12,9 +13,28 @@ case "$command" in
echo
branch
echo
commit
;;
"clone"
|
"fetch"
|
"pull"
|
"push"
)
"fetch"
)
[[
$2
!=
-
*
&&
$3
==
*
:
*
&&
$3
!=
-
*
]]
||
exit
0
refspec
=
"
$3
"
dest
=
"
${
refspec
#*
:
}
"
head
=
"
$(
git rev-parse
--verify
-q
HEAD
||
true
)
"
if
[
-z
"
$head
"
]
;
then
git commit
--allow-empty
-m
"auto-commit"
head
=
"
$(
git rev-parse
--verify
-q
HEAD
)
"
fi
if
[[
$dest
==
refs/remotes/
*
]]
;
then
mkdir
-p
".git/
${
dest
%/*
}
"
cat
>
".git/
${
dest
}
"
<<<
"
$head
"
cat
>
".git/FETCH_HEAD"
<<<
"
$head
"
else
"
$HUB_SYSTEM_GIT
"
checkout
-b
"
${
dest
#refs/heads/
}
"
HEAD
cat
>
".git/FETCH_HEAD"
<<<
"
$head
"
fi
exit
0
;;
"clone"
|
"pull"
|
"push"
)
# don't actually execute these commands
exit
exit
0
;;
*
)
# note: `submodule add` also initiates a clone, but we work around it
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录