git

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package git attributes workspace changes relative to an in-memory-owned baseline using fixed read-only Git commands.

Index

Constants

View Source
const (
	// DefaultDiffBytes caps one captured commit-diff body.
	DefaultDiffBytes int64 = 256 << 10
	// DefaultDiffTimeout bounds one commit-diff capture.
	DefaultDiffTimeout = 5 * time.Minute
	// HeadCaptureTimeout bounds the best-effort HEAD resolve.
	HeadCaptureTimeout = time.Second
)

The commit-capture bounds are the reference's own: a 256 KiB diff body and a five-minute Git budget, with a one-second budget for the best-effort baseline resolve at Goal creation.

Variables

View Source
var (
	// ErrNotRepository means the workspace is not inside a Git work tree.
	ErrNotRepository = errors.New("coding git changes: workspace is not a repository")
	// ErrSnapshotExpired means a snapshot is stale, consumed, foreign, or forged.
	ErrSnapshotExpired = errors.New("coding git changes: snapshot expired")
	// ErrLimit means a bounded scan, copy, command, or diff budget was exceeded.
	ErrLimit = errors.New("coding git changes: resource limit exceeded")
	// ErrGit means a fixed read-only Git command failed.
	ErrGit = errors.New("coding git changes: git command failed")
	// ErrClosed means an Inspector was used after Close.
	ErrClosed = errors.New("coding git changes: inspector closed")
)

Functions

This section is empty.

Types

type Changes added in v0.1.9

type Changes struct {
	Diff         string
	Truncated    bool
	ChangedFiles []string
}

Changes is one captured commit diff: the unified diff from a baseline commit to the current worktree, whether the body hit its byte bound, and the complete changed-path list including untracked files.

type Config

type Config struct {
	GitPath  string
	TempRoot string
	Limits   Limits
}

Config identifies the fixed Git executable and Inspector-owned temp root.

type Inspector

type Inspector struct {
	// contains filtered or unexported fields
}

Inspector owns single-use content baselines for one Workspace.

func New

func New(
	ws workspace.Workspace,
	tree *workspace.Tree,
	policy execution.Policy,
	executor *execution.Executor,
	config Config,
) (*Inspector, error)

New constructs a read-only Git change Inspector.

func (*Inspector) Capture

func (i *Inspector) Capture(ctx context.Context) (changes.Snapshot, error)

Capture records the current tracked and non-ignored worktree content.

func (*Inspector) Changes

func (i *Inspector) Changes(
	ctx context.Context,
	snapshot changes.Snapshot,
) (_ changes.Report, returnErr error)

Changes consumes a Snapshot and reports worktree changes since Capture.

func (*Inspector) Close

func (i *Inspector) Close() error

Close removes every unconsumed baseline and closes the owned temp handle.

func (*Inspector) CommitChanges added in v0.1.9

func (i *Inspector) CommitChanges(
	ctx context.Context,
	base string,
	bytes int64,
	timeout time.Duration,
) (Changes, error)

CommitChanges captures the diff from base to the current worktree plus the complete changed-path list, tracked and untracked alike. The body is bounded by bytes; the path list is read from its own bounded command, so a truncated body never shortens it. Every failure is reported so a caller can render the reference's own sentinel instead of failing its decision.

func (*Inspector) ExcludeLocal

func (i *Inspector) ExcludeLocal(ctx context.Context, name string) error

ExcludeLocal adds an anchored path to the repository's local info/exclude. It never modifies the shared .gitignore file.

func (*Inspector) Head added in v0.1.9

func (i *Inspector) Head(ctx context.Context, timeout time.Duration) (string, error)

Head resolves the repository's current HEAD commit. It reports ErrNotRepository outside a worktree and ErrGit when Git cannot resolve a commit, so a caller that only wants a best-effort baseline can ignore both.

func (*Inspector) ListWorkspaceFiles

func (i *Inspector) ListWorkspaceFiles(ctx context.Context) ([]string, bool, error)

ListWorkspaceFiles returns tracked and non-ignored untracked repository paths in stable order. repository is false only outside a Git worktree.

func (*Inspector) Status

Status returns current repository truth without consuming an interaction baseline or mutating Git state.

func (*Inspector) Tracked

func (i *Inspector) Tracked(ctx context.Context, name string) (bool, bool, error)

Tracked reports whether name is tracked and whether the Workspace is a Git repository. It is the narrow guard used for machine-local project files.

type Limits

type Limits struct {
	Files         int
	HashBytes     int64
	CopyBytes     int64
	DiffFileBytes int64
	GitBytes      int64
	DiffBytes     int64
	GitTimeout    time.Duration
	InspectTime   time.Duration
}

Limits bounds repository discovery, hashing, baseline copies, and output.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns conservative P0 Git inspection budgets.

Jump to

Keyboard shortcuts

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