gitutil

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: 0BSD Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BasePath

func BasePath(gitDir string) string

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 EnsureDir

func EnsureDir(path string) error

EnsureDir creates the directory for path if missing.

func GitDir

func GitDir(root string) (string, error)

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

func HooksDir(root string) (string, error)

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

func PathIgnored(root, rel string) bool

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

func Root(dir string) (string, error)

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.

func Stage

func Stage(root, rel string) error

Stage adds a repo-relative path to the index by invoking the git binary. Staging only happens from within the pre-commit hook (i.e. during a git invocation), so the git binary is guaranteed to be present here; using it sidesteps go-git's config-extension validation.

func StorePath

func StorePath(root string) string

StorePath is the canonical location of the encrypted store.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL