diff --git a/clone.go b/clone.go index 5d80002..6c0fecc 100644 --- a/clone.go +++ b/clone.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" @@ -42,6 +43,21 @@ git bug user */ +// CleanRepoURL removes http://, https://, and .git suffix from the given URL if present. +func CleanRepoURL(url string) string { + // Trim protocol prefix + if strings.HasPrefix(url, "http://") { + url = strings.TrimPrefix(url, "http://") + } else if strings.HasPrefix(url, "https://") { + url = strings.TrimPrefix(url, "https://") + } + + // Trim trailing .git + url = strings.TrimSuffix(url, ".git") + + return url +} + func clone(gopath string) (*gitpb.Repo, error) { // if the user defined a repo, attempt to download it now if gopath == "" { @@ -49,6 +65,7 @@ func clone(gopath string) (*gitpb.Repo, error) { // user probably wants to --recursive on current working dir return nil, errors.New("gopath was blank") } + gopath = CleanRepoURL(gopath) os.Setenv("REPO_AUTO_CLONE", "true") // pb, _ := forge.NewGoPath(gopath) check := forge.FindAnyPath(filepath.Join(forge.GetGoSrc(), gopath))