summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--currentVersions.go5
-rw-r--r--parseURL.go79
-rw-r--r--reloadParseGitConfig.go3
-rw-r--r--reloadTags.go3
-rw-r--r--repo.new.go6
5 files changed, 88 insertions, 8 deletions
diff --git a/currentVersions.go b/currentVersions.go
index 48563f9..1360c3c 100644
--- a/currentVersions.go
+++ b/currentVersions.go
@@ -37,7 +37,8 @@ func (repo *Repo) setMasterVersion() {
if err == nil {
repo.MasterVersion = v
} else {
- log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
+ // this is dumb
+ // log.Log(WARN, "gitpb.GitMasterVersion() error:", err)
}
}
@@ -137,7 +138,7 @@ func (repo *Repo) gitVersionByName(name string) (string, error) {
r, err := repo.RunQuiet(cmd)
output := strings.Join(r.Stdout, "\n")
if err != nil {
- log.Log(WARN, repo.FullPath, "gitDescribeByName() ", output, err, cmd)
+ // log.Log(WARN, repo.FullPath, "gitDescribeByName() ", output, err, cmd)
return "", err
}
return strings.TrimSpace(output), nil
diff --git a/parseURL.go b/parseURL.go
new file mode 100644
index 0000000..e8b133b
--- /dev/null
+++ b/parseURL.go
@@ -0,0 +1,79 @@
+package gitpb
+
+import (
+ "fmt"
+ "net/url"
+ "regexp"
+ "strings"
+)
+
+// scpLikeURLRegex is a regex to parse scp-like URLs, e.g., "[email protected]:user/repo.git".
+// It captures the user, host, and path.
+var scpLikeURLRegex = regexp.MustCompile(`^([^@]+)@([^:]+):(.+)$`)
+
+// ParseGitURL parses a Git URL, handling both standard schemes (http, https, ssh)
+// and the scp-like syntax (e.g., [email protected]:user/repo.git).
+func ParseGitURL(rawURL string) (*url.URL, error) {
+ // First, try to parse it as a standard URL.
+ // This will handle http://, https://, ssh://, git://, etc.
+ parsedURL, err := url.Parse(rawURL)
+ if err == nil && parsedURL.Scheme != "" {
+ return parsedURL, nil
+ }
+
+ // If parsing failed or the scheme is missing, it might be an scp-like URL.
+ // Try to match it against our regex.
+ matches := scpLikeURLRegex.FindStringSubmatch(rawURL)
+
+ if len(matches) != 4 {
+ // If it doesn't match, we return the original parsing error or a new one.
+ if err != nil {
+ return nil, err
+ }
+ return nil, fmt.Errorf("invalid or unsupported URL format: %s", rawURL)
+ }
+
+ // If it matches, we manually construct a url.URL struct.
+ // We'll use the "ssh" scheme to represent this connection type.
+ user := matches[1]
+ host := matches[2]
+ path := matches[3]
+
+ // The path might have a ".git" suffix, which we can optionally remove.
+ path = strings.TrimSuffix(path, ".git")
+
+ return &url.URL{
+ Scheme: "ssh",
+ User: url.User(user),
+ Host: host,
+ Path: "/" + path, // Standard URL paths start with a slash.
+ }, nil
+}
+
+/*
+func parsemain() {
+ urlsToTest := []string{
+ // The problematic scp-like syntax
+ "[email protected]:jcarr/jcarr.git",
+ // A standard HTTPS URL
+ "https://gitea.wit.com/wit/bash.git",
+ // A standard SSH URL
+ "ssh://[email protected]/golang/go.git",
+ // An invalid URL
+ "this is not a url",
+ }
+
+ for _, u := range urlsToTest {
+ fmt.Printf("Parsing URL: %s\n", u)
+ parsed, err := ParseGitURL(u)
+ if err != nil {
+ fmt.Printf(" Error: %v\n\n", err)
+ continue
+ }
+ fmt.Printf(" Scheme: %s\n", parsed.Scheme)
+ fmt.Printf(" User: %s\n", parsed.User.Username())
+ fmt.Printf(" Host: %s\n", parsed.Host)
+ fmt.Printf(" Path: %s\n\n", parsed.Path)
+ }
+}
+*/
diff --git a/reloadParseGitConfig.go b/reloadParseGitConfig.go
index c6d01e6..7d63020 100644
--- a/reloadParseGitConfig.go
+++ b/reloadParseGitConfig.go
@@ -197,7 +197,8 @@ func (repo *Repo) processBranch(branch string) {
data, err := ioutil.ReadFile(filename)
if err != nil {
- log.Log(WARN, "hash: read failed", filename)
+ // need to get the hash some other way.
+ // log.Log(WARN, "hash: read failed", filename)
return
}
newhash := strings.TrimSpace(string(data))
diff --git a/reloadTags.go b/reloadTags.go
index 810d616..ce0ca84 100644
--- a/reloadTags.go
+++ b/reloadTags.go
@@ -123,7 +123,8 @@ func (repo *Repo) reloadGitTags() error {
if repo.GetMasterBranchName() == "" {
if err := repo.findHEAD(); err != nil {
- log.Info(repo.FullPath, "master branch blank", err)
+ // todo: redo all this shitty code
+ // log.Info(repo.FullPath, "master branch blank", err)
}
}
return nil
diff --git a/repo.new.go b/repo.new.go
index cb79bf2..48c588b 100644
--- a/repo.new.go
+++ b/repo.new.go
@@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"fmt"
- "net/url"
"os/exec"
"path/filepath"
"strings"
@@ -124,14 +123,13 @@ func NewRepo(fullpath string) (*Repo, error) {
return &repo, nil
}
// log.Info("GET Namespace from URL", giturl)
- tmpURL, err := url.Parse(giturl)
+ tmpURL, err := ParseGitURL(giturl)
if err != nil {
- log.Info(repo.FullPath, "URL parse failed", giturl, err)
+ log.Info(repo.FullPath, "URL can not be parsed for namespace")
return &repo, nil
}
// log.Info(repo.FullPath, "namespace might be:", tmpURL.Hostname(), tmpURL.Path)
repo.Namespace = filepath.Join(tmpURL.Hostname(), tmpURL.Path)
- // log.Info(repo.FullPath, "Namesapce =", repo.Namespace)
}
return &repo, nil
}