Documentation
¶
Index ¶
- Variables
- func CurrentBranchIn(dir string) (string, error)
- func DefaultBranchIn(dir string) (string, error)
- func HeadRef(cwd string) (string, error)
- func HeadRefCtx(ctx context.Context, cwd string) (string, error)
- func RepoRoot(from string) (string, error)
- func TopLevelCtx(ctx context.Context, dir string) string
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotRegularFile reports a changed path that is neither a regular file // nor absent — most often a dirty submodule, whose state lives in another // repository and so cannot be hashed from here. ErrNotRegularFile = errors.New("changed path is not a regular file") // ErrDigestBudget reports that the changed files total more than the digest // budget, the point past which hashing them costs more than whatever the // caller would have skipped. ErrDigestBudget = errors.New("changed files exceed the digest budget") )
Errors reported by Fingerprint. They name the condition that stopped it, because a caller that silently stops caching for one repo and not another is otherwise impossible to explain: each of these means "this tree cannot be fingerprinted at all", not "nothing has changed".
Functions ¶
func CurrentBranchIn ¶ added in v0.7.160
CurrentBranchIn returns the current git branch name for the repo rooted at dir. Returns an error if in detached HEAD state or not in a git repo.
func DefaultBranchIn ¶ added in v0.7.174
DefaultBranchIn returns the default branch of the repo rooted at dir — the branch a PR merges into. It reads the remote HEAD symref git records at clone time, trying origin before upstream so a fork checkout whose canonical remote is upstream still resolves. An error is a routine answer, not a failure: a repo created with `git init` and pushed has no remote HEAD at all, and callers are expected to fall back rather than treat this as fatal.
func HeadRef ¶ added in v0.7.122
HeadRef returns the SHA of the current HEAD commit in the repo at cwd.
func HeadRefCtx ¶ added in v0.7.138
HeadRefCtx returns the SHA of the current HEAD commit in the repo at cwd, honouring ctx for cancellation/timeout.
Types ¶
type Worktree ¶ added in v0.7.144
type Worktree struct {
// Head is the SHA of the current HEAD commit.
Head string
// Digest hashes every path git reports as changed, contents included.
Digest string
// Clean reports whether git sees no change at all relative to HEAD: nothing
// modified, staged, or untracked.
Clean bool
}
Worktree fingerprints the state of a git working tree at a point in time. Two Worktrees with equal Head and Digest describe trees with identical content, so callers can compare one against a previously recorded value to decide whether anything has changed since.
The zero Worktree describes no tree at all. It reports the tree as not clean and is refused as a cache key, so a caller holding one falls back to doing whatever work it might otherwise have skipped. Fingerprint returns it alongside an error saying which condition made the tree unfingerprintable.
func Fingerprint ¶ added in v0.7.144
Fingerprint captures the state of the working tree at dir: the HEAD commit plus a digest of the porcelain status entries — which record adds, deletions, renames and mode changes — and the current contents of every changed path.
Hashing contents is what makes the fingerprint sensitive to repeated edits. Porcelain output for a modified file is byte-identical before and after a further edit (both report " M path"), so status alone would call the tree unchanged across that edit — exactly the loop a Stop hook runs in.
The error is non-nil when the tree's state cannot be established: dir is not a repo, the repo has no commits yet, a changed path cannot be read, or the tree exceeds the digest budget. The returned Worktree is then the zero value, which is safe to pass on: no caller can mistake it for a real tree.