Skip to content

Commit

Permalink
the user part can stay
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecoffman committed Jun 26, 2022
1 parent 516572e commit 21a28a2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/url"
"os"
"os/exec"
"regexp"
"strings"
)

Expand Down Expand Up @@ -65,15 +66,15 @@ func findGit(envPath string) string {
return ""
}

var sshUrl = regexp.MustCompile(`^(?P<user>.*?)@(?P<host>.*?):(?:(?P<port>.*?)/)?(?P<path>.*?/.*?)$`)

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
Expand Down
4 changes: 2 additions & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func TestScrub(t *testing.T) {
},
{
input: "[email protected]:jakecoffman/git-https-shim",
expected: "https://github.com/jakecoffman/git-https-shim",
expected: "https://git@github.com/jakecoffman/git-https-shim",
},
{
input: "ssh://[email protected]/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",
Expand Down

0 comments on commit 21a28a2

Please sign in to comment.