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

Merge branch 'master' of https://github.com/github/hub

......@@ -119,9 +119,24 @@ 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)
newArgs = append(newArgs, newBranchName)
args.Before("git", "fetch", baseRemote.Name, refSpec)
ref := fmt.Sprintf("refs/pull/%s/head", id)
args.Before("git", "fetch", baseRemote.Name, fmt.Sprintf("%s:%s", ref, newBranchName))
remote := baseRemote.Name
mergeRef := ref
if pullRequest.MaintainerCanModify && pullRequest.Head.Repo != nil {
project, err := github.NewProjectFromRepo(pullRequest.Head.Repo)
if err != nil {
return err
}
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)
}
replaceCheckoutParam(args, checkoutURL, newArgs...)
return nil
......
......@@ -25,12 +25,13 @@ Feature: hub checkout <PULLREQ-URL>
:html_url => 'https://github.com/mojombo/jekyll',
:owner => { :login => "mojombo" },
}
}
}, :maintainer_can_modify => false
}
"""
When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
Then "git fetch origin refs/pull/77/head:mislav-fixes" should be run
And "git checkout -f mislav-fixes -q" should be run
And "mislav-fixes" should merge "refs/pull/77/head" from remote "origin"
Scenario: No matching remotes for pull request base
Given the GitHub API server:
......@@ -68,12 +69,13 @@ Feature: hub checkout <PULLREQ-URL>
:html_url => 'https://github.com/mojombo/jekyll',
:owner => { :login => "mojombo" },
}
}
}, :maintainer_can_modify => false
}
"""
When I run `hub checkout https://github.com/mojombo/jekyll/pull/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"
Scenario: Same-repo
Given the GitHub API server:
......@@ -140,6 +142,7 @@ 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
And "pr-77" should merge "refs/pull/77/head" from remote "origin"
Scenario: Reuse existing remote for head branch
Given the GitHub API server:
......@@ -192,3 +195,58 @@ Feature: hub checkout <PULLREQ-URL>
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
Scenario: Modifiable fork
Given the GitHub API server:
"""
get('/repos/mojombo/jekyll/pulls/77') {
halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
json :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
}
"""
When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
Then "git fetch origin refs/pull/77/head:mislav-fixes" should be run
And "git checkout -f mislav-fixes -q" should be run
And "mislav-fixes" should merge "refs/heads/fixes" from remote "git@github.com:mislav/jekyll.git"
Scenario: Modifiable fork with HTTPS
Given the GitHub API server:
"""
get('/repos/mojombo/jekyll/pulls/77') {
halt 406 unless request.env['HTTP_ACCEPT'] == 'application/vnd.github.v3+json;charset=utf-8'
json :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 HTTPS is preferred
When I run `hub checkout -f https://github.com/mojombo/jekyll/pull/77 -q`
Then "git fetch origin refs/pull/77/head:mislav-fixes" should be run
And "git checkout -f mislav-fixes -q" should be run
And "mislav-fixes" should merge "refs/heads/fixes" from remote "https://github.com/mislav/jekyll.git"
......@@ -208,6 +208,14 @@ Then(/^the "([^"]*)" submodule url should be "([^"]*)"$/) do |name, url|
expect(found).to eql(url)
end
Then(/^"([^"]*)" should merge "([^"]*)" from remote "([^"]*)"$/) do |name, merge, remote|
actual_remote = run_silent %(git config --get-all branch.#{name}.remote)
expect(remote).to eql(actual_remote)
actual_merge = run_silent %(git config --get-all branch.#{name}.merge)
expect(merge).to eql(actual_merge)
end
Then(/^there should be no "([^"]*)" remote$/) do |remote_name|
remotes = run_silent('git remote').split("\n")
expect(remotes).to_not include(remote_name)
......
......@@ -91,12 +91,13 @@ func (client *Client) PullRequestPatch(project *Project, id string) (patch io.Re
}
type PullRequest struct {
ApiUrl string `json:"url"`
Number int `json:"number"`
HtmlUrl string `json:"html_url"`
Title string `json:"title"`
Head *PullRequestSpec `json:"head"`
Base *PullRequestSpec `json:"base"`
ApiUrl string `json:"url"`
Number int `json:"number"`
HtmlUrl string `json:"html_url"`
Title string `json:"title"`
MaintainerCanModify bool `json:"maintainer_can_modify"`
Head *PullRequestSpec `json:"head"`
Base *PullRequestSpec `json:"base"`
}
type PullRequestSpec struct {
......
......@@ -103,6 +103,16 @@ func preferredProtocol() string {
return userProtocol
}
func NewProjectFromRepo(repo *Repository) (p *Project, err error) {
url, err := url.Parse(repo.HtmlUrl)
if err != nil {
return
}
p, err = NewProjectFromURL(url)
return
}
func NewProjectFromURL(url *url.URL) (p *Project, err error) {
if !knownGitHubHostsInclude(url.Host) {
err = &GithubHostError{url}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册