6
0
mirror of https://github.com/grdl/git-get.git synced 2026-02-04 17:24:49 +00:00

Parse URL and create a repo dir inside CloneRepo function

This commit is contained in:
Grzegorz Dlugoszewski
2020-05-22 12:19:32 +02:00
parent 2bb6f06962
commit 2b622b99fe
4 changed files with 28 additions and 18 deletions

View File

@@ -13,7 +13,7 @@ import (
// See: https://golang.org/src/cmd/go/internal/get/vcs.go
var scpSyntax = regexp.MustCompile(`^([a-zA-Z0-9_]+)@([a-zA-Z0-9._-]+):(.*)$`)
func URLToPath(rawurl string) (string, error) {
func URLToPath(rawurl string) (repoPath string, err error) {
url, err := parseURL(rawurl)
if err != nil {
return "", err
@@ -23,13 +23,13 @@ func URLToPath(rawurl string) (string, error) {
repoHost := strings.Split(url.Host, ":")[0]
// remove trailing ".git" from repo name
localPath := path.Join(repoHost, url.Path)
localPath = strings.TrimSuffix(localPath, ".git")
repoPath = path.Join(repoHost, url.Path)
repoPath = strings.TrimSuffix(repoPath, ".git")
// remove tilde (~) char from username
localPath = strings.ReplaceAll(localPath, "~", "")
repoPath = strings.ReplaceAll(repoPath, "~", "")
return localPath, nil
return repoPath, nil
}
func parseURL(rawurl string) (url *urlpkg.URL, err error) {