From c042fa4d991a406551e21a086583e03d85ecd8bb Mon Sep 17 00:00:00 2001 From: sciencesakura Date: Thu, 19 Mar 2026 00:16:13 +0900 Subject: [PATCH] feat(get): add `ghq.defaultHost` config to resolve the default host. --- url.go | 7 ++++++- url_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/url.go b/url.go index 0eef388..aee9753 100644 --- a/url.go +++ b/url.go @@ -139,7 +139,12 @@ func newURL(ref string, ssh, forceMe bool) (*url.URL, error) { } } u.Scheme = "https" - u.Host = "github.com" + host, err := gitconfig.Get("ghq.defaultHost") + if (err != nil && !gitconfig.IsNotFound(err)) || host != "" { + u.Host = host + } else { + u.Host = "github.com" + } if u.Path[0] != '/' { u.Path = "/" + u.Path } diff --git a/url_test.go b/url_test.go index 22207f0..65c81a3 100644 --- a/url_test.go +++ b/url_test.go @@ -66,6 +66,15 @@ completeUser = false`)) url: "peco", expect: "https://github.com/peco/peco", 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 {