worktree

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package worktree creates ephemeral `git worktree` checkouts so concurrent agent workers can each mutate files without racing on one shared tree.

Usage:

wt, err := worktree.Create(repoRoot, "swarm-w0")
if err != nil { ... }
defer wt.Cleanup()
// wt.Path is a fresh working tree on a detached HEAD at the original ref.

The caller decides what to do with diverging worktrees on completion (merge, copy patches back, discard). This package only handles allocation + cleanup; it does not invent a merge policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Worktree

type Worktree struct {
	Path string
	// contains filtered or unexported fields
}

Worktree is one isolated checkout. Path is the working directory; the underlying branch is detached so commits there don't move the source repo's HEAD.

func Create

func Create(repoRoot, label string) (*Worktree, error)

Create allocates a new worktree rooted under the repo's standard `.git/worktrees` parent dir if available, falling back to a sibling directory of repoRoot. `label` is a short suffix used to name both the directory and the detached branch reference for easier debugging.

repoRoot must point inside a git repo. Returns an error if `git` is not on PATH or repoRoot is not a working tree.

func (*Worktree) Cleanup

func (w *Worktree) Cleanup() error

Cleanup removes the worktree and its on-disk state. Best-effort: errors are returned but the directory is also force-removed so a partial failure can't leak storage indefinitely.

Jump to

Keyboard shortcuts

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