sandbox

package
v1.234.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sandbox runs repository checks against an isolated Git index and checkout. It never writes the source index, creates branches, registers worktrees, or fetches refs.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOptions indicates an unsupported sandbox scope or option.
	ErrInvalidOptions = errors.New("invalid Git sandbox options")
	// ErrClosed indicates a sandbox that has already finished or been removed.
	ErrClosed = errors.New("git sandbox is closed or finished")
	// ErrUnsafePath indicates a path outside the checkout or inside Git metadata.
	ErrUnsafePath = errors.New("unsafe repository path")
	// ErrUnmergedIndex prevents checking an index containing unresolved conflicts.
	ErrUnmergedIndex = errors.New("resolve unmerged index entries before running repository checks")
	// ErrFixConflict means a fix could not be safely applied to the working file.
	ErrFixConflict = errors.New("formatter fix conflict")
	// ErrSupportFile indicates an invalid support-file copy.
	ErrSupportFile = errors.New("invalid sandbox support file")
	// ErrFileType indicates a file state that cannot be captured or written.
	ErrFileType = errors.New("unsupported file type")
	// ErrMissingBase identifies an unavailable comparison ref.
	ErrMissingBase = errors.New("comparison base unavailable")
)

Functions

func CleanEnvironment

func CleanEnvironment(env []string) []string

CleanEnvironment removes the caller's repository/index overrides before invoking Git in a different checkout. Source reads must retain these overrides, especially GIT_INDEX_FILE supplied by git commit --only.

Types

type Options

type Options struct {
	Directory  string
	Scope      string
	BaseRef    string
	Env        []string
	Runner     atmosgit.Runner
	Stderr     io.Writer
	OnProgress func(Progress)
}

Options controls selection and the checkout contents. Staged uses the caller's index; pr and all overlay tracked working-tree contents. No refs are fetched.

type Progress

type Progress struct {
	Phase            string
	Completed, Total int
}

Progress describes checkout preparation without tying Git operations to a renderer.

type Sandbox

type Sandbox struct {
	Root  string
	Path  string
	Scope string
	Base  string
	Files []string
	Added []string
	// contains filtered or unexported fields
}

Sandbox owns a temporary repository. Call Close even if checks or reconciliation fail. Files and Added contain repo-relative paths; Base is a resolved commit.

func Open

func Open(ctx context.Context, opts Options) (_ *Sandbox, err error)

Open captures the index and selected files without modifying the source repository.

func (*Sandbox) Close

func (s *Sandbox) Close() error

Close deletes only this sandbox's private checkout and Git metadata.

func (*Sandbox) Copy

func (s *Sandbox) Copy(paths []string) error

Copy adds an existing, untracked support file such as a prebuilt linter. Its timestamp and permissions are preserved. It is never reconciled into the source.

func (*Sandbox) Finish

func (s *Sandbox) Finish(apply bool) (bool, error)

Finish reports differences, optionally applying them as unstaged edits. It never writes the live index. Cancellation prevents reconciliation; conflicts preserve the original file and produce a recoverable patch. It may run only once.

func (*Sandbox) Track

func (s *Sandbox) Track(paths []string) error

Track adds formatter side effects (e.g. go.sum) to reconciliation. Call before running modifying checks. Paths must be repository-relative, without symlink parents.

Jump to

Keyboard shortcuts

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