提交 671759b2 编写于 作者: M Mislav Marohnić

Fix the case of unavailable fork in `checkout`

Fixes #1293
上级 4777bd36
......@@ -100,7 +100,11 @@ func transformCheckoutArgs(args *Args) error {
newArgs = append(newArgs, "-b", newBranchName, "--track", remoteBranch)
} else {
if newBranchName == "" {
newBranchName = fmt.Sprintf("%s-%s", pullRequest.Head.Repo.Owner.Login, pullRequest.Head.Ref)
if pullRequest.Head.Repo == nil {
newBranchName = fmt.Sprintf("pr-%s", id)
} else {
newBranchName = fmt.Sprintf("%s-%s", pullRequest.Head.Repo.Owner.Login, pullRequest.Head.Ref)
}
}
refSpec = fmt.Sprintf("pull/%s/head:%s", id, newBranchName)
newArgs = append(newArgs, newBranchName)
......
......@@ -120,3 +120,23 @@ Feature: hub checkout <PULLREQ-URL>
When I run `hub checkout https://github.com/mojombo/jekyll/pull/77 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
Scenario: Unavailable fork
Given the GitHub API server:
"""
get('/repos/mojombo/jekyll/pulls/77') {
json :head => {
:ref => "fixes",
:repo => nil
}, :base => {
:repo => {
:name => "jekyll",
:html_url => "https://github.com/mojombo/jekyll",
:owner => { :login => "mojombo" },
}
}
}
"""
When I run `hub checkout https://github.com/mojombo/jekyll/pull/77`
Then "git fetch origin pull/77/head:pr-77" should be run
And "git checkout pr-77" should be run
......@@ -107,7 +107,8 @@ type PullRequestSpec struct {
}
func (pr *PullRequest) IsSameRepo() bool {
return pr.Head.Repo.Name == pr.Base.Repo.Name &&
return pr.Head.Repo != nil &&
pr.Head.Repo.Name == pr.Base.Repo.Name &&
pr.Head.Repo.Owner.Login == pr.Base.Repo.Owner.Login
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册