Documentation
¶
Overview ¶
Package workspace prepares the directory an agent works in: a git worktree on branch otag/<task> outside the repository (mode "worktree"), or the project itself ("same"). Nothing is written into the project's working tree; `git worktree add` only adds metadata under the repository's .git directory.
Index ¶
- Constants
- func BranchExists(ctx context.Context, projectPath, branch string) bool
- func BranchFor(taskID string) string
- func Changes(ctx context.Context, dir string) (string, error)
- func CommitsSince(ctx context.Context, dir, base string) (int, error)
- func DefaultBranch(ctx context.Context, projectPath string) string
- func DeleteBranch(ctx context.Context, projectPath, branch, target string) (int, error)
- func Head(ctx context.Context, dir string) (sha string, dirty bool, err error)
- func MergeBase(ctx context.Context, projectPath, branch string) string
- func Remove(ctx context.Context, s RemoveSpec) (string, error)
- func Uncommitted(ctx context.Context, s RemoveSpec) (string, error)
- func Unmerged(ctx context.Context, projectPath, branch, target string) (int, error)
- type DirtyError
- type RemoveSpec
- type Result
- type Spec
Constants ¶
const ( Worktree = "worktree" Same = "same" )
Modes.
const ( Removed = "removed" Gone = "gone" // deleted before (pruned from git's list), or an empty directory left behind // Replaced: the path is now another linked worktree of the repository, on another // branch. It is not the task's any more and is left alone. Replaced = "replaced" )
Outcomes of Remove.
Variables ¶
This section is empty.
Functions ¶
func BranchExists ¶
BranchExists reports whether the local branch exists in the repository at projectPath.
func Changes ¶
Changes returns the uncommitted changes of the work tree at dir (`git status --porcelain`; "" when clean).
func CommitsSince ¶
CommitsSince counts commits on HEAD of dir that are not in base.
func DefaultBranch ¶
DefaultBranch returns the branch work is merged into: the local branch origin/HEAD names, else the branch the project checkout is on ("" when detached).
func DeleteBranch ¶
DeleteBranch deletes branch if target contains all of its commits (the semantics of `git branch -d`, against target instead of the checkout's HEAD). It returns the number of unmerged commits; with any, nothing is deleted. Both commits are read once: the deletion is one ref transaction that verifies target and deletes branch only if both still point at them, so a branch or target that moved meanwhile keeps the branch. A symbolic branch ref (it would delete what it points at) and a branch checked out in a worktree (the main checkout included) are refused.
func Head ¶
Head returns the commit at HEAD of dir and whether the work tree has uncommitted changes.
func MergeBase ¶
MergeBase returns the merge base of branch and the project's HEAD: the best guess of a task's base when none was recorded.
func Remove ¶
func Remove(ctx context.Context, s RemoveSpec) (string, error)
Remove removes the worktree of a task (`git worktree remove`) and returns what it found: Removed, Gone or Replaced. Uncommitted changes are a *DirtyError unless Force, which discards them. A path that no longer exists is only pruned from git's list; an empty directory (what an interrupted removal leaves) is deleted first, as it has nothing to lose. A path outside Root, the main checkout, anything that is not a linked worktree of the repository, and a worktree with a detached HEAD are refused. The branch stays.
func Uncommitted ¶
func Uncommitted(ctx context.Context, s RemoveSpec) (string, error)
Uncommitted returns the uncommitted changes of the task worktree s ("" when it is clean, gone or not the task's any more); errors are Remove's refusals.
Types ¶
type DirtyError ¶
DirtyError means a worktree has uncommitted changes (tracked or untracked files).
func (*DirtyError) Error ¶
func (e *DirtyError) Error() string
type RemoveSpec ¶
type RemoveSpec struct {
ProjectPath string
Path string // the recorded worktree path
Branch string // the task's branch: the worktree must still be on it
// Root is otag's worktree root of the project (<data>/worktrees/<project>): Path,
// with symlinks resolved, must be inside it.
Root string
Force bool // discard uncommitted changes
}
RemoveSpec names the worktree of a task that is to be removed.
type Result ¶
type Result struct {
Mode string `json:"mode"`
Path string `json:"path"`
Branch string `json:"branch,omitempty"`
BaseRef string `json:"base_ref,omitempty"`
BaseSHA string `json:"base_sha,omitempty"`
Reused bool `json:"reused"` // an existing worktree of the task was reused
// BranchExisted: the branch predates this call (reused worktree, or recreated from a
// surviving branch); BaseSHA is then not the task's base and the caller keeps the
// recorded one (or MergeBase).
BranchExisted bool `json:"branch_existed"`
}
Result is a prepared workspace.