Documentation
¶
Overview ¶
Package gitutil provides git repository helpers used to locate the store ($GIT_ROOT/.gitward.json) and the private base snapshot (.git/gitward/base.json), stage files, and test ignore rules.
Repository discovery is done by walking the filesystem for the .git entry rather than via go-git's PlainOpen. This deliberately avoids parsing the repository config, so repos that declare extensions go-git does not understand (notably extensions.worktreeConfig, set by `git worktree` and `git maintenance`) still work.
Index ¶
- func BasePath(gitDir string) string
- func EnsureDir(path string) error
- func GitDir(root string) (string, error)
- func HooksDir(root string) (string, error)
- func PathIgnored(root, rel string) bool
- func Root(dir string) (string, error)
- func Stage(root, rel string) error
- func StorePath(root string) string
- type IgnoreMatcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasePath ¶
BasePath is the canonical location of the private plaintext base snapshot, hidden inside the git dir so it is neither committed nor visible in the work tree. In a linked worktree this is the per-worktree git dir, giving each worktree its own base snapshot (matching its own checkout).
func GitDir ¶
GitDir resolves the absolute git directory for the worktree at root. It handles the common cases: a real .git directory; and a ".git" file containing "gitdir: <path>" (linked worktrees and submodules), where the resolved path is the per-worktree git dir (e.g. .git/worktrees/<name>).
func HooksDir ¶
HooksDir returns the absolute directory git runs hooks from for the worktree at root. It honors core.hooksPath (used by husky and similar tooling) by asking git directly (`git rev-parse --git-path hooks`), which also resolves correctly inside linked worktrees. If git is unavailable it falls back to the conventional <gitDir>/hooks.
func PathIgnored ¶
PathIgnored reports whether the repo-relative path is ignored by git, evaluating .gitignore patterns via go-git's matcher. It reads patterns directly off the filesystem rooted at root, without opening the repository, so it is unaffected by unsupported config extensions.
Reading the patterns recursively walks the worktree, so callers that test many paths against the same root should build an IgnoreMatcher once with NewIgnoreMatcher and reuse it instead of calling PathIgnored in a loop.
func Root ¶
Root returns the absolute worktree root for the repo containing dir (or the cwd when dir is empty) by walking up until a .git entry (directory or file) is found.
Types ¶
type IgnoreMatcher ¶ added in v0.1.1
type IgnoreMatcher struct {
// contains filtered or unexported fields
}
IgnoreMatcher evaluates .gitignore rules for a repo without re-reading the worktree on every check. Build it once with NewIgnoreMatcher and call Match for each candidate path.
func NewIgnoreMatcher ¶ added in v0.1.1
func NewIgnoreMatcher(root string) (*IgnoreMatcher, error)
NewIgnoreMatcher reads all .gitignore patterns under root once (the expensive step) and returns a reusable matcher.
func (*IgnoreMatcher) Match ¶ added in v0.1.1
func (im *IgnoreMatcher) Match(rel string) bool
Match reports whether the repo-relative path is ignored.