Documentation
¶
Index ¶
- Variables
- func CreateBundle(base, cwd string) ([]byte, error)
- func CurrentBranch() (string, error)
- func CurrentBranchIn(dir string) (string, error)
- func GeneratePatch(base string) (string, error)
- func HeadRef(cwd string) (string, error)
- func HeadRefCtx(ctx context.Context, cwd string) (string, error)
- func IsBranchPushed() bool
- func MergeBase() (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".
var ErrNoOriginHEAD = errors.New("origin/HEAD is not set")
ErrNoOriginHEAD is returned by MergeBase when the upstream tracking branch is set but origin/HEAD is not — a common state after git init + push without fetch.
Functions ¶
func CreateBundle ¶ added in v0.7.122
CreateBundle creates a git bundle from base..HEAD in the repo at cwd and returns the raw bytes. If base is empty, the full history up to HEAD is bundled.
func CurrentBranch ¶
CurrentBranch returns the current git branch name resolved from the process CWD. Returns an error if in detached HEAD state or not in a git repo.
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 GeneratePatch ¶
GeneratePatch generates a binary diff from the given base commit, including untracked files. It temporarily stages untracked files with git add -N and resets them after generating the diff.
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.
func IsBranchPushed ¶ added in v0.7.1
func IsBranchPushed() bool
IsBranchPushed returns true if the current branch exists on the remote (i.e. refs/remotes/origin/<branch> is present locally).
func MergeBase ¶
MergeBase returns a commit SHA that the remote is guaranteed to have. Tries merge-base between upstream and origin/HEAD first, falls back to origin/HEAD.
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.