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.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/internal/rtree/remote.go b/internal/rtree/remote.go
index 0c4e880..b2b3340 100644
--- a/internal/rtree/remote.go
+++ b/internal/rtree/remote.go
@@ -49,6 +49,25 @@ func ExpandRemoteURL(remoteURL string) string {
return best.Replacement + strings.TrimPrefix(remoteURL, best.Alias)
}
+//ContractRemoteURL takes the canonical URL for a given remote and shortens it
+//as much as possible by substituting an alias from the system-wide and
+//user-global Git config. This function is pretty much the reverse of
+//ExpandRemoteURL().
+func ContractRemoteURL(remoteURL string) string {
+ var best *RemoteAlias
+ for _, current := range RemoteAliases {
+ if strings.HasPrefix(remoteURL, current.Replacement) {
+ if best == nil || len(best.Replacement) < len(current.Replacement) {
+ best = current
+ }
+ }
+ }
+ if best == nil {
+ return remoteURL
+ }
+ return best.Alias + strings.TrimPrefix(remoteURL, 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).