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
- Variables
- type AdoptOptions
- type CommitSummary
- type ContentDigest
- type LocalWorktree
- type Manager
- func (m *Manager) Adopt(ctx context.Context, opts AdoptOptions) (*Workspace, error)
- func (m *Manager) ChangedFilesByPath(ctx context.Context, path, baseSHA string) ([]string, error)
- func (m *Manager) ChangedFilesWorkspace(ctx context.Context, ws *Workspace) ([]string, error)
- func (m *Manager) CheckMerge(ctx context.Context, path, baseOID, headOID string) (MergeCheck, error)
- func (m *Manager) CheckMergeWorkspace(ctx context.Context, ws *Workspace, baseOID, headOID string) (MergeCheck, error)
- func (m *Manager) Clone(ctx context.Context, remote, name string) error
- func (m *Manager) Create(ctx context.Context, mirrorName, baseRef, candidateRef, name string) (*Workspace, error)
- func (m *Manager) Diff(ctx context.Context, name string) (string, error)
- func (m *Manager) DiffByPath(ctx context.Context, path, baseSHA string) (string, error)
- func (m *Manager) DiffWorkspace(ctx context.Context, ws *Workspace) (string, error)
- func (m *Manager) Fetch(ctx context.Context, name string) error
- func (m *Manager) Get(name string) (*Workspace, bool)
- func (m *Manager) HasUntrackedByPath(ctx context.Context, path string) (bool, error)
- func (m *Manager) HasUntrackedWorkspace(ctx context.Context, ws *Workspace) (bool, error)
- func (m *Manager) List() []*Workspace
- func (m *Manager) MergeBase(ctx context.Context, name string) (string, error)
- func (m *Manager) Remove(ctx context.Context, path string, force bool) error
- func (m *Manager) Resolve(ctx context.Context, mirrorName, ref string) (string, error)
- func (m *Manager) SnapshotByPath(ctx context.Context, path, baseSHA, mergeBase string) (Snapshot, error)
- func (m *Manager) Status(ctx context.Context, name string) (Status, error)
- func (m *Manager) StatusByPath(ctx context.Context, path string) (Status, error)
- func (m *Manager) StatusWorkspace(ctx context.Context, ws *Workspace) (Status, error)
- func (m *Manager) UntrackedFilesByPath(ctx context.Context, path string) ([]UntrackedFileSnapshot, error)
- func (m *Manager) ValidateWorkspace(ctx context.Context, ws *Workspace) error
- func (m *Manager) ValidateWorkspacePath(path string) error
- type MergeCheck
- type Ownership
- type Runner
- type Snapshot
- type SnapshotGap
- type Status
- type SubmoduleIdentity
- type UntrackedFileSnapshot
- type UntrackedResource
- type Workspace
Constants ¶
const (
// WorkspaceSnapshotVersion identifies the composite candidate identity contract.
WorkspaceSnapshotVersion = "workspace-snapshot.v1"
)
Variables ¶
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") ErrMirrorInvalid = errors.New("existing mirror path is not a valid bare repository") 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") ErrPathChanged = errors.New("workspace path identity changed") )
Functions ¶
This section is empty.
Types ¶
type AdoptOptions ¶ added in v0.10.0
AdoptOptions identifies an existing worktree without granting ownership of its files or refs.
type CommitSummary ¶ added in v0.10.0
CommitSummary is one bounded commit header between base and HEAD.
type ContentDigest ¶ added in v0.10.0
ContentDigest identifies bounded content without embedding it.
type LocalWorktree ¶ added in v0.19.0
LocalWorktree is a read-only inspection of a Git worktree. It deliberately contains no ownership or workflow identity; callers may use it for routing without adopting the path or changing refs.
func InspectPath ¶ added in v0.19.0
InspectPath reads the current branch, HEAD, and configured remotes from a local worktree. It does not fetch, write refs, invoke hooks, or modify the worktree. A nil runner uses the safe default Git runner.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages Git mirrors and detached worktrees under a single root.
func NewManager ¶
NewManager creates a manager and its root when necessary. A nil runner uses the default git runner.
func OpenManager ¶ added in v0.10.0
OpenManager opens an existing manager root without creating filesystem state. Use it for read-only workspace inspection paths.
func (*Manager) Adopt ¶ added in v0.10.0
Adopt inspects an existing worktree without fetching, changing refs, or taking ownership of the path. The returned administrative identities are revalidated by later workspace operations.
func (*Manager) ChangedFilesByPath ¶
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) ChangedFilesWorkspace ¶ added in v0.10.0
ChangedFilesWorkspace revalidates workspace authority before listing files.
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) CheckMergeWorkspace ¶ added in v0.10.0
func (m *Manager) CheckMergeWorkspace(ctx context.Context, ws *Workspace, baseOID, headOID string) (MergeCheck, error)
CheckMergeWorkspace revalidates workspace authority before comparing refs.
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 ¶
Diff returns the current worktree diff against its recorded base SHA, including staged and unstaged changes without invoking external diff tools.
func (*Manager) DiffByPath ¶
DiffByPath returns the diff for a workspace path against the supplied base SHA, including staged and unstaged changes.
func (*Manager) DiffWorkspace ¶ added in v0.10.0
DiffWorkspace revalidates workspace authority before reading its diff.
func (*Manager) HasUntrackedByPath ¶
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) HasUntrackedWorkspace ¶ added in v0.10.0
HasUntrackedWorkspace revalidates workspace authority before reading files.
func (*Manager) MergeBase ¶
MergeBase recomputes the merge base for the workspace base and candidate.
func (*Manager) Remove ¶
Remove removes the worktree at path. It refuses paths outside the managed root, unrecorded paths, and dirty workspaces unless force is true.
func (*Manager) SnapshotByPath ¶ added in v0.10.0
func (m *Manager) SnapshotByPath(ctx context.Context, path, baseSHA, mergeBase string) (Snapshot, error)
SnapshotByPath derives a bounded, no-hook identity for a managed worktree.
func (*Manager) StatusByPath ¶
StatusByPath reports the dirty state of any workspace path inside the managed root without requiring the workspace to be loaded in memory.
func (*Manager) StatusWorkspace ¶ added in v0.10.0
StatusWorkspace revalidates workspace authority before reading status.
func (*Manager) UntrackedFilesByPath ¶ added in v0.10.0
func (m *Manager) UntrackedFilesByPath(ctx context.Context, path string) ([]UntrackedFileSnapshot, error)
UntrackedFilesByPath returns a bounded, deterministic snapshot of untracked, non-ignored files. Git performs path discovery and content hashing.
func (*Manager) ValidateWorkspace ¶ added in v0.10.0
ValidateWorkspace revalidates the authority recorded for a persisted workspace before it is used.
func (*Manager) ValidateWorkspacePath ¶ added in v0.10.0
ValidateWorkspacePath verifies that path exists within the managed worktree subtree without invoking Git or changing filesystem state. Mirrors and other manager state are deliberately excluded from executable capabilities.
type MergeCheck ¶ added in v0.5.0
MergeCheck is a non-mutating comparison of two already-fetched revisions.
type Ownership ¶ added in v0.10.0
type Ownership string
Ownership distinguishes worktrees created by GitContribute from external worktrees that it may inspect but never remove.
type Runner ¶
Runner executes an external command.
func DefaultRunner ¶
func DefaultRunner() Runner
DefaultRunner returns a Runner backed by the local git executable.
type Snapshot ¶ added in v0.10.0
type Snapshot struct {
Version string `json:"version"`
Ownership string `json:"ownership"`
BaseSHA string `json:"base_sha,omitempty"`
HeadSHA string `json:"head_sha"`
MergeBase string `json:"merge_base,omitempty"`
Staged ContentDigest `json:"staged"`
Unstaged ContentDigest `json:"unstaged"`
Untracked []UntrackedResource `json:"untracked"`
Submodules []SubmoduleIdentity `json:"submodules"`
ChangedFiles []string `json:"changed_files"`
Commits []CommitSummary `json:"commits"`
CommitTotal int `json:"commit_total"`
CommitsTruncated bool `json:"commits_truncated"`
Complete bool `json:"complete"`
Gaps []SnapshotGap `json:"gaps"`
SHA256 string `json:"sha256"`
}
Snapshot is a deterministic composite identity for a managed worktree.
type SnapshotGap ¶ added in v0.10.0
type SnapshotGap struct {
Code string `json:"code"`
Path string `json:"path,omitempty"`
Reason string `json:"reason"`
}
SnapshotGap explicitly records candidate content that could not be bound.
type SubmoduleIdentity ¶ added in v0.10.0
type SubmoduleIdentity struct {
Path string `json:"path"`
IndexSHA string `json:"index_sha"`
HeadSHA string `json:"head_sha,omitempty"`
Dirty *bool `json:"dirty,omitempty"`
}
SubmoduleIdentity binds the index and checked-out identities of a submodule.
type UntrackedFileSnapshot ¶ added in v0.10.0
UntrackedFileSnapshot identifies exact untracked content without returning file bytes. ObjectID is Git's content hash from hash-object --no-filters.
type UntrackedResource ¶ added in v0.10.0
type UntrackedResource struct {
Path string `json:"path"`
Kind string `json:"kind"`
Mode uint32 `json:"mode"`
SHA256 string `json:"sha256,omitempty"`
Bytes int64 `json:"bytes,omitempty"`
}
UntrackedResource identifies one untracked path and its content when bounded.
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
HasUntracked bool
Ownership Ownership
GitDir string
GitCommonDir string
CreatedAt time.Time
// contains filtered or unexported fields
}
Workspace is a product-owned record for a Git worktree.