Skip to content

Commit 21a28a2

Browse files
committed
the user part can stay
1 parent 516572e commit 21a28a2

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/url"
66
"os"
77
"os/exec"
8+
"regexp"
89
"strings"
910
)
1011

@@ -65,15 +66,15 @@ func findGit(envPath string) string {
6566
return ""
6667
}
6768

69+
var sshUrl = regexp.MustCompile(`^(?P<user>.*?)@(?P<host>.*?):(?:(?P<port>.*?)/)?(?P<path>.*?/.*?)$`)
70+
6871
func Scrub(argument string) string {
6972
u, err := url.Parse(argument)
7073
if err == nil && u.Scheme != "" {
7174
u.Scheme = "https"
72-
u.User = nil
7375
return u.String()
7476
}
75-
if strings.HasPrefix(argument, "git@") && strings.Contains(argument, ":") {
76-
argument = strings.TrimPrefix(argument, "git@")
77+
if sshUrl.MatchString(argument) {
7778
return "https://" + strings.Replace(argument, ":", "/", 1)
7879
}
7980
return argument

main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ func TestScrub(t *testing.T) {
1616
},
1717
{
1818
input: "[email protected]:jakecoffman/git-https-shim",
19-
expected: "https://github.com/jakecoffman/git-https-shim",
19+
expected: "https://git@github.com/jakecoffman/git-https-shim",
2020
},
2121
{
2222
input: "ssh://[email protected]/jakecoffman/git-https-shim",
23-
expected: "https://github.com/jakecoffman/git-https-shim",
23+
expected: "https://git@github.com/jakecoffman/git-https-shim",
2424
},
2525
{
2626
input: "ssh://github.com/jakecoffman/git-https-shim",

0 commit comments

Comments
 (0)