Documentation
¶
Overview ¶
Package repo gives plugins a read-only, deterministic view of one checkout.
Only files tracked by git are visible. That matters twice: untracked files (a real .env, local build output) are never read, and two checkouts of the same commit always present the same file list.
Index ¶
- func BranchRef(dir, branch string) (string, error)
- func Dir(rel string) string
- func Git(dir string, args ...string) *exec.Cmd
- func GitContext(ctx context.Context, dir string, args ...string) *exec.Cmd
- func InsideWorkTree(dir string) (bool, error)
- func Join(elem ...string) (string, bool)
- func MemoFile[T any](r *Repo, file string, src []byte, read func() (T, error)) (T, error)
- type Repo
- func (r *Repo) Close() error
- func (r *Repo) Dirty() (bool, error)
- func (r *Repo) Has(rel string) bool
- func (r *Repo) Match(match func(base string) bool) []string
- func (r *Repo) Memo(key any, compute func() any) any
- func (r *Repo) Read(rel string) ([]byte, error)
- func (r *Repo) Restrict(keep []string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BranchRef ¶
BranchRef names branch unambiguously for git: refs/heads/<branch>, or refs/remotes/origin/<branch> when there is no local head (a CLI scan of a clone). A bare name would let a tag of the same name win.
func Git ¶
Git runs git in dir. The scanned repository is untrusted and so is its .git/config, which can name programs for git to run: the overrides turn off the ones the read-only commands used here could reach. A scan never fetches: a partial clone would fetch a missing object from its promisor remote, and an ext:: or ssh remote is a command. Each protocol is turned off by name, because protocol.<name>.allow in the repository's config would win over protocol.allow; GIT_NO_LAZY_FETCH (git 2.45) stops the fetch itself.
func GitContext ¶
GitContext is Git, killed when ctx is done.
func InsideWorkTree ¶
InsideWorkTree reports whether dir is in a git work tree (false outside git; an error for a bare repository or a git directory).
Types ¶
type Repo ¶
type Repo struct {
Root string // absolute path of the checkout
Files []string // repo-relative, forward slashes, sorted
// contains filtered or unexported fields
}
func Open ¶
Open lists tracked files with `git ls-files`, also when root is a folder inside a work tree (paths are then relative to root). Outside git it falls back to a directory walk (used by tests on plain folders). A bare repository or a git directory has no files as they are: use OpenCommit.
func OpenCommit ¶
OpenCommit gives the view of one commit without checking it out: the tracked files of its tree from `git ls-tree`, their content from git's object store. The working tree is never read, so a scan of old commits can run beside work in progress. Symlinks and submodules are skipped as in Open. Call Close when done.
func (*Repo) Dirty ¶
Dirty reports uncommitted changes, staged or not, to tracked files under Root: the working tree Read sees then differs from HEAD. A commit view or a folder outside git is never dirty. Submodules are ignored, as in Open.
func (*Repo) Memo ¶
Memo returns the value stored under key, computing and storing it on the first call. Readers shared by plugins (jsread, pyread) cache per scan this way. compute runs outside the lock; a racing duplicate is discarded, so every caller sees the first stored value.