Documentation
¶
Overview ¶
Package gitread runs the read-only git commands the release, hooks, Repo scripts, and Deps services ask of a clone, and reads their answers: the current branch, uncommitted changes, what git is in the middle of, branches and tags here and on origin, the commits between two, the signing settings, where the hooks live, and a commit's tree, the newest commit to change a manifest, and a blob's contents. Message words their failures for the user, and DefaultBranch is the rule Repo scripts and Deps share for a repository's default branch.
Every command is checked against an exact allowlist before it runs, and anything else is refused with ErrGitCommandNotAllowed: no command here changes a clone's files, index, refs, or config, or runs a hook, and a status runs with the filter drivers the clone's own config defines turned off, so reading a clone runs no program the clone names. Each runs as `git -C <dir> -c core.fsmonitor=false -c submodule.recurse=false <args>`, with GIT_OPTIONAL_LOCKS=0, so a status never takes the index lock a release might need, and GIT_TERMINAL_PROMPT=0, so git never waits for an answer no one can give. core.hooksPath is left alone: the hooks scan needs the folder it names, and none of these commands runs a hook.
A tree's listing, a log, and a blob's contents are the repository's to make as large as it likes, so git is stopped, and the read fails with execpath.ErrOutputLimit, once one prints more than its cap.
git is the one on the PATH of the environment Config.Env returns, the login shell's in the app, so the checks use the same git, and the same credential helpers, as the tools the user releases with. The ls-remote commands, the only ones that reach origin, stop after RemoteTimeout, and run ssh in batch mode unless the user chose their own ssh command, which can carry an agent such as a password manager's. They run no program the clone's own config names (see remoteGuard): a remote helper is refused, and so is an http or https origin the clone's own config reroutes; only the file, http, https, and ssh transports are allowed; the clone's ssh command, password program, and credential helpers give way to the user's own; no cookie file is written; and origin is asked for git's own upload-pack. No other command reaches a transport at all.
The git commands that do change a clone, run elsewhere, get what they run with from a Setup (RemoteSetup, RemoteSetupFor, CheckoutSetup), which first refuses a clone whose own config holds a setting cloneconfig.go's classes refuse.
Index ¶
- Constants
- Variables
- func DefaultBranch(ctx context.Context, git OriginHeadReader, dir, stored string, ...) string
- func Hardening() []string
- func IsCommitID(oid string) bool
- func Message(err error) string
- func SetAsideNote(remote string, settings []string) string
- func ValidBranch(name string) bool
- func ValidLockfilePath(path string) bool
- func ValidManifestPath(path string) bool
- func ValidRemoteName(name string) bool
- type Change
- type CloneConfigError
- type Commit
- type Config
- type Entry
- type Git
- func (g *Git) Blob(ctx context.Context, dir, oid string) ([]byte, error)
- func (g *Git) ChangedFiles(ctx context.Context, dir, from, to string) ([]string, error)
- func (g *Git) Changes(ctx context.Context, dir string) ([]Change, error)
- func (g *Git) CheckedOutElsewhere(ctx context.Context, dir, branch string) ([]string, error)
- func (g *Git) CheckoutSetup(ctx context.Context, dir string) (Setup, error)
- func (g *Git) CloneConfig(ctx context.Context, dir string) error
- func (g *Git) CommitsBetween(ctx context.Context, dir, from, to string) (int, error)
- func (g *Git) CurrentBranch(ctx context.Context, dir string) (string, error)
- func (g *Git) Entries(ctx context.Context, dir string) ([]Entry, error)
- func (g *Git) FetchHead(ctx context.Context, dir string) (string, error)
- func (g *Git) GitFinder() execpath.Finder
- func (g *Git) HasCommit(ctx context.Context, dir, oid string) (bool, error)
- func (g *Git) Head(ctx context.Context, dir string) (string, error)
- func (g *Git) HookPaths(ctx context.Context, dir string) (HookPaths, error)
- func (g *Git) HooksDir(ctx context.Context, dir string) (string, error)
- func (g *Git) InProgress(ctx context.Context, dir string) (Operation, error)
- func (g *Git) IndexLocked(ctx context.Context, dir string) (bool, error)
- func (g *Git) IsAncestor(ctx context.Context, dir, oid, of string) (bool, error)
- func (g *Git) LastChange(ctx context.Context, dir, from, manifest, lockfile string) (Commit, error)
- func (g *Git) LocalBranch(ctx context.Context, dir, branch string) (string, error)
- func (g *Git) LocalSetup(ctx context.Context, dir string) (Local, error)
- func (g *Git) LocalTagCommit(ctx context.Context, dir, tag string) (string, error)
- func (g *Git) LocalVersionTags(ctx context.Context, dir string) ([]string, error)
- func (g *Git) OriginHead(ctx context.Context, dir string) (string, error)
- func (g *Git) ReadEnv() []string
- func (g *Git) RemoteBranch(ctx context.Context, dir, branch string) (string, error)
- func (g *Git) RemoteRefs(ctx context.Context, dir string) (RemoteRefs, error)
- func (g *Git) RemoteSetup(ctx context.Context, dir string) (Setup, error)
- func (g *Git) RemoteSetupFor(ctx context.Context, dir, remote string) (Setup, error)
- func (g *Git) RemoteTagCommit(ctx context.Context, dir, tag string) (string, error)
- func (g *Git) RemoteVersionTags(ctx context.Context, dir string) ([]string, error)
- func (g *Git) Run(ctx context.Context, dir string, args ...string) (stdout, stderr []byte, err error)
- func (g *Git) Shallow(ctx context.Context, dir string) (bool, error)
- func (g *Git) Signing(ctx context.Context, dir string) (Signing, error)
- func (g *Git) TrackingBranch(ctx context.Context, dir, branch string) (string, error)
- func (g *Git) TrackingCommit(ctx context.Context, dir, branch string) (string, error)
- func (g *Git) Tree(ctx context.Context, dir, commit string, keep func(path string) bool) ([]TreeEntry, error)
- func (g *Git) Unpushed(ctx context.Context, dir, branch string) (int, error)
- func (g *Git) Upstream(ctx context.Context, dir, branch string) (Upstream, error)
- func (g *Git) WorktreeDiff(ctx context.Context, dir, from string) (WorktreeDiff, error)
- type HookPaths
- type Local
- type Operation
- type OriginHeadReader
- type RefusedError
- type RemoteRefs
- type RemoteTag
- type SetAsideError
- type Setup
- type Signing
- type TreeEntry
- type Upstream
- type WorktreeDiff
Constants ¶
const ( // The settings of the clone's own an ls-remote set aside, as SetAsideError names them: // its ssh command, password program, and credential helpers. SetAsideSSHCommand = "core.sshCommand" SetAsideAskPass = "core.askPass" SetAsideHelpers = helperKey )
const MaxDiff = 1 << 20
MaxDiff is the most of a worktree's diff WorktreeDiff returns, in bytes.
const ( // RemoteTimeout bounds one ls-remote, the only command that reaches origin. RemoteTimeout = 15 * time.Second )
Variables ¶
var ErrCloneConfig = errors.New("this clone's own git config sets settings a command that changes it isn't run with")
ErrCloneConfig is returned, inside a CloneConfigError, for a clone whose own git config sets a setting a command that changes the clone isn't run with (cloneSettingAllowed).
var ErrCloneRoutes = errors.New("this clone's own git config changes how origin is reached, so it isn't asked from here")
ErrCloneRoutes is returned for a clone whose origin is on http or https and whose own config changes how it is reached: whether its certificate is checked and against what, a proxy, or the address its host resolves to (routeKeys). Asked from there, origin could be someone else, handed the user's credentials, cookies, and headers for the real host, so an ls-remote there is refused before it runs.
var ErrGitCommandNotAllowed = errors.New("git command not allowed")
ErrGitCommandNotAllowed is returned for a git command outside the allowlist, or a folder that is not absolute and clean; it is never run.
var ErrNoGit = errors.New("git can't be found on the login shell's PATH or in the usual tool folders")
ErrNoGit is returned for a Setup when git can't be found where every gitread command looks for it (GitFinder).
var ErrRemoteHelper = errors.New("origin is reached through a remote helper, which isn't run")
ErrRemoteHelper is returned for a clone whose origin is reached through a remote helper (a <helper>::<address> URL, after any insteadOf, or remote.origin.vcs): git looks for the helper as a program, then as an alias, which the clone's config can define, so an ls-remote there is refused before it runs.
var ErrRemoteTimeout = errors.New("origin didn't answer in time")
ErrRemoteTimeout is returned for an ls-remote that ran past RemoteTimeout, the only command here with a limit of its own.
var ErrWorkTree = errors.New("git doesn't take this folder as its clone's top folder")
ErrWorkTree is returned for a folder git doesn't take as its clone's top folder, as a subfolder of one, so no command that changes it runs there.
Functions ¶
func DefaultBranch ¶
func DefaultBranch(ctx context.Context, git OriginHeadReader, dir, stored string, guess func(branch string) bool) string
DefaultBranch works out the default branch of the repository the clone at dir is a clone of, as the app knows it without asking anyone: stored, the branch the app stored for the repository (the inbox's), when it stored one; else the branch the clone's refs/remotes/origin/HEAD names, read through git (OriginHead) when git isn't nil; else the first of main and master that guess accepts, when guess isn't nil, as Repo scripts takes the one the clone is on and Deps the one it has of origin's. It is "" when none of them names a branch, and a read that fails names none. Repo scripts and Deps share the rule.
func Hardening ¶
func Hardening() []string
Hardening returns the settings, ahead of its subcommand, that every git command the app runs to change a clone runs with: no hook from a hooks folder, the file system monitor off, and no submodule recursion. core.hooksPath points the hooks folder at an empty one. It doesn't reach the hooks a config names (hook.<name>.command and .event, from git 2.54): the clone's own hook.* settings refuse every command that could fire one (cloneconfig.go), which is what keeps them from running. Beside that, hook.<event>.enabled=false is set for every event git can fire (hookEvents): git 2.56 documents it as turning off every hook of the event, the user's own config hooks too, and a test shows it does there; a git whose config hooks predate that switch may read it as the switch of a hook named after the event, which turns off nothing, and a git older than config hooks ignores it. git runs hooks and the file system monitor with the clone as their working folder, so either could run a program the clone's own files hold, and a submodule's URL is the clone's to name. internal/worktrees runs each of its commands with them, and Repo scripts' pull too (RemoteSetup).
func IsCommitID ¶
IsCommitID reports a full commit ID, SHA-1 or SHA-256, that can name a commit. The null ID is refused: given as the old value to `update-ref -d` it turns the comparison off, and git reports it as the HEAD of a worktree with no commits. internal/worktrees holds its commit IDs to it too.
func Message ¶
Message is the part of a failure of one of gitread's commands, or of a command run with a Setup, worth showing the user: what git said, without the command and the exit status, or that origin didn't answer an ls-remote in time. A git failure's words are read from the *commandError in err's chain, not from err's text, so however a caller wraps it, its wrap never reaches the window. A clone whose own config sets settings a Setup refuses names them, and where to set them instead (CloneConfigError); a remote refused before anything ran says why, naming it (RefusedError, origin when none is named); and a command that failed after setting aside the clone's own ssh command, password program, or credential helpers says so, and where to set them instead.
func SetAsideNote ¶
SetAsideNote says which of the clone's own settings, of SetAsideSSHCommand, SetAsideAskPass, and SetAsideHelpers, a command reaching the clone's remote called remote went without, which may be why it failed, and where to set them so that they are used: the user's global config, for this folder alone with an includeIf, which gitread counts as the user's own. It is "" for none.
func ValidBranch ¶
ValidBranch reports a branch name the app may hand git as an argument: one that can't be read as an option, a range, a refspec's src:dst, or a pattern, and that git itself would take (validBranch).
func ValidLockfilePath ¶
ValidLockfilePath reports the path, in a commit's tree, of a lockfile gitread passes to git: a go.sum, pnpm-lock.yaml, package-lock.json, yarn.lock, bun.lock, or bun.lockb, as treePath has it.
func ValidManifestPath ¶
ValidManifestPath reports the path, in a commit's tree, of a manifest gitread passes to git: a go.mod or a package.json, as treePath has it. Deps holds what it reads to it.
func ValidRemoteName ¶
ValidRemoteName reports a remote's name the app may pass to git, which can't be read as an option, a path, or a URL: remoteNamePattern, with no "..", and at most maxNameLen bytes. internal/worktrees holds the remotes it fetches from to it too.
Types ¶
type Change ¶
type Change struct {
// Code is git's two-letter status, as in " M", "A ", "R ", or "??".
Code string
// Path is the file, relative to the worktree's top folder; for a rename or a copy,
// its new name. An untracked folder ends in "/".
Path string
}
Change is one changed or untracked file in a worktree.
type CloneConfigError ¶
type CloneConfigError struct {
// Keys are the settings, as git lists them (the section and the name lowercased), each
// once, in the order git reads them, and Origins where each was first set, as git names
// it (file:.git/config).
Keys []string
Origins []string
}
CloneConfigError is a command that changes a clone refused before anything ran, as the clone's own git config sets settings cloneSettingAllowed doesn't allow.
func (*CloneConfigError) Error ¶
func (e *CloneConfigError) Error() string
Error returns the refusal's text, with the settings and where each is set.
func (*CloneConfigError) Unwrap ¶
func (e *CloneConfigError) Unwrap() error
Unwrap returns ErrCloneConfig.
type Commit ¶
Commit is a commit as LastChange reads it: when it was committed, and its subject, the first line of its message.
type Config ¶
type Config struct {
// Env returns the environment each command starts from, read again for every
// command: in the app, the login shell's (shellenv), so git, ssh, and the credential
// helpers see what the user's terminal does. git is found on its PATH. It defaults to
// os.Environ.
Env func() []string
// Runner returns what runs one command, given that command's whole environment. It
// defaults to an execpath.Exec that runs with env and finds git on env's PATH, then
// in the well-known tool folders (execpath.Search).
Runner func(env []string) execpath.Runner
}
Config holds a Git's settings. Every field is optional.
type Entry ¶
type Entry struct {
// Code is git's two-letter status, "." standing for no change on that side, as in
// ".M" (changed, not staged), "M." (staged), or "A."; "??" is an untracked file.
Code string
// Index names what the index holds for the file: its staged object, or, for an
// unmerged file, its three stages' objects joined by ":"; "" for an untracked file. A
// file staged again shows as a new Index even when Code stays the same.
Index string
// Path is the file, relative to the worktree's top folder; for a rename or a copy, its
// new name, and From its old one.
Path string
From string
}
Entry is one changed, staged, unmerged, or untracked file in a worktree, as `git status --porcelain=v2` lists it.
type Git ¶
type Git struct {
// contains filtered or unexported fields
}
Git runs allowlisted, read-only git commands. It is safe for concurrent use.
func (*Git) Blob ¶
Blob returns the contents of the blob oid in the clone at dir (`cat-file blob`), a file a tree names, such as a manifest: read from the clone's objects, never its worktree, through no filter. git is stopped, and the read fails with execpath.ErrOutputLimit, holding none of it, once it prints more than maxBlob bytes, a mebibyte and a bit.
func (*Git) ChangedFiles ¶ added in v0.4.0
ChangedFiles returns the files the commits from from to to changed, as paths from the worktree's top, each once, in git's order: the files a run's commits touched. It reads the two commits' trees alone, never a file's contents. It fails when the clone lacks either commit (see HasCommit).
func (*Git) Changes ¶
Changes returns the worktree at dir's changed and untracked files, by `git status --porcelain`, which is the rule a release applies: any line means uncommitted changes.
func (*Git) CheckedOutElsewhere ¶
CheckedOutElsewhere returns the folders of the clone's other worktrees, every one but the one at dir, that have branch checked out. dir must be a worktree's top folder.
func (*Git) CheckoutSetup ¶
CheckoutSetup works out what a git command in the clone at dir that writes its files but reaches no remote runs with, as `git worktree add` does: RemoteSetup's, but that no remote is weighed and git may use no transport (Checkout), unless the clone is partial, whose promisor remotes are weighed as RemoteSetup weighs its remote.
func (*Git) CloneConfig ¶
CloneConfig reads the clone at dir's whole config and refuses it as every Setup does before anything runs, reading only the clone: a setting of its own outside cloneSettingAllowed (a CloneConfigError naming them), and settings that change how a host is reached where Git LFS may run (cloneRoutes). Repo scripts' branch status asks it before offering a pull that would be refused.
func (*Git) CommitsBetween ¶
CommitsBetween returns how many commits the commit to has that the commit from doesn't, as `rev-list --count from..to` counts them: the commits a fast-forward from one to the other brought. It fails when the clone lacks either commit (see HasCommit).
func (*Git) CurrentBranch ¶
CurrentBranch returns the branch checked out in the worktree at dir, as in "main", or "" when HEAD is detached.
func (*Git) Entries ¶
Entries returns every changed, staged, unmerged, and untracked file in the worktree at dir, each untracked file listed on its own, by `git status --porcelain=v2 --untracked-files=all`, which names what the index holds for each. Taken before and after a tool runs, they tell which files it changed or staged.
func (*Git) FetchHead ¶
FetchHead returns where the clone at dir keeps FETCH_HEAD, whether or not it is there: every fetch writes it, so its modification time is when the clone last fetched, and a clone that never fetched has none. It asks git where the file would be, which differs in a linked worktree.
func (*Git) GitFinder ¶
GitFinder returns what finds the git every Setup names, as every gitread command finds it: on the PATH of the environment Config.Env returns, the login shell's in the app, then in the well-known tool folders under its HOME. Core hands it to every other service that runs git on a clone, so one clone is never handled by two git builds.
func (*Git) Head ¶ added in v0.4.0
Head returns the commit checked out in the worktree at dir, or "" when it has none yet, as a worktree made with no commits: what a run left there as it ended.
func (*Git) HookPaths ¶
HookPaths returns the worktree at dir's top folder, hooks folder, and common git folder, which together tell a hooks folder only this clone uses from one shared with others.
func (*Git) HooksDir ¶
HooksDir returns the folder git runs the worktree at dir's hooks from: core.hooksPath when set, else the hooks folder in the common git folder.
func (*Git) InProgress ¶
InProgress returns what git is in the middle of in the worktree at dir: a rebase (or git am), a merge, a cherry-pick, or a revert, or OperationNone. It asks git where each one's file would be, which differs in a linked worktree, and looks for it.
func (*Git) IndexLocked ¶
IndexLocked reports whether the clone at dir's index is locked: whether git's index.lock, as a git that was writing the index, as a checkout does, leaves when it is cut off, is there. It asks git where the file would be, which differs in a linked worktree, and looks for it.
func (*Git) IsAncestor ¶
IsAncestor reports whether the commit oid is of or one of its ancestors. It fails when the clone lacks either commit (see HasCommit).
func (*Git) LastChange ¶
LastChange returns the newest commit, from the commit from back, merges left out, that changed the manifest at path manifest or, when lockfile isn't "", the lockfile at that path: when it was committed, and its subject; the zero Commit when none did. A shallow clone's history stops at its shallow commits, which the log takes as the first, so the answer is never older than they are. The manifest's path must be one ValidManifestPath takes, and the lockfile's one ValidLockfilePath does; each is passed with :(literal), so git reads no wildcard or other magic in it. The log runs no program the clone names: no signature is checked, and no external diff or textconv runs. git is stopped, and the read fails with execpath.ErrOutputLimit, once it prints more than maxLastChange bytes. It fails when the clone lacks the commit.
func (*Git) LocalBranch ¶
LocalBranch returns the commit the clone's branch points at, or "" when it has no such branch.
func (*Git) LocalSetup ¶
LocalSetup works out what a git command in dir, a clone or one of its worktrees, that reaches no remote runs with (Local), reading the config git reads there: no command here reaches the network. A config git can't read, a folder that isn't absolute and clean, and no git refuse it; a clone whose own config holds a setting a Setup would refuse is told by Local.Refused, so a read that runs none of its programs can go on.
func (*Git) LocalTagCommit ¶
LocalTagCommit returns the commit the clone's version tag points at, peeled through an annotated tag, or "" when the clone has no such tag.
func (*Git) LocalVersionTags ¶
LocalVersionTags returns the clone's version tags (v*), in git's order.
func (*Git) OriginHead ¶
OriginHead returns origin's default branch as the clone at dir last learned it, as in "main": the branch its refs/remotes/origin/HEAD points at, which git clone and git remote set-head write. It reads the clone's own refs and never asks origin. It is "" when the clone has no such ref, as one made with git init and git remote add, or when it doesn't name a branch of origin's.
func (*Git) ReadEnv ¶
ReadEnv returns the environment a read of a clone runs with, every gitread read's (environment) with replace refs ignored too: no transport (an empty GIT_ALLOW_PROTOCOL, which every git honors, so a partial clone's missing object is never fetched through a URL the clone names), no lazy fetch (GIT_NO_LAZY_FETCH, from git 2.44), no optional lock, no prompt, and no replace ref. The worktree service runs its own reads with it (git's --no-lazy-fetch, which only git 2.44 and later take, isn't passed: the app runs any git the user has).
func (*Git) RemoteBranch ¶
RemoteBranch asks origin for one branch's commit (`ls-remote --heads origin refs/heads/<branch>`), and returns it, or "" when origin has no such branch, under every guard an ls-remote runs under: origin answers with that one branch, never every branch and tag it has. A branch ValidBranch refuses is refused (ErrGitCommandNotAllowed). It stops after RemoteTimeout.
func (*Git) RemoteRefs ¶
RemoteRefs asks origin for its branches and tags (`ls-remote --heads --tags origin`), which also says whether origin can be reached. It stops after RemoteTimeout.
func (*Git) RemoteSetup ¶
RemoteSetup works out what a git command in the clone at dir that reaches origin and writes the clone's files runs with (Setup), reading the clone's config, its folders, and origin's URL (`ls-remote --get-url`, which asks origin nothing): no command here reaches the network. It refuses, before anything runs, a clone whose own config holds a setting cloneSettingAllowed doesn't allow (a CloneConfigError naming them), a folder that isn't its clone's top folder (ErrWorkTree), what an ls-remote's guard refuses (an origin reached through a remote helper, a RefusedError naming it, for a partial clone its promisor remotes too), a clone whose own config reroutes a host where it would matter (ErrCloneRoutes), and a setting it can't pass safely (ErrGitCommandNotAllowed).
func (*Git) RemoteSetupFor ¶
RemoteSetupFor is RemoteSetup for the clone's remote called remote, as worktree creation fetches from a fork's upstream: that remote's URL and remote helper are weighed in origin's place. A name that isn't one is refused (ErrGitCommandNotAllowed). Its Checkout serves the same clone's checkout.
func (*Git) RemoteTagCommit ¶
RemoteTagCommit asks origin for the commit its version tag names, peeled, or "" when origin has no such tag. It stops after RemoteTimeout.
func (*Git) RemoteVersionTags ¶
RemoteVersionTags asks origin for its version tags (v*) and returns their names, sorted. It stops after RemoteTimeout.
func (*Git) Run ¶
func (g *Git) Run(ctx context.Context, dir string, args ...string) (stdout, stderr []byte, err error)
Run runs `git -C dir -c core.fsmonitor=false -c submodule.recurse=false args...` and returns what git wrote, once args has passed the allowlist and dir is absolute and clean; otherwise it returns ErrGitCommandNotAllowed and runs nothing. A non-zero exit is an error that execpath.ExitCode reads. An ls-remote stops after RemoteTimeout, when the error wraps context.DeadlineExceeded. One that fails otherwise, after setting aside a setting the clone's own config makes, returns a *SetAsideError.
func (*Git) Shallow ¶
Shallow reports whether the clone at dir is shallow (`rev-parse --is-shallow-repository`): its history stops at the commits it was cut at, so a log reaches nothing older.
func (*Git) TrackingBranch ¶
TrackingBranch returns the commit origin's branch pointed at when the clone last learned it (refs/remotes/origin/<branch>), or "" when the clone has no such ref.
func (*Git) TrackingCommit ¶
TrackingCommit returns the commit origin's branch pointed at when the clone last learned it, peeled (refs/remotes/origin/<branch>^{commit}), so the answer is always a commit's ID, or "" when the clone has no such ref or it names no commit. gitread knows only the remote origin: a clone whose remote has another name has no such ref.
func (*Git) Tree ¶
func (g *Git) Tree(ctx context.Context, dir, commit string, keep func(path string) bool) ([]TreeEntry, error)
Tree returns the files in the commit's tree, every subfolder's included, whose paths keep accepts (every one for a nil keep), in git's order, each with its object and a blob's size: `ls-tree -r -z -l --full-tree`, which reads the commit's trees and its objects' sizes, never a file's contents, nor the worktree. git is stopped, and the read fails with execpath.ErrOutputLimit, holding none of the listing, once it prints more than maxTreeListing bytes, as a tree of millions of files would. It fails when the clone lacks the commit (see HasCommit), or a blob in it, as a partial clone may.
func (*Git) Unpushed ¶
Unpushed returns how many commits the clone's branch has that origin's branch, as the clone last learned it, doesn't. It fails when either ref is missing (see LocalBranch and TrackingBranch).
func (*Git) Upstream ¶
Upstream returns the upstream config of the clone's branch, which a release's `pull --rebase origin` needs. A key that isn't set is "".
func (*Git) WorktreeDiff ¶ added in v0.4.0
WorktreeDiff returns the worktree at dir's changes since the commit from, committed or not, read-only: a diff from the commit to the worktree's files, run with no external diff, no textconv, and the clone's own filter drivers off, so it runs no program the clone names; and the files git doesn't track. It fails when the clone lacks the commit.
type HookPaths ¶
type HookPaths struct {
// Toplevel is the worktree's top folder.
Toplevel string
// Hooks is the folder git runs hooks from: core.hooksPath when set, else the hooks
// folder in the common git folder.
Hooks string
// CommonDir is the git folder the clone's worktrees share, as in <clone>/.git.
CommonDir string
}
HookPaths is where a worktree's hooks live, as git resolves them. A relative answer from git is made absolute against the folder asked about; an absolute one is kept as git gives it.
type Local ¶
type Local struct {
Setup
// Refused, when set, is why a command there that could run one of the clone's own
// programs, as a status's clean filter or a hook, must not run: the clone's own config
// holds a setting cloneSettingAllowed doesn't allow (a CloneConfigError naming them).
Refused error
}
Local is what a git command in a clone, or in one of its worktrees, that reaches no remote and writes no file of the clone's runs with (LocalSetup), as the worktrees' own status, removal, and branch deletion do: Setup's git and settings, the environment a read runs with (no transport, no lazy fetch, no optional lock, no replace ref), and every filter driver the clone's own config defines turned off, Git LFS's too, as a read does.
type Operation ¶
type Operation string
Operation is what git is in the middle of in a worktree, if anything.
type OriginHeadReader ¶
OriginHeadReader reads origin's default branch as a clone last learned it, from its own refs/remotes/origin/HEAD, asking no one: *Git.
type RefusedError ¶
RefusedError is a remote gitread's guards refused before anything ran: Remote is its name, and Err says why, ErrRemoteHelper or ErrCloneRoutes, with the setting or the URL that refused it.
func (*RefusedError) Error ¶
func (e *RefusedError) Error() string
Error returns the refusal's text.
type RemoteRefs ¶
type RemoteRefs struct {
// Heads maps each branch, as in "main", to the commit it points at.
Heads map[string]string
// Tags maps each tag, as in "v1.4.2", to what it names.
Tags map[string]RemoteTag
}
RemoteRefs is what origin has, as ls-remote lists it.
type RemoteTag ¶
type RemoteTag struct {
// Object is what the tag's ref points at: an annotated tag's own object, or a
// lightweight tag's commit.
Object string
// Commit is the commit the tag names: the peeled one for an annotated tag.
Commit string
}
RemoteTag is one of origin's tags.
type SetAsideError ¶
type SetAsideError struct {
// Err is the command's error, and Settings the settings set aside, of
// SetAsideSSHCommand, SetAsideAskPass, and SetAsideHelpers.
Err error
Settings []string
// Remote is the remote the command reached, "" for origin.
Remote string
}
SetAsideError is an ls-remote, or a fetch run with RemoteSetupFor's settings, that failed after gitread set aside settings, which may be why it failed: the clone picks its own ssh key with core.sshCommand, say, which gitread doesn't run. Its text is the command's own.
func (*SetAsideError) Error ¶
func (e *SetAsideError) Error() string
Error returns the ls-remote's error's text.
func (*SetAsideError) Unwrap ¶
func (e *SetAsideError) Unwrap() error
Unwrap returns the ls-remote's error.
type Setup ¶
type Setup struct {
// Git is git's absolute path, as GitFinder finds it: the git the command must run.
Git string
// Env is the command's whole environment, its settings in it, so its argv holds
// nothing but git's own words:
//
// - for one that reaches a remote, the ls-remote's (remoteGuard), with
// GIT_TERMINAL_PROMPT=0, the transports GIT_ALLOW_PROTOCOL allows, and the ssh
// command the user's own config or environment chose, else a batch-mode ssh; for one
// that reaches none (Checkout), the same but that it allows no transport.
// GIT_NO_LAZY_FETCH=1 is in it, but for a partial clone, whose promisor remotes the
// guard has weighed too;
// - GIT_DIR and GIT_WORK_TREE, the clone's git folder and the folder itself, which
// beat anything its config says;
// - Settings, through GIT_CONFIG_COUNT, after any the environment passes already.
Env []string
// Settings are the key=value settings Env passes, read only to say what they are:
// Hardening's; fetchHardening's; the remote guard's, which set aside the clone's own
// password program and credential helpers for the user's own, and save no cookie; and
// every filter driver the clone's own config defines but Git LFS's turned off.
Settings []string
// SetAside names the clone's own settings set aside, of SetAsideSSHCommand,
// SetAsideAskPass, and SetAsideHelpers, which may be why a command that reached a
// remote failed: SetAsideNote says so.
SetAside []string
// Partial reports a partial clone, whose checkout may fetch a missing file's contents
// from its promisor remote.
Partial bool
}
Setup is what a git command that changes a clone runs with, Repo scripts' pull and worktree creation's fetches, ls-remote, and checkouts: the clone's own config weighed setting by setting first (cloneconfig.go), then every guard gitread's own ls-remote runs under, and those a status runs under, so a command that changes a clone is held tighter than the reads.
func (Setup) Checkout ¶
Checkout returns s for a command that writes the clone's files and reaches no remote, as `git worktree add` does, from a Setup RemoteSetupFor worked out for the same clone: the same, but that git may use no transport, unless the clone is partial, whose checkout may fetch a missing file's contents from its promisor remotes, which the setup weighed.
type Signing ¶
type Signing struct {
// SignTags is tag.gpgSign: every annotated tag is signed.
SignTags bool
// SignAnnotated is tag.forceSignAnnotated: an annotated tag made without asking for
// a signature is signed.
SignAnnotated bool
// Format is gpg.format, as in "openpgp", "x509", or "ssh", or "" when unset, which
// git reads as openpgp.
Format string
// Key is user.signingkey as written, or "" when unset: a key ID, a key file (which
// may start with ~), or a key itself.
Key string
}
Signing is the clone's tag signing config, as git reads it there.
type TreeEntry ¶
type TreeEntry struct {
// Path is the file, from the tree's top, with slashes.
Path string
// Mode is git's mode for it, as in 100644, 100755, 120000 (a symbolic link), or
// 160000 (a submodule), and Type its object's type as git names it: blob, or, for a
// submodule, the type of the object a submodule's entry points at.
Mode string
Type string
// Object is its object's ID, and Size a blob's size in bytes, or -1 for a submodule,
// which git gives no size, and for a blob the clone doesn't hold.
Object string
Size int64
// Missing reports a blob the clone doesn't hold, as a partial clone may lack one it
// never fetched: its history can be read, but not its contents.
Missing bool
}
TreeEntry is one file in a commit's tree, as `git ls-tree -r -l` lists it.
type Upstream ¶
type Upstream struct {
// Remote is branch.<b>.remote, as in "origin", or "" when unset.
Remote string
// Ref is branch.<b>.merge, as in "refs/heads/main", or "" when unset.
Ref string
}
Upstream is the branch a local branch is set to follow, from its config.
type WorktreeDiff ¶ added in v0.4.0
type WorktreeDiff struct {
// Patch is git's unified diff from the commit to the worktree's files, at most MaxDiff
// bytes, cut at a line's end; Cut reports a patch cut short.
Patch string
Cut bool
// Untracked are the files git doesn't track, which no patch shows, from the
// worktree's top.
Untracked []string
}
WorktreeDiff is a worktree's changes since a commit: what its commits since then changed, and what isn't committed yet, as one patch, and the files git doesn't track.