worktree

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package worktree isolates a delegated agent in its own copy of a git repository, so two sub-agents working in parallel do not tread on each other's files.

A git worktree is a second checkout sharing one object store: cheap to create, and its own working directory. A sub-agent given one can edit, build, and commit without the parent's tree or another sibling's tree changing under it. When the sub-agent is done, an unchanged worktree is removed; one with work in it is left for a person to look at.

None of this needs anything but git. Where git is absent, or the workspace is not a repository, isolation is simply unavailable and the caller falls back to the shared workspace — reported, never fatal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Available

func Available(workspace string) bool

Available reports whether isolation can be used for a workspace: git is installed and the workspace is inside a repository.

Types

type Worktree

type Worktree struct {
	// Path is the working directory the agent should use.
	Path string
	// Branch is the throwaway branch the worktree is on.
	Branch string
	// contains filtered or unexported fields
}

Worktree is one isolated checkout.

func Create

func Create(ctx context.Context, workspace, label string) (*Worktree, error)

Create makes a worktree off the workspace's repository. label is worked into the branch and directory names so a person can tell whose it is.

func (*Worktree) Cleanup

func (w *Worktree) Cleanup(ctx context.Context) string

Cleanup removes an unchanged worktree and leaves a changed one, returning a sentence describing what it did for the delegating agent to relay.

func (*Worktree) Dirty

func (w *Worktree) Dirty(ctx context.Context) bool

Dirty reports whether the worktree has uncommitted changes — the signal for whether there is work worth keeping.

func (*Worktree) Remove

func (w *Worktree) Remove(ctx context.Context, force bool) error

Remove deletes the worktree and its throwaway branch. It is meant for a worktree with nothing worth keeping; force removes it regardless.

Jump to

Keyboard shortcuts

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