Skip to content

Commit 9345571

Browse files
authored
Merge pull request cli#266 from cli/non-github-remotes
Fix parsing non-GitHub remotes
2 parents 4c75270 + 8453bf6 commit 9345571

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

context/remote.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ func translateRemotes(gitRemotes git.RemoteSet, urlTranslate func(*url.URL) *url
8181
if r.PushURL != nil && repo == nil {
8282
repo, _ = ghrepo.FromURL(urlTranslate(r.PushURL))
8383
}
84+
if repo == nil {
85+
continue
86+
}
8487
remotes = append(remotes, &Remote{
8588
Remote: r,
8689
Owner: repo.RepoOwner(),

context/remote_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package context
22

33
import (
44
"errors"
5+
"net/url"
56
"testing"
67

78
"github.com/cli/cli/git"
@@ -25,3 +26,34 @@ func Test_Remotes_FindByName(t *testing.T) {
2526
_, err = list.FindByName("nonexist")
2627
eq(t, err, errors.New(`no GitHub remotes found`))
2728
}
29+
30+
func Test_translateRemotes(t *testing.T) {
31+
publicURL, _ := url.Parse("https://github.com/monalisa/hello")
32+
originURL, _ := url.Parse("http://example.com/repo")
33+
34+
gitRemotes := git.RemoteSet{
35+
&git.Remote{
36+
Name: "origin",
37+
FetchURL: originURL,
38+
},
39+
&git.Remote{
40+
Name: "public",
41+
FetchURL: publicURL,
42+
},
43+
}
44+
45+
identityURL := func(u *url.URL) *url.URL {
46+
return u
47+
}
48+
result := translateRemotes(gitRemotes, identityURL)
49+
50+
if len(result) != 1 {
51+
t.Errorf("got %d results", len(result))
52+
}
53+
if result[0].Name != "public" {
54+
t.Errorf("got %q", result[0].Name)
55+
}
56+
if result[0].RepoName() != "hello" {
57+
t.Errorf("got %q", result[0].RepoName())
58+
}
59+
}

0 commit comments

Comments
 (0)