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 Slugify(input string) string
- type Error
- type Info
- type Manager
- func (m *Manager) Add(ctx context.Context, repoRoot string, info Info) 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) Root() string
- type Runner
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" )
Error codes shared with the ACP/CLI projections.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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) 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.
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.