Help us shape the future of Go! Take the 2026 Go Developer Survey

worktree

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package worktree wraps git-worktree operations for per-agent isolation (design 008): give a pane/agent its own git worktree so parallel agents never collide on the same repo — "N agents, N branches, one tab, zero collisions."

This package is the tested git seam. The command surface (##worktree) and the eventual pane-cwd integration live in internal/actors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(repoRoot, path, branch string) error

Add creates a worktree at path on a new branch. If the branch already exists, it is checked out instead of created.

func DeleteBranch

func DeleteBranch(repoRoot, branch string) error

DeleteBranch force-deletes a local branch. Used by the headless CI runner (design 009) to drop the throwaway branch its per-run worktree was created on, so repeated `rysh run --worktree` invocations never accumulate branches.

func DiffStat

func DiffStat(path string) (string, error)

DiffStat returns `git diff --stat` for the worktree at path.

func Dir

func Dir(repoRoot, branch string) string

Dir returns the conventional worktree path for a branch under the repo's .rysh/worktrees/ (mirrors the monorepo's own worktrees/ convention).

func IsClean

func IsClean(path string) (bool, error)

IsClean reports whether the worktree at path has no uncommitted changes.

func IsGitRepo

func IsGitRepo(dir string) bool

IsGitRepo reports whether dir is inside a git work tree.

func Merge

func Merge(repoRoot, branch string) (string, error)

Merge merges branch into the current branch at repoRoot, returning git output. Fails (non-nil error) on conflicts — callers surface it fail-closed.

func MergePreview

func MergePreview(repoRoot, branch string) (string, error)

MergePreview returns a diff --stat of what merging branch would bring in.

func Prune

func Prune(repoRoot string) error

Prune drops stale administrative entries — worktrees whose directory was deleted out from under git (crashed agent, manual rm -rf). It never touches a directory that still exists, so it is safe to run unconditionally at session start (design 008's orphan sweep).

func Remove

func Remove(repoRoot, path string, force bool) error

Remove removes a worktree. force removes even if dirty.

func RepoRoot

func RepoRoot(dir string) (string, error)

RepoRoot returns the top-level directory of the repo containing dir.

func SanitizeBranch

func SanitizeBranch(branch string) string

SanitizeBranch turns a branch name into a filesystem-safe directory segment.

Types

type Info

type Info struct {
	Path   string
	Branch string
	Head   string
}

Info describes one worktree from `git worktree list`.

func List

func List(repoRoot string) ([]Info, error)

List returns the repo's worktrees (porcelain-parsed).

Jump to

Keyboard shortcuts

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