gitwt

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 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 gitwt inspects git worktrees. It is safety-critical: a worktree may only be offered for removal when Inspect proves it holds no unsaved work. Whenever a git command needed for the proof fails, Inspect returns an error (callers keep the item) rather than guessing that the worktree is clean.

Index

Constants

This section is empty.

Variables

View Source
var Regenerable = []string{"node_modules", "dist", "build", "target", ".venv", "venv", "__pycache__", ".next", ".turbo", "coverage", ".pytest_cache", ".gradle", ".cache", ".parcel-cache", "out"}

Regenerable lists directory names whose ignored contents can be rebuilt.

Functions

func BaseRef

func BaseRef(ctx context.Context, repo string) string

BaseRef picks the ref work is considered saved into, or "" if none exists.

func FindRepos

func FindRepos(root string, depth int) []string

FindRepos returns root and directories at most depth levels below it that contain a .git directory. It skips node_modules and hidden directories and never follows symlinks.

func Remove

func Remove(ctx context.Context, repo, path string) error

Remove unregisters and deletes a worktree without --force. git only refuses for modified or untracked files it can see; it does NOT refuse for ignored files, assume-unchanged/skip-worktree edits, or untracked files hidden by status.showUntrackedFiles=no. Callers must Inspect immediately before Remove.

func RepoOf

func RepoOf(ctx context.Context, path string) (string, error)

RepoOf returns the main checkout path that path belongs to.

func TrackedFiles

func TrackedFiles(ctx context.Context, path string) (map[string]bool, error)

TrackedFiles returns the set of files git tracks in the worktree at path, as slash-separated paths relative to it. It uses the same sanitized git environment as the rest of the package.

Types

type State

type State struct {
	HeadSHA, Base                       string
	Uncommitted, Untracked, IgnoredKept []string
	HiddenFromStatus                    []string // assume-unchanged / skip-worktree files
	UnsavedCommits, CommitsBeyondBase   int
	DetachedUnreachable                 bool
	OpInProgress                        string
	Locked                              bool
}

State is what Inspect found in a worktree.

func Inspect

func Inspect(ctx context.Context, wt Worktree, base string) (State, error)

Inspect reports everything in wt that would be lost by removing it. base is the ref work is merged into ("" if unknown, which makes every commit not on a remote count as unsaved).

func (State) Unsaved

func (s State) Unsaved() []string

Unsaved returns human-readable reasons the worktree holds unsaved work; empty means nothing is unsaved.

type Worktree

type Worktree struct {
	Repo, Path, Head, Branch         string
	Main, Detached, Locked, Prunable bool
}

Worktree is one entry of `git worktree list --porcelain`.

func List

func List(ctx context.Context, repo string) ([]Worktree, error)

List returns the worktrees of repo; the first is the main checkout.

Jump to

Keyboard shortcuts

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