feat(get): add ghq.defaultHost config to resolve the default host.

This commit is contained in:
sciencesakura 2026-03-19 00:16:13 +09:00
parent c71ae6ae4b
commit c042fa4d99
2 changed files with 15 additions and 1 deletions

5
url.go
View file

@ -139,7 +139,12 @@ func newURL(ref string, ssh, forceMe bool) (*url.URL, error) {
} }
} }
u.Scheme = "https" u.Scheme = "https"
host, err := gitconfig.Get("ghq.defaultHost")
if (err != nil && !gitconfig.IsNotFound(err)) || host != "" {
u.Host = host
} else {
u.Host = "github.com" u.Host = "github.com"
}
if u.Path[0] != '/' { if u.Path[0] != '/' {
u.Path = "/" + u.Path u.Path = "/" + u.Path
} }

View file

@ -66,6 +66,15 @@ completeUser = false`))
url: "peco", url: "peco",
expect: "https://github.com/peco/peco", expect: "https://github.com/peco/peco",
host: "github.com", host: "github.com",
}, {
name: "configured default host",
setup: func(t *testing.T) {
t.Cleanup(gitconfig.WithConfig(t, `[ghq]
defaultHost = gitlab.com`))
},
url: "gnuwget/wget2",
expect: "https://gitlab.com/gnuwget/wget2",
host: "gitlab.com",
}} }}
for _, tc := range testCases { for _, tc := range testCases {