Documentation
¶
Overview ¶
Package gitread reads git repository state straight out of .git, with no exec dependency and no git library: the daemon must work on machines where a git binary may not exist, and hooks fire on every prompt. The readers back the provenance stamp on captured plans and subagent notes (internal/hooks), the gardener's stale-plan ship evidence (internal/gardener), and the repo root / main-worktree / origin identity a cwd registers a project by (internal/store). Every failure yields a zero value -- all reads are best-effort by design.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Head ¶
Head resolves the repo's current commit at cwd: a detached HEAD is the hash itself; a symbolic ref is dereferenced via its loose ref file, then packed-refs, following a worktree's gitdir pointer and commondir. Any failure yields "".
func MainWorktreeRoot ¶ added in v0.5.0
MainWorktreeRoot resolves a linked-worktree root to the root of its main checkout. A linked worktree's .git is a file ("gitdir: <admin dir>") whose admin dir lives under the main repository's .git/worktrees/<name>/, and the commondir file inside it points back at the shared .git directory; the main checkout root is that directory's parent. Everything else resolves to root unchanged: a regular checkout (.git directory), a submodule (gitdir under .git/modules/, no commondir file -- a genuinely separate repository), a bare main repo (commondir not named .git, so there is no main checkout), or an unparseable/stale layout. Pure filesystem -- hooks and session_start must not depend on a git executable.
func OriginURL ¶ added in v0.5.0
OriginURL returns the url of the repository's "origin" remote, read straight out of .git/config -- the one piece of repo identity that survives being cloned to another machine under a different path, which is what makes it usable for deciding whether two checkouts are the same project.
"" when the repo has no origin (a purely local repo, or one whose remote goes by another name): absent is absent, never a guess at some other remote. The config is read from the worktree's own admin dir first and then the shared common dir, since a linked worktree keeps its remotes in the latter.
Types ¶
type ReflogEntry ¶
ReflogEntry is one HEAD reflog line: HEAD moved from Old to New, and Message says why ("commit: <subject>", "merge <branch>: Fast-forward", "checkout: moving from a to b", ...).
func ReflogHEAD ¶
func ReflogHEAD(cwd string) []ReflogEntry
ReflogHEAD returns the HEAD reflog at cwd, oldest first -- the repo's local record of every commit, merge, and checkout that moved HEAD. Worktrees keep their own HEAD log under their gitdir, so a worktree cwd reads that worktree's history. nil when the repo or its log cannot be read (a fresh clone, a pruned log): absent history is not evidence of anything.