gitremote

package
v0.10.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package gitremote provides general-purpose git remote URL utilities: parsing, resolving, and redacting remote URLs. It has no dependency on checkpoint, strategy, or settings packages.

Index

Constants

View Source
const (
	ProtocolSSH   = "ssh"
	ProtocolHTTPS = "https"
	// ProtocolEntire is the scheme of Entire's git remote helper (entire://).
	// These URLs carry a forge/namespace prefix before owner/repo.
	ProtocolEntire = "entire"
)

Variables

This section is empty.

Functions

func GetPushURLs added in v0.10.0

func GetPushURLs(ctx context.Context, remoteName string) ([]string, error)

GetPushURLs returns every URL a push to remoteName delivers to, in the order git will use them.

A remote's push destinations are remote.<name>.pushurl when any is set and its remote.<name>.url otherwise (git's push_url_of_remote), and BOTH may repeat — git pushes to all of them, in config order. So this, not GetRemoteURL, describes where a push actually goes; GetRemoteURL reports the FETCH URL, which can name a different repository entirely.

Returns at least one entry on success.

func GetRemoteURL

func GetRemoteURL(ctx context.Context, remoteName string) (string, error)

GetRemoteURL returns the URL configured for the named git remote.

func GetRemoteURLInDir added in v0.6.3

func GetRemoteURLInDir(ctx context.Context, dir, remoteName string) (string, error)

GetRemoteURLInDir returns the URL configured for the named git remote in dir.

func IsSupportedForge added in v0.7.8

func IsSupportedForge(forge string) bool

IsSupportedForge reports whether forge is a known short forge id (e.g. "gh") understood by the trails API. It rejects forge hostnames ("github.com") and any other unrecognized value, so callers parsing a bare forge/owner/repo triple can fail clearly instead of forwarding a malformed forge to the API.

func RedactURL

func RedactURL(rawURL string) string

RedactURL removes credentials and query parameters from a URL for safe logging. SCP-style SSH URLs (e.g., git@github.com:org/repo.git) are returned as-is since they contain no embedded credentials.

func RedactURLOrPath added in v0.10.0

func RedactURLOrPath(remote string) string

RedactURLOrPath renders a remote for display with any credentials removed, accepting values that are not URLs at all.

RedactURL cannot be applied blanket-fashion: it round-trips through url.Parse and rebuilds "scheme://host/path", so a bare filesystem path like /srv/repo.git comes back as ":///srv/repo.git" and a bare word like "origin" as "://origin". Those inputs carry no credentials, so they pass through unchanged. Use this wherever the value may be a remote name, a local path, or a URL — i.e. anywhere a push/fetch target is shown to a user.

func ResolveRemoteRepo

func ResolveRemoteRepo(ctx context.Context, remoteName string) (forge, owner, repo string, err error)

ResolveRemoteRepo returns the forge identifier, owner, and repo name for the given git remote. The forge is the short id used by the trails API ("gh", "et", ...); it is derived from the hostname for direct git URLs or from the path prefix on entire:// URLs. It is empty for unrecognized hosts. For example, git@github.com:org/my-repo.git returns ("gh", "org", "my-repo").

Types

type Info

type Info struct {
	Protocol string
	Host     string
	Port     string
	Forge    string
	Owner    string
	Repo     string
}

Info holds the parsed components of a git remote URL. Host is the hostname only (never includes a port). Port is empty unless the source URL specified an explicit non-default port. Callers that need the combined "host[:port]" form should use HostPort.

Forge is the short identifier of the upstream forge ("gh", "et", ...) used by the Entire trails API. It is populated from the path prefix on entire:// URLs (entire://host/<forge>/owner/repo) and from a hostname lookup on direct git URLs (github.com → "gh"). It is empty for direct git URLs to unrecognized hosts, and for entire:// URLs without a forge segment.

func ParseURL

func ParseURL(rawURL string) (*Info, error)

ParseURL parses a git remote URL (SSH SCP-style or HTTPS) into its components.

func (*Info) CanonicalHost added in v0.7.6

func (i *Info) CanonicalHost() string

CanonicalHost returns the canonical public host of the upstream forge.

For direct git URLs this is just Host. For entire:// remotes — whose Host is the Entire cluster (e.g. aws-us-east-2.entire.io) rather than the forge — it maps the forge prefix back to the forge's host (gh → github.com). Falls back to Host when the forge is unknown (e.g. a self-hosted GitHub Enterprise), preserving the only host we know for it.

func (*Info) HostPort

func (i *Info) HostPort() string

HostPort returns Host, or "Host:Port" when Port is non-empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL