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

Change `MainProject()` logic to skip over non-GitHub remotes

When running `hub pull-request` with this git remote setup:
* origin:   `github.com/myuser/myfork`
* github:   `github.com/owner/repo`
* upstream: `example.com/other-repo`

this error would be shown:

    Aborted: the origin remote doesn't point to a GitHub repository.

The error is both unfortunate (the existence of "upstream" shouldn't
have aborted the whole operation) and misleading (it wasn't the "origin"
remote that was the problem).

This changes `MainProject()` so it skips over non-GitHub remotes until
it finds one that points to a GitHub project.
上级 fe603ad3
......@@ -85,7 +85,10 @@ Feature: hub ci-status
Scenario: Non-GitHub repo
Given the "origin" remote has url "mygh:Manganeez/repo.git"
When I run `hub ci-status`
Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
Then the stderr should contain exactly:
"""
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
And the exit status should be 1
Scenario: Enterprise CI statuses
......
......@@ -152,7 +152,7 @@ Feature: hub compare
Then the stdout should contain exactly ""
And the stderr should contain exactly:
"""
Aborted: the origin remote doesn't point to a GitHub repository.\n
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
And the exit status should be 1
......
......@@ -250,7 +250,7 @@ Feature: hub fork
Then the exit status should be 1
And the stderr should contain exactly:
"""
Aborted: the origin remote doesn't point to a GitHub repository.\n
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
And there should be no "origin" remote
......@@ -260,7 +260,7 @@ Feature: hub fork
Then the exit status should be 1
And the stderr should contain exactly:
"""
Aborted: the origin remote doesn't point to a GitHub repository.\n
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
Scenario: Enterprise fork
......
......@@ -13,7 +13,10 @@ Feature: hub pull-request
Scenario: Non-GitHub repo
Given the "origin" remote has url "mygh:Manganeez/repo.git"
When I run `hub pull-request`
Then the stderr should contain "Aborted: the origin remote doesn't point to a GitHub repository.\n"
Then the stderr should contain exactly:
"""
Aborted: could not find any git remote pointing to a GitHub repository\n
"""
And the exit status should be 1
Scenario: Create pull request respecting "insteadOf" configuration
......@@ -822,6 +825,23 @@ Feature: hub pull-request
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
Scenario: Create pull request to "github" remote when "upstream" is non-GitHub
Given I am on the "master" branch pushed to "origin/master"
And the "github" remote has url "git://github.com/github/coral.git"
And the "upstream" remote has url "git://example.com/coral.git"
Given the GitHub API server:
"""
post('/repos/github/coral/pulls') {
assert :base => 'master',
:head => 'mislav:master',
:title => 'hereyougo'
status 201
json :html_url => "the://url"
}
"""
When I successfully run `hub pull-request -m hereyougo`
Then the output should contain exactly "the://url\n"
Scenario: Open pull request in web browser
Given the GitHub API server:
"""
......
......@@ -192,34 +192,25 @@ func (r *GitHubRepo) RemoteForProject(project *Project) (*Remote, error) {
return nil, fmt.Errorf("could not find a git remote for '%s'", project)
}
func (r *GitHubRepo) MainRemote() (remote *Remote, err error) {
func (r *GitHubRepo) MainRemote() (*Remote, error) {
r.loadRemotes()
if len(r.remotes) > 0 {
remote = &r.remotes[0]
}
if remote == nil {
err = fmt.Errorf("Can't find git remote origin")
return &r.remotes[0], nil
} else {
return nil, fmt.Errorf("no git remotes found")
}
return
}
func (r *GitHubRepo) MainProject() (project *Project, err error) {
origin, err := r.MainRemote()
if err != nil {
err = fmt.Errorf("Aborted: the origin remote doesn't point to a GitHub repository.")
return
}
func (r *GitHubRepo) MainProject() (*Project, error) {
r.loadRemotes()
project, err = origin.Project()
if err != nil {
err = fmt.Errorf("Aborted: the origin remote doesn't point to a GitHub repository.")
for _, remote := range r.remotes {
if project, err := remote.Project(); err == nil {
return project, nil
}
}
return
return nil, fmt.Errorf("Aborted: could not find any git remote pointing to a GitHub repository")
}
func (r *GitHubRepo) CurrentProject() (project *Project, err error) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册