gitremote

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitremote reads and switches a checkout's GitHub origin between the three transport modes: profile (git@github-<profile>:owner/repo.git), ssh (git@github.com:owner/repo.git) and https (https://github.com/owner/repo.git).

Index

Constants

View Source
const (
	StateManaged   = "managed"   // a GitHub origin authama can switch
	StateNoOrigin  = "no-origin" // not a repository, or one with no origin
	StateUnmanaged = "unmanaged" // an origin that is not a GitHub remote
)

Checkout states, as `ssh git status` reports them.

View Source
const (
	ProfileFromRemote = "remote" // the origin names it (profile mode)
	ProfileFromOwner  = "owner"  // defaults.git.orgs, then defaults.git.profile
	ProfileFromFlag   = "flag"   // --profile on `ssh git use`
)

Profile sources: where a managed checkout's profile came from.

Variables

This section is empty.

Functions

func URLFor

func URLFor(m *manifest.Manifest, mode, owner, repo, profile string) (string, error)

URLFor builds the origin URL for owner/repo in mode. Profile mode needs a profile with a github.com host; ssh mode needs defaults.git.profile, whose key `Host github.com` uses.

Types

type Change

type Change struct {
	Dir, From, To string
	Applied       bool
	Skipped       string // why nothing changed; empty when it changed or would
	// Owner and Repo are the origin's; Profile is the one the new URL is built
	// for, and ProfileFrom says what chose it. All four are empty when the
	// checkout was skipped before its origin was parsed.
	Owner, Repo, Profile, ProfileFrom string
}

Change is what `use` did, or would do, to one checkout.

func Use

func Use(g Git, m *manifest.Manifest, dir, mode, profile string, dryRun bool) (Change, error)

Use points dir's origin at mode. The new URL is proven with ls-remote before origin is rewritten, so a checkout never ends up with a remote it cannot authenticate to.

type Checkout added in v0.1.6

type Checkout struct {
	Path  string `json:"path"`
	State string `json:"state"`
	URL   string `json:"url,omitempty"`
	Mode  string `json:"mode,omitempty"`
	Owner string `json:"owner,omitempty"`
	Repo  string `json:"repo,omitempty"`
	// Profile is empty when neither the origin nor the manifest names one.
	Profile     string `json:"profile,omitempty"`
	ProfileFrom string `json:"profile_from,omitempty"`
}

Checkout is one checkout's origin, as `ssh git status` reports it. Its JSON is the shape `ssh git status --json` prints, which other tools read: add fields, never rename or remove one, and say so in the CHANGELOG.

func Status added in v0.1.6

func Status(g Git, m *manifest.Manifest, dirs []string) []Checkout

Status reads each directory's origin and says how it reaches GitHub.

type Exec

type Exec struct{}

Exec is Git through the git binary.

func (Exec) LsRemote

func (e Exec) LsRemote(dir, url string) error

func (Exec) Origin

func (e Exec) Origin(dir string) (string, error)

func (Exec) SetOrigin

func (e Exec) SetOrigin(dir, url string) error

type Git

type Git interface {
	Origin(dir string) (string, error)
	LsRemote(dir, url string) error
	SetOrigin(dir, url string) error
}

Git is the slice of git this package needs, so tests can stand in for the network.

type Remote

type Remote struct {
	URL     string
	Mode    string // profile, ssh or https
	Owner   string
	Repo    string
	Profile string // profile mode: the profile whose alias it uses
}

Remote is a parsed GitHub origin.

func Parse

func Parse(m *manifest.Manifest, url string) (Remote, bool)

Parse recognises a GitHub origin. ok is false for anything else, which callers leave alone.

type Resolution added in v0.1.6

type Resolution struct {
	Profile, Mode, URL, HostAlias string
	Key                           *manifest.KeyRef
}

Resolution is how one GitHub repository would be reached: the profile that owns it, the mode, the remote URL, and the SSH alias and key that URL authenticates with. HostAlias and Key are empty in https mode, which uses the git credential helper rather than a key.

func Resolve added in v0.1.6

func Resolve(m *manifest.Manifest, owner, repo, mode, profile string) (Resolution, error)

Resolve works out how owner/repo would be reached, touching nothing. The profile is the one given, else the owner's (manifest.ProfileForOwner), which may be empty outside profile mode when no profile is mapped. In profile mode the alias and key are the profile's github.com host; in ssh mode they are Host github.com and defaults.git.profile's key, which that host uses.

Jump to

Keyboard shortcuts

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