6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 20:19:42 +00:00
Files
git-get/pkg/url.go
2020-05-21 22:48:28 +02:00

29 lines
589 B
Go

package pkg
import (
"net/url"
"path"
"strings"
"github.com/pkg/errors"
)
// TODO: maybe use https://github.com/whilp/git-urls?
func URLToPath(rawurl string) (string, error) {
parsed, err := url.Parse(rawurl)
if err != nil {
return "", errors.Wrap(err, "Failed parsing URL")
}
repoHost := strings.Split(parsed.Host, ":")[0]
repoPath := parsed.Path
//repoPath = strings.TrimSuffix(repoPath, ".git/")
//repoPath = strings.TrimSuffix(repoPath, ".git")
localPath := path.Join(repoHost, repoPath)
localPath = strings.TrimSuffix(localPath, ".git")
return localPath, nil
}