diff --git a/main.go b/main.go index 92c2220..0b5e468 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "net/url" "os" "os/exec" + "regexp" "strings" ) @@ -65,15 +66,15 @@ func findGit(envPath string) string { return "" } +var sshUrl = regexp.MustCompile(`^(?P.*?)@(?P.*?):(?:(?P.*?)/)?(?P.*?/.*?)$`) + func Scrub(argument string) string { u, err := url.Parse(argument) if err == nil && u.Scheme != "" { u.Scheme = "https" - u.User = nil return u.String() } - if strings.HasPrefix(argument, "git@") && strings.Contains(argument, ":") { - argument = strings.TrimPrefix(argument, "git@") + if sshUrl.MatchString(argument) { return "https://" + strings.Replace(argument, ":", "/", 1) } return argument diff --git a/main_test.go b/main_test.go index cf1e9eb..9a6f834 100644 --- a/main_test.go +++ b/main_test.go @@ -16,11 +16,11 @@ func TestScrub(t *testing.T) { }, { input: "git@github.com:jakecoffman/git-https-shim", - expected: "https://github.com/jakecoffman/git-https-shim", + expected: "https://git@github.com/jakecoffman/git-https-shim", }, { input: "ssh://git@github.com/jakecoffman/git-https-shim", - expected: "https://github.com/jakecoffman/git-https-shim", + expected: "https://git@github.com/jakecoffman/git-https-shim", }, { input: "ssh://github.com/jakecoffman/git-https-shim",