remote

package
v0.21.4 Latest Latest
Warning

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

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

Documentation

Overview

Package remote turns a git remote URL into the pieces a forge call needs.

Index

Constants

View Source
const DefaultName = "origin"

DefaultName is the remote a project pushes to unless told otherwise.

Variables

View Source
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.

View Source
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

func TokenBoundToOrigin(settings repo.Settings, origin string) repo.Settings

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

func FromRepository(path, name string) (Remote, error)

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 Parse

func Parse(raw string) (Remote, error)

Parse reads a git remote URL in any of the forms git accepts.

func (Remote) EndpointHost added in v0.19.1

func (r Remote) EndpointHost() string

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.

func (Remote) Named added in v0.5.0

func (r Remote) Named(name render.Forge) (Remote, error)

Named sets the forge for a host that did not reveal one (spec 0009 D3).

An empty name changes nothing. A name that agrees with what the host said changes nothing. A name that disagrees is refused rather than honoured.

Jump to

Keyboard shortcuts

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