Documentation
¶
Overview ¶
Package remote turns a git remote URL into the pieces a forge call needs.
Index ¶
Constants ¶
const DefaultName = "origin"
DefaultName is the remote a project pushes to unless told otherwise.
Variables ¶
var ErrForgeMismatch = errors.New("remote: forge mismatch")
ErrForgeMismatch reports a forge named for a host that is known to be a different one. The host is the stronger evidence, and letting the name win would send one forge's token to another's client.
var ErrNotARepository = errors.New("remote: not a repository URL")
ErrNotARepository reports a remote that cannot be read as owner/repo on a host.
Functions ¶
func TokenBoundToOrigin ¶ added in v0.21.3
TokenBoundToOrigin names origin as the host a token may go to. go/repo assumes the public forge when Settings.Host is empty and refuses every other host (go/repo spec 0011). Plain http stays refused unless settings opt in: a remote's scheme is no opt-in, since `http://gitlab.com` would send the token in clear.
Types ¶
type Remote ¶
type Remote struct {
// Host is the forge's hostname, without scheme, port or credentials.
Host string
// Owner is everything before the final path element. On this estate that
// is frequently a nested group such as "phpboyscout/go", not a single
// name.
Owner string
Repo string
// Forge names the URL conventions, and is EMPTY when the host is not
// recognised. A self-hosted instance cannot be identified by hostname, and
// guessing would point every link in the changelog somewhere that does not
// exist.
Forge render.Forge
// Origin is the forge's scheme, host and port, such as
// "http://localhost:3000". An ssh remote's port is git's, not the web's,
// so it gives "https://" and the hostname.
Origin string
// WebURL is the project's browsable URL, with any credentials removed.
WebURL string
}
Remote is a parsed git remote.
func FromRepository ¶
FromRepository reads the named remote out of the repository at path and parses it.
EnableDotGitCommonDir matters here for the same reason it does when reading history: in a linked worktree .git is a FILE pointing elsewhere, and without following it the repository opens and reports no remotes at all.
func (Remote) EndpointHost ¶ added in v0.19.1
EndpointHost is Origin in the form the forge's adapter reads as forge.Endpoint.Host. forge-github prefixes https:// to whatever it is given, so GitHub takes the bare host and port; the others keep the scheme.