workspace

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package workspace manages Git mirrors and detached worktrees used to inspect candidate contributions.

Paths are contained beneath one managed root, repository hooks and optional helpers are disabled, command output is bounded, and dirty worktrees require explicit force before removal. Creating a workspace invokes git but never executes repository-controlled code.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExists         = errors.New("workspace already exists")
	ErrNotFound       = errors.New("workspace not found")
	ErrNotManaged     = errors.New("path is not a managed workspace")
	ErrDirty          = errors.New("dirty workspace cannot be removed without force")
	ErrMirrorExists   = errors.New("mirror already exists")
	ErrMirrorNotFound = errors.New("mirror not found")
	ErrInvalidName    = errors.New("invalid name")
	ErrInvalidRemote  = errors.New("invalid remote")
	ErrRemoteMismatch = errors.New("existing mirror remote does not match requested remote")
	ErrOutputLimit    = errors.New("git output exceeds limit")
)

Functions

This section is empty.

Types

type Manager

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

Manager manages Git mirrors and detached worktrees under a single root.

func NewManager

func NewManager(root string, runner Runner) (*Manager, error)

NewManager creates a manager. A nil runner uses the default git runner.

func (*Manager) ChangedFilesByPath

func (m *Manager) ChangedFilesByPath(ctx context.Context, path, baseSHA string) ([]string, error)

ChangedFilesByPath returns raw Git paths changed from the supplied base. Git owns rename, deletion, and quoted-path handling; NUL delimiters preserve paths containing whitespace or other special characters.

func (*Manager) CheckMerge added in v0.5.0

func (m *Manager) CheckMerge(ctx context.Context, path, baseOID, headOID string) (MergeCheck, error)

CheckMerge compares already-fetched revisions without fetching or changing refs, the index, or a worktree.

func (*Manager) Clone

func (m *Manager) Clone(ctx context.Context, remote, name string) error

Clone clones remote into a bare mirror under the managed root.

func (*Manager) Create

func (m *Manager) Create(ctx context.Context, mirrorName, baseRef, candidateRef, name string) (*Workspace, error)

Create creates a detached worktree from mirrorName at candidateRef against baseRef.

func (*Manager) Diff

func (m *Manager) Diff(ctx context.Context, name string) (string, error)

Diff returns the current worktree diff against its recorded base SHA, including staged and unstaged changes without invoking external diff tools.

func (*Manager) DiffByPath

func (m *Manager) DiffByPath(ctx context.Context, path, baseSHA string) (string, error)

DiffByPath returns the diff for a workspace path against the supplied base SHA, including staged and unstaged changes.

func (*Manager) Fetch

func (m *Manager) Fetch(ctx context.Context, name string) error

Fetch updates an existing mirror.

func (*Manager) Get

func (m *Manager) Get(name string) (*Workspace, bool)

Get returns a workspace by name.

func (*Manager) HasUntrackedByPath

func (m *Manager) HasUntrackedByPath(ctx context.Context, path string) (bool, error)

HasUntrackedByPath reports whether a managed workspace contains untracked, non-ignored files. Callers preparing a complete diff must handle these explicitly because git diff does not include them.

func (*Manager) List

func (m *Manager) List() []*Workspace

List returns all workspaces sorted by name.

func (*Manager) MergeBase

func (m *Manager) MergeBase(ctx context.Context, name string) (string, error)

MergeBase recomputes the merge base for the workspace base and candidate.

func (*Manager) Remove

func (m *Manager) Remove(ctx context.Context, path string, force bool) error

Remove removes the worktree at path. It refuses paths outside the managed root, unrecorded paths, and dirty workspaces unless force is true.

func (*Manager) Resolve

func (m *Manager) Resolve(ctx context.Context, mirrorName, ref string) (string, error)

Resolve resolves a ref to a full SHA in the named mirror.

func (*Manager) Status

func (m *Manager) Status(ctx context.Context, name string) (Status, error)

Status reports whether the workspace has uncommitted changes.

func (*Manager) StatusByPath

func (m *Manager) StatusByPath(ctx context.Context, path string) (Status, error)

StatusByPath reports the dirty state of any workspace path inside the managed root without requiring the workspace to be loaded in memory.

type MergeCheck added in v0.5.0

type MergeCheck struct {
	MergeBase  string
	Conflicted bool
	Summary    string
}

MergeCheck is a non-mutating comparison of two already-fetched revisions.

type Runner

type Runner interface {
	Run(ctx context.Context, name string, args ...string) (string, error)
}

Runner executes an external command.

func DefaultRunner

func DefaultRunner() Runner

DefaultRunner returns a Runner backed by the local git executable.

type Status

type Status struct {
	Dirty bool
}

Status reports the dirty state of a workspace.

type Workspace

type Workspace struct {
	Name            string
	InvestigationID string
	RepoOwner       string
	RepoName        string
	Path            string
	Remote          string
	BaseSHA         string
	CandidateSHA    string
	MergeBase       string
	Dirty           bool
	CreatedAt       time.Time
	// contains filtered or unexported fields
}

Workspace is a product-owned record for a managed Git worktree.

Jump to

Keyboard shortcuts

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