Documentation
¶
Overview ¶
Package worktree owns the git worktree mechanics used by the Runtime: name planning, materialization, listing, removal and reset. It never touches SQL, sessions or the Runtime; git is the only content authority it consults.
Index ¶
- Constants
- func RollbackChangeSet(ctx context.Context, root string, changeSet ChangeSet, applied ApplyResult) error
- func Slugify(input string) string
- type ApplyResult
- type ChangeFile
- type ChangeSet
- type Error
- type Info
- type Manager
- func (m *Manager) Add(ctx context.Context, repoRoot string, info Info) error
- func (m *Manager) CaptureChangeSet(ctx context.Context, directory, baseRevision string, patchLimit int) (ChangeSet, error)
- func (m *Manager) DefaultBranch(ctx context.Context, repoRoot string) (string, error)
- func (m *Manager) DirectoryFor(repoRoot, name string) string
- func (m *Manager) List(ctx context.Context, repoRoot string) ([]Info, error)
- func (m *Manager) LockDir(ctx context.Context, directory string) (func(), error)
- func (m *Manager) Plan(ctx context.Context, repoRoot, requested string, detached bool) (Info, error)
- func (m *Manager) Populate(ctx context.Context, info Info) error
- func (m *Manager) Remove(ctx context.Context, repoRoot, directory, branch string) error
- func (m *Manager) RepoRoot(ctx context.Context, dir string) (string, error)
- func (m *Manager) Reset(ctx context.Context, repoRoot, directory string) error
- func (m *Manager) Revision(ctx context.Context, directory string) (string, error)
- func (m *Manager) Root() string
- type Runner
- type UntrackedFile
Constants ¶
const ( CodeNotGit = "not_git" CodeNameGenerationFailed = "name_generation_failed" CodeCreateFailed = "create_failed" CodePopulateFailed = "populate_failed" CodeListFailed = "list_failed" CodeRemoveFailed = "remove_failed" CodeResetFailed = "reset_failed" CodeDefaultBranchFailed = "default_branch_failed" CodeRevisionFailed = "revision_failed" CodeChangeSetFailed = "change_set_failed" CodeApplyFailed = "apply_failed" CodeApplyConflict = "apply_conflict" )
Error codes shared with the ACP/CLI projections.
const DefaultChangeSetPatchBytes = 512 << 10
DefaultChangeSetPatchBytes bounds the patch retained in one immutable change-set snapshot. A truncated patch is still useful for review, but it is never safe to integrate without the complete snapshot.
const DefaultChangeSetUntrackedBytes = 512 << 10
DefaultChangeSetUntrackedBytes bounds the raw content retained for untracked files. Git's patch format already handles tracked binary files.
Variables ¶
This section is empty.
Functions ¶
func RollbackChangeSet ¶
func RollbackChangeSet(ctx context.Context, root string, changeSet ChangeSet, applied ApplyResult) error
RollbackChangeSet reverses one ApplyChangeSet that already ran against root. It is used when a later selection in the same integration request conflicts: the Runtime must not leave a partially applied multi-selection behind. The function re-verifies created untracked bytes before deleting them and never removes a file whose content changed after integration.
Types ¶
type ApplyResult ¶
ApplyResult reports the paths a Runtime-owned integration actually changed.
func ApplyChangeSet ¶
ApplyChangeSet applies one verified change-set snapshot to a repository worktree. It never uses the mutable child worktree: the patch and untracked bytes in the snapshot are the only inputs. The tracked patch is dry-run before mutation; untracked paths are resolved component-by-component with a symlink fence so a snapshot can never redirect a write outside root.
type ChangeFile ¶
type ChangeFile struct {
Path string `json:"path"`
Status string `json:"status"`
OriginalPath string `json:"originalPath,omitempty"`
}
ChangeFile is one tracked path in a change-set snapshot.
type ChangeSet ¶
type ChangeSet struct {
Version int `json:"version"`
BaseRevision string `json:"baseRevision"`
HeadRevision string `json:"headRevision"`
Digest string `json:"digest"`
Files []ChangeFile `json:"files"`
UntrackedFiles []UntrackedFile `json:"untrackedFiles,omitempty"`
Patch string `json:"patch,omitempty"`
PatchTruncated bool `json:"patchTruncated,omitempty"`
UntrackedTruncated bool `json:"untrackedTruncated,omitempty"`
}
ChangeSet is an immutable, bounded snapshot of a managed worktree relative to a recorded base revision. It is a review/integration input, not an artifact and never an authorization source.
type Error ¶
Error is a typed mechanism error carrying a stable machine code so adapters can map it to protocol errors without string matching.
type Info ¶
Info describes one git worktree derived from a repository. An empty Branch means the worktree is detached.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns git worktree mechanics under Root. It is safe for concurrent use as long as callers serialize per repository root (the Runtime does).
func NewManager ¶
NewManager builds a Manager whose worktrees live under root. An empty branchPrefix falls back to "mothx".
func (*Manager) Add ¶
Add materializes the worktree directory without checking out files. The directory exists after a successful Add, so it can be authorized before the (slower) Populate step runs.
func (*Manager) CaptureChangeSet ¶
func (m *Manager) CaptureChangeSet(ctx context.Context, directory, baseRevision string, patchLimit int) (ChangeSet, error)
CaptureChangeSet snapshots tracked changes and bounded untracked content for a managed worktree. directory must live under the Manager root; callers must already have proved the directory is a registered worktree.
func (*Manager) DefaultBranch ¶
DefaultBranch resolves the repository's default branch ref, preferring origin/HEAD and falling back to main/master.
func (*Manager) DirectoryFor ¶
DirectoryFor returns the canonical worktree directory for name under the repository's key directory.
func (*Manager) LockDir ¶
LockDir acquires a cross-process lock for one worktree directory under the manager root. The returned release function is always non-nil on success.
func (*Manager) Plan ¶
func (m *Manager) Plan(ctx context.Context, repoRoot, requested string, detached bool) (Info, error)
Plan generates a unique name/directory/branch for a new worktree. requested is slugified; when empty, the repository basename is used. Conflicts on the directory or branch are retried with a random suffix.
func (*Manager) Remove ¶
Remove deletes a worktree directory and, when non-empty, its branch. It is the caller's responsibility to prove directory belongs to repoRoot's registered worktrees before calling Remove.
func (*Manager) Reset ¶
Reset returns a worktree to the repository's default branch, discarding local changes. It fails rather than silently leaving the tree dirty.
type Runner ¶
type Runner func(ctx context.Context, cwd string, args ...string) (stdout, stderr string, code int, err error)
Runner executes git in cwd and returns stdout, stderr and the exit code. A non-nil error means the process could not be started at all; a non-zero code with a nil error is a normal git failure.
type UntrackedFile ¶
type UntrackedFile struct {
Path string `json:"path"`
Size int64 `json:"size"`
Digest string `json:"digest"`
ContentBase64 string `json:"contentBase64,omitempty"`
ContentTruncated bool `json:"contentTruncated,omitempty"`
Binary bool `json:"binary,omitempty"`
}
UntrackedFile carries bounded content for a file git does not track. The content is base64 encoded so arbitrary bytes survive JSON persistence.