Merge pull request #266 from cli/non-github-remotes
Fix parsing non-GitHub remotes
This commit is contained in:
commit
9345571ee8
2 changed files with 35 additions and 0 deletions
|
|
@ -81,6 +81,9 @@ func translateRemotes(gitRemotes git.RemoteSet, urlTranslate func(*url.URL) *url
|
|||
if r.PushURL != nil && repo == nil {
|
||||
repo, _ = ghrepo.FromURL(urlTranslate(r.PushURL))
|
||||
}
|
||||
if repo == nil {
|
||||
continue
|
||||
}
|
||||
remotes = append(remotes, &Remote{
|
||||
Remote: r,
|
||||
Owner: repo.RepoOwner(),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package context
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"github.com/cli/cli/git"
|
||||
|
|
@ -25,3 +26,34 @@ func Test_Remotes_FindByName(t *testing.T) {
|
|||
_, err = list.FindByName("nonexist")
|
||||
eq(t, err, errors.New(`no GitHub remotes found`))
|
||||
}
|
||||
|
||||
func Test_translateRemotes(t *testing.T) {
|
||||
publicURL, _ := url.Parse("https://github.com/monalisa/hello")
|
||||
originURL, _ := url.Parse("http://example.com/repo")
|
||||
|
||||
gitRemotes := git.RemoteSet{
|
||||
&git.Remote{
|
||||
Name: "origin",
|
||||
FetchURL: originURL,
|
||||
},
|
||||
&git.Remote{
|
||||
Name: "public",
|
||||
FetchURL: publicURL,
|
||||
},
|
||||
}
|
||||
|
||||
identityURL := func(u *url.URL) *url.URL {
|
||||
return u
|
||||
}
|
||||
result := translateRemotes(gitRemotes, identityURL)
|
||||
|
||||
if len(result) != 1 {
|
||||
t.Errorf("got %d results", len(result))
|
||||
}
|
||||
if result[0].Name != "public" {
|
||||
t.Errorf("got %q", result[0].Name)
|
||||
}
|
||||
if result[0].RepoName() != "hello" {
|
||||
t.Errorf("got %q", result[0].RepoName())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue