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

[checkout] Handle case when PR matches the current branch

上级 cd81a7ba
......@@ -115,8 +115,16 @@ func transformCheckoutArgs(args *Args, pullRequest *github.PullRequest, newBranc
}
newArgs = append(newArgs, newBranchName)
b, errB := repo.CurrentBranch()
isCurrentBranch := errB == nil && b.ShortName() == newBranchName
ref := fmt.Sprintf("refs/pull/%d/head", pullRequest.Number)
args.Before("git", "fetch", baseRemote.Name, fmt.Sprintf("%s:%s", ref, newBranchName))
if isCurrentBranch {
args.Before("git", "fetch", baseRemote.Name, ref)
args.After("git", "merge", "--ff-only", "FETCH_HEAD")
} else {
args.Before("git", "fetch", baseRemote.Name, fmt.Sprintf("%s:%s", ref, newBranchName))
}
remote := baseRemote.Name
mergeRef := ref
......
......@@ -251,6 +251,35 @@ Feature: hub checkout <PULLREQ-URL>
And "git checkout -f fixes -q" should be run
And "fixes" should merge "refs/heads/fixes" from remote "git@github.com:mislav/jekyll.git"
Scenario: Modifiable fork into current branch
Given the GitHub API server:
"""
get('/repos/mojombo/jekyll/pulls/77') {
json :number => 77, :head => {
:ref => "fixes",
:repo => {
:owner => { :login => "mislav" },
:name => "jekyll",
:html_url => "https://github.com/mislav/jekyll.git",
:private => false
},
}, :base => {
:repo => {
:name => 'jekyll',
:html_url => 'https://github.com/mojombo/jekyll',
:owner => { :login => "mojombo" },
}
}, :maintainer_can_modify => true
}
"""
And I am on the "fixes" branch
And there is a git FETCH_HEAD
When I successfully run `hub checkout https://github.com/mojombo/jekyll/pull/77`
Then "git fetch origin refs/pull/77/head" should be run
And "git checkout fixes" should be run
And "git merge --ff-only FETCH_HEAD" should be run
And "fixes" should merge "refs/heads/fixes" from remote "git@github.com:mislav/jekyll.git"
Scenario: Modifiable fork with HTTPS
Given the GitHub API server:
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册