summaryrefslogtreecommitdiff
path: root/internal/rtree/remote.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/rtree/remote.go')
-rw-r--r--internal/rtree/remote.go45
1 files changed, 22 insertions, 23 deletions
diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go
index 8435979..36e12dd 100644
--- a/internal/rtree/remote.go
+++ b/internal/rtree/remote.go
@@ -25,18 +25,18 @@ import (
"strings"
)
-//RemoteURL is the URL of a remote of a Git repository.
+// RemoteURL is the URL of a remote of a Git repository.
type RemoteURL string
-//ParseRemoteURL parses the given remote URL by substituting aliases defined in
-//the system-wide and user-global Git config. For example, with
+// ParseRemoteURL parses the given remote URL by substituting aliases defined in
+// the system-wide and user-global Git config. For example, with
//
-// $ cat /etc/gitconfig
-// [url "git://github.com/"]
-// insteadOf = gh:
+// $ cat /etc/gitconfig
+// [url "git://github.com/"]
+// insteadOf = gh:
//
-//and the input "gh:foo/bar", the result has a canonical URL of
-//"git://github.com/foo/bar".
+// and the input "gh:foo/bar", the result has a canonical URL of
+// "git://github.com/foo/bar".
func ParseRemoteURL(input string) RemoteURL {
var best *RemoteAlias
for _, current := range RemoteAliases {
@@ -52,15 +52,15 @@ func ParseRemoteURL(input string) RemoteURL {
return RemoteURL(best.Replacement + strings.TrimPrefix(input, best.Alias))
}
-//CanonicalURL returns the URL where the remote will be fetched from.
+// CanonicalURL returns the URL where the remote will be fetched from.
func (u RemoteURL) CanonicalURL() string {
return string(u)
}
-//CompactURL returns the most compact representation of this remote URL,
-//obtained by substituting the longest matching alias defined in the
-//system-wide or user-global Git config. This function is mostly the reverse of
-//ParseRemoteURL().
+// CompactURL returns the most compact representation of this remote URL,
+// obtained by substituting the longest matching alias defined in the
+// system-wide or user-global Git config. This function is mostly the reverse of
+// ParseRemoteURL().
func (u RemoteURL) CompactURL() string {
var best *RemoteAlias
for _, current := range RemoteAliases {
@@ -76,16 +76,15 @@ func (u RemoteURL) CompactURL() string {
return best.Alias + strings.TrimPrefix(string(u), best.Replacement)
}
-//This regex recognizes the scp-like syntax for git remotes
-//(i.e. "[user@]example.org:path/to/repo") as specified by the "GIT URLS"
-//section of man:git-clone(1).
+// This regex recognizes the scp-like syntax for git remotes
+// (i.e. "[user@]example.org:path/to/repo") as specified by the "GIT URLS"
+// section of man:git-clone(1).
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.git") -> "example.org/foo/bar"
+// 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.git") -> "example.org/foo/bar"
func (u RemoteURL) CheckoutPath() (string, error) {
stripped := strings.TrimSuffix(u.CanonicalURL(), ".git")
@@ -102,13 +101,13 @@ func (u RemoteURL) CheckoutPath() (string, error) {
return filepath.Join(parsed.Hostname(), parsed.Path), nil
}
-//MarshalYAML implements the yaml.Marshaler interface.
+// MarshalYAML implements the yaml.Marshaler interface.
func (u RemoteURL) MarshalYAML() (interface{}, error) {
//store URLs in the index in the compact format
- return u.CompactURL(), nil
+ return u.CanonicalURL(), nil
}
-//UnmarshalYAML implements the yaml.Unmarshaler interface.
+// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (u *RemoteURL) UnmarshalYAML(unmarshal func(interface{}) error) error {
var s string
err := unmarshal(&s)