Documentation
¶
Overview ¶
Package git provides bounded, read-only repository inspection.
Index ¶
- Constants
- Variables
- func ChangedFiles(ctx context.Context, root, base, head string) ([]string, error)
- func CommonDir(ctx context.Context, root string) (string, error)
- func DefaultBranch(ctx context.Context, root string) string
- func ExplainShallow(ctx context.Context, root string, err error) error
- func Files(ctx context.Context, root, ref string) ([]string, error)
- func HasIdentity(ctx context.Context, root, identity string) bool
- func Identity(ctx context.Context, root string) string
- func IsAncestor(ctx context.Context, root, base, head string) (bool, error)
- func LocalBranches(ctx context.Context, root string) ([]string, error)
- func MergeBase(ctx context.Context, root, a, b string) (string, error)
- func PrivateCommand(ctx context.Context, root string, args ...string) *exec.Cmd
- func ReadBlob(ctx context.Context, root, oid string) ([]byte, error)
- func ReadFile(ctx context.Context, root, ref, path string) ([]byte, error)
- func Resolve(ctx context.Context, root, ref string) (string, error)
- func RunPrivate(ctx context.Context, root string, args ...string) (string, error)
- func ShallowBoundary(ctx context.Context, root string) ([]string, error)
- func TopLevel(ctx context.Context, dir string) (string, error)
- func Tree(ctx context.Context, root, ref string) (string, error)
- func WorkingFiles(ctx context.Context, root string) ([]string, error)
- func WorktreeBranches(ctx context.Context, root string) ([]string, error)
- type BlobReader
- type Info
- type ShallowHistoryError
- type TreeEntry
- type WorktreeStatus
Constants ¶
const MaxFileBytes = 4 << 20
MaxFileBytes bounds a single file or small command output.
const NullPath = "/dev/null"
command binds every operation to the explicit root and object database. NullPath is the empty config/attributes path for Git. os.DevNull is "NUL" on Windows, which Git for Windows rejects; it maps "/dev/null" itself.
Variables ¶
var ErrBlobTooLarge = errors.New("Git blob exceeds read limit")
ErrBlobTooLarge reports a blob above the caller's read limit.
Functions ¶
func ChangedFiles ¶
ChangedFiles lists paths that differ between base and head. head may be WORKTREE, which includes staged, unstaged and untracked non-ignored files. Renames are reported as both the old and the new path.
func DefaultBranch ¶
DefaultBranch guesses the integration base: the local counterpart of origin/HEAD, then main, master or trunk. It returns "" when none exists.
func ExplainShallow ¶
ExplainShallow turns a history error from a shallow clone into a ShallowHistoryError that says how to fix it; other errors pass unchanged.
func HasIdentity ¶
HasIdentity reports whether the repository at root holds every root commit of identity (as Identity formats it) as a parentless commit. Unlike comparing Identity, it does not depend on the checked-out branch: an orphan branch or merged unrelated history keeps the repository's identity.
func Identity ¶
Identity returns a location-independent repository identity derived from its root commits, shared by every clone and worktree. It returns "" when the directory is not a Git repository with history.
func IsAncestor ¶
IsAncestor checks history without changing refs or relying on mutable branch names.
func LocalBranches ¶
LocalBranches lists local branch names in ref order.
func PrivateCommand ¶
PrivateCommand prepares Git for building a private candidate repository. Unlike the read-only profile it may write objects, refs and a worktree, so it also disables hooks, attributes, signing and the caller's identity, and pins commit dates so the candidate commit is reproducible. It is used to read from the source repository and write only the private one.
func RunPrivate ¶
RunPrivate runs PrivateCommand and returns its trimmed output. On failure the returned text holds only bounded Git diagnostics.
func ShallowBoundary ¶
ShallowBoundary returns the commits at which a shallow clone's history is cut, or nil for a complete repository. A private repository holding objects copied from a shallow clone needs the same boundary, or Git walks into parents that were never copied.
func WorkingFiles ¶
WorkingFiles lists tracked and untracked, non-ignored files below root, relative to root. It respects .gitignore and Git exclude settings.
Types ¶
type BlobReader ¶
type BlobReader struct {
// contains filtered or unexported fields
}
BlobReader streams many objects through one `git cat-file --batch` process instead of spawning a subprocess per file.
func OpenBlobReader ¶
func OpenBlobReader(ctx context.Context, root string) (*BlobReader, error)
OpenBlobReader starts a batch reader bound to ctx; Close releases it.
type Info ¶
type ShallowHistoryError ¶
type ShallowHistoryError struct{ Err error }
ShallowHistoryError reports that a shallow clone lacks the history Git needs to combine commits. Radar never fetches, so the user must.
func (*ShallowHistoryError) Error ¶
func (e *ShallowHistoryError) Error() string
func (*ShallowHistoryError) Unwrap ¶
func (e *ShallowHistoryError) Unwrap() error
type WorktreeStatus ¶
type WorktreeStatus struct {
Path string `json:"path"`
Branch string `json:"branch,omitempty"`
Commit string `json:"commit"`
Detached bool `json:"detached"`
Staged []string `json:"staged"`
Unstaged []string `json:"unstaged"`
Untracked []string `json:"untracked"`
InspectionError string `json:"inspection_error,omitempty"`
CommitIncluded bool `json:"commit_included"`
UncommittedIncluded bool `json:"uncommitted_included"`
}
WorktreeStatus is a read-only boundary observation. Dirty files never enter committed integration candidates; ignored files are not enumerated.
func InspectWorktrees ¶
func InspectWorktrees(ctx context.Context, root string) ([]WorktreeStatus, error)