Documentation
¶
Overview ¶
Package giturl is a tiny, dependency-free predicate package for classifying Git remote URL forms (HTTP(s) vs SSH). Lives outside pkg/utils/git so callers in pkg/config and pkg/config/prompt can import it without the import cycle that pkg/utils/git creates by depending on pkg/config.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ParsedURL ¶
type ParsedURL struct {
// Host is the network authority — "github.com" or
// "gitea.example.com:2223". Includes port when non-standard.
Host string
// Owner is the first path segment — typically the org or user.
Owner string
// Repo is the second path segment, with any trailing ".git"
// stripped.
Repo string
// Scheme is the URL scheme — "https", "http", or "ssh"
// (scp-style git@host:path is reported as "ssh").
Scheme string
}
ParsedURL is the structured representation of a Git remote URL. Host-agnostic — works with any forge (github.com, gitea.example.com:2223, self-hosted gitlab, etc.). Use Parse to construct.
func Parse ¶
Parse extracts host/owner/repo/scheme from a Git remote URL. Accepted forms:
- https://host[:port]/owner/repo[.git]
- http://host[:port]/owner/repo[.git]
- ssh://[user@]host[:port]/owner/repo[.git]
- [user@]host:owner/repo[.git] (scp-style)
Returns an error on empty input, unparseable URLs, or paths that don't carry at least owner/repo segments.
func (*ParsedURL) HTTPCloneURL ¶
HTTPCloneURL returns the HTTPS clone-URL form regardless of the original scheme — useful when constructing forge URLs for users to click (e.g., GitHub's "/compare/..." page) without leaking agent-routed credentials.
For ssh-derived URLs (scp-style or ssh://), drops any port suffix on Host: an SSH port is meaningless to HTTPS, and leaving it in produces clickable URLs that 404 (browser trying HTTPS against the SSH daemon — was the bug behind operators clicking "https://gitea.example.com:2223/...").
For http/https-derived URLs, preserves the port — those may legitimately use a non-default HTTPS port like :8443.
func (*ParsedURL) HostName ¶
HostName returns Host with any "<host>:<port>" suffix stripped. Use for filesystem paths (where the colon would break tools like docker's -v <src>:<dst> volume specs) and TLS SAN comparisons (where the port is irrelevant). Falls back to Host unchanged when there's no port to strip.