Documentation
¶
Overview ¶
Package localgit reads the local Git repository through the git binary.
It is deliberately read-only where credentials are concerned: nothing here writes a token into .git/config, and nothing here pushes. Pushing is always the user's own `git push`, with the credentials already on their machine.
Index ¶
Constants ¶
const DefaultRemoteName = "origin"
DefaultRemoteName is the remote picked when a repository has several and the caller did not name one.
const Placeholder = "[redacted: unrecognized remote URL]"
Placeholder stands in for a remote URL whose parts could not be identified, so that none of its contents are echoed.
Variables ¶
var ( // remotes. The directory may not be a repository, git may be missing, or // git may have refused to read it — dubious ownership in a container, // an unreadable config. git's own message is appended whenever there is // one, because the fix differs sharply per cause and "not a git // repository" points nowhere near most of them. ErrGitUnavailable = errors.New("could not read this directory's Git repository") // ErrNoRemotes indicates a repository that has no remote configured. ErrNoRemotes = errors.New("no remote URLs found in your Git config") // ErrNotGitHub indicates a remote URL that does not point at github.com. ErrNotGitHub = errors.New("remote is not a github.com repository") // ErrUnparsableRemote indicates a remote URL that is not a recognizable Git URL. ErrUnparsableRemote = errors.New("remote URL could not be parsed") )
Functions ¶
func Redact ¶
Redact renders a remote URL safe to print. CI systems rewrite remotes to carry a job token — GitLab's is "https://gitlab-ci-token:<token>@…", and the url.<base>.insteadOf idiom injects one into any URL — so a message naming the remote would otherwise put that token in the build log.
A recognized URL comes back with its whole userinfo removed, not just a password field: a token is as often the entire userinfo ("https://<pat>@github.com/owner/repo.git" is GitHub's own documented form), and nothing distinguishes that from a user name.
Anything whose parts cannot be identified comes back as Placeholder rather than verbatim. git accepts remotes whose "URL" is a command line ("ext::ssh -o Password=… %S repo.git"), a local path, or — when an argument was mistyped — a bare token, and none of those can be safely echoed.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client runs git in the working directory.
func New ¶
func New(deps cliruntime.Deps) Client
New returns a client that runs the real git binary unless deps injects a runner.
type Remote ¶
type Remote struct {
Name string
// FetchURL is where the remote fetches from.
FetchURL string
// PushURLs is every destination a push to this remote reaches. git accepts
// several `remote.<name>.pushurl` entries and a single push updates all of
// them, so a remote with more than one names no single repository to bind.
// git prints the fetch URL as the sole push URL unless a pushurl is set.
PushURLs []string
}
Remote is one configured Git remote.
func SelectRemote ¶
SelectRemote picks the remote to connect. A named remote must exist. With no name, a lone remote is taken as-is and "origin" wins among several; anything else is ambiguous and the caller has to choose.
func (Remote) Diverges ¶
Diverges reports whether this remote fetches from somewhere other than the single place it pushes to.
func (Remote) PushTarget ¶
PushTarget returns the one repository a push to this remote reaches. A push is what triggers a deployment, so this — not the fetch URL — is what a binding has to name; a remote that reaches several has no answer, and choosing one would bind a repository while pushes kept updating the others.
type Repository ¶
Repository is a GitHub repository identified by a remote URL.
func ParseGitHubRepository ¶
func ParseGitHubRepository(rawURL string) (Repository, error)
ParseGitHubRepository resolves a Git remote URL to the GitHub repository it names. It accepts the three forms GitHub hands out — scp-like SSH (git@github.com:owner/repo.git), ssh:// URLs, and https:// URLs — and rejects anything hosted elsewhere, since the platform's only provider is GitHub.
func (Repository) FullName ¶
func (r Repository) FullName() string
FullName returns the owner/name form the API selects repositories by.