From c240ab9137db008609a0c8406ce27b1ff54917df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Mon, 20 Dec 2021 16:09:46 +0100 Subject: [PATCH] Unconditionally resolve "ssh.github.com" to "github.com" Previously, only "github.com" mapped to "ssh.github.com" via ssh config was treated as "github.com". Now, any "ssh.github.com" host is treated as "github.com", even if it was initially aliased as something else in the user's ssh hostname mappings. --- git/ssh_config.go | 5 ++--- git/ssh_config_test.go | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/git/ssh_config.go b/git/ssh_config.go index a4e234a02..3c5056474 100644 --- a/git/ssh_config.go +++ b/git/ssh_config.go @@ -30,9 +30,8 @@ func (m SSHAliasMap) Translator() func(*url.URL) *url.URL { if !ok { return u } - // FIXME: cleanup domain logic - if strings.EqualFold(u.Hostname(), "github.com") && strings.EqualFold(resolvedHost, "ssh.github.com") { - return u + if strings.EqualFold(resolvedHost, "ssh.github.com") { + resolvedHost = "github.com" } newURL, _ := url.Parse(u.String()) newURL.Host = resolvedHost diff --git a/git/ssh_config_test.go b/git/ssh_config_test.go index f05ca303b..058617269 100644 --- a/git/ssh_config_test.go +++ b/git/ssh_config_test.go @@ -128,12 +128,14 @@ func Test_Translator(t *testing.T) { m := SSHAliasMap{ "gh": "github.com", "github.com": "ssh.github.com", + "my.gh.com": "ssh.github.com", } tr := m.Translator() cases := [][]string{ {"ssh://gh/o/r", "ssh://github.com/o/r"}, {"ssh://github.com/o/r", "ssh://github.com/o/r"}, + {"ssh://my.gh.com", "ssh://github.com"}, {"https://gh/o/r", "https://gh/o/r"}, } for _, c := range cases {