repo

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 17 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BranchRef

func BranchRef(dir, branch string) (string, error)

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 Dir

func Dir(rel string) string

Dir returns the repo-relative directory of a file, "." for the root.

func Git

func Git(dir string, args ...string) *exec.Cmd

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

func GitContext(ctx context.Context, dir string, args ...string) *exec.Cmd

GitContext is Git, killed when ctx is done.

func InsideWorkTree

func InsideWorkTree(dir string) (bool, error)

InsideWorkTree reports whether dir is in a git work tree (false outside git; an error for a bare repository or a git directory).

func Join

func Join(elem ...string) (string, bool)

Join joins repo-relative path elements and cleans the result. It returns ok=false when the result escapes the repository (starts with "..").

func MemoFile

func MemoFile[T any](r *Repo, file string, src []byte, read func() (T, error)) (T, error)

MemoFile caches read for the scan, by file path and content, since several plugins read every file. T keeps the readers' results apart.

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

func Open(root string) (*Repo, error)

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

func OpenCommit(root, rev string) (*Repo, string, error)

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) Close

func (r *Repo) Close() error

Close stops the object reader of a commit view; a no-op for a checkout.

func (*Repo) Dirty

func (r *Repo) Dirty() (bool, error)

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) Has

func (r *Repo) Has(rel string) bool

Has reports whether a tracked file exists at the repo-relative path.

func (*Repo) Match

func (r *Repo) Match(match func(base string) bool) []string

Match returns tracked files whose base name satisfies match, sorted.

func (*Repo) Memo

func (r *Repo) Memo(key any, compute func() any) any

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.

func (*Repo) Read

func (r *Repo) Read(rel string) ([]byte, error)

Read returns a tracked file's content; a file over max_file_bytes is an error, so a crafted repo cannot exhaust memory.

func (*Repo) Restrict

func (r *Repo) Restrict(keep []string)

Restrict narrows the visible files to keep (which must be a subset of the current files, as produced by the scan's exclusion plan).

Directories

Path Synopsis
Package repotest builds repo views for tests.
Package repotest builds repo views for tests.

Jump to

Keyboard shortcuts

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