From 4e0b90e3fb9c2c1276a695692179f59dda481e81 Mon Sep 17 00:00:00 2001 From: Sandro Jäckel Date: Wed, 8 Sep 2021 16:13:52 +0200 Subject: rtree: strip final .git from clone URLs otherwise paths contain a final .git when using the clone URLs copied from the GitHub Web UI --- internal/rtree/remote.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'internal/rtree/remote.go') diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go index 484dd92..6e073a5 100644 --- a/internal/rtree/remote.go +++ b/internal/rtree/remote.go @@ -87,7 +87,8 @@ var scpSyntaxRx = regexp.MustCompile(`^(?:[^/@:]+@)?([^/:]+\.[^/:]+):(.+)$`) // RemoteURL("git@example.org:foo/bar") -> "example.org/foo/bar" // func (u RemoteURL) CheckoutPath() (string, error) { - match := scpSyntaxRx.FindStringSubmatch(u.CanonicalURL()) + stripped := strings.TrimSuffix(u.CanonicalURL(), ".git") + match := scpSyntaxRx.FindStringSubmatch(stripped) if match != nil { //match[1] is the hostname, match[2] is the path to the repo return filepath.Join(match[1], match[2]), nil -- cgit v1.3.1 From 8cea64eb2a4e51275bda51533536f9d7ad358208 Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Wed, 8 Sep 2021 17:17:11 +0200 Subject: also strip final .git from clone URLs that are not SSH syntax --- internal/rtree/remote.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'internal/rtree/remote.go') diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go index 6e073a5..8435979 100644 --- a/internal/rtree/remote.go +++ b/internal/rtree/remote.go @@ -84,17 +84,18 @@ var scpSyntaxRx = regexp.MustCompile(`^(?:[^/@:]+@)?([^/:]+\.[^/:]+):(.+)$`) //CheckoutPath derives the checkout path for a remote URL. // // RemoteURL("https://example.org/foo/bar") -> "example.org/foo/bar" -// RemoteURL("git@example.org:foo/bar") -> "example.org/foo/bar" +// RemoteURL("git@example.org:foo/bar.git") -> "example.org/foo/bar" // func (u RemoteURL) CheckoutPath() (string, error) { stripped := strings.TrimSuffix(u.CanonicalURL(), ".git") + match := scpSyntaxRx.FindStringSubmatch(stripped) if match != nil { //match[1] is the hostname, match[2] is the path to the repo return filepath.Join(match[1], match[2]), nil } - parsed, err := url.Parse(u.CanonicalURL()) + parsed, err := url.Parse(stripped) if err != nil { return "", err } -- cgit v1.3.1