worktrees

package
v0.97.2 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package worktrees provides functionality for creating and managing Git worktrees for operating across multiple Git references.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StackDiff

type StackDiff struct {
	Added   []*component.Stack
	Removed []*component.Stack
	Changed []StackDiffChangedPair
}

type StackDiffChangedPair

type StackDiffChangedPair struct {
	FromStack *component.Stack
	ToStack   *component.Stack
}

type Worktree

type Worktree struct {
	Ref  string
	Path string
}

Worktree is collects a Git reference and the path to the associated worktree.

type WorktreePair

type WorktreePair struct {
	GitExpression *filter.GitExpression
	Diffs         *git.Diffs
	FromWorktree  Worktree
	ToWorktree    Worktree
}

WorktreePair is a pair of worktrees, one for the from and one for the to reference, along with the GitExpression that generated the diffs and the diff for that expression.

func (*WorktreePair) Expand

func (wp *WorktreePair) Expand() (filter.Filters, filter.Filters)

Expand expands a worktree pair with an associated Git expression into the equivalent to and from filter expressions based on the provided diffs for the worktree pair.

type Worktrees

type Worktrees struct {
	WorktreePairs map[string]WorktreePair

	OriginalWorkingDir string
	// contains filtered or unexported fields
}

Worktrees is a map of WorktreePairs, and the Git runner used to create and manage the worktrees. The key is the string representation of the GitExpression that generated the worktree pair.

func NewWorktrees

func NewWorktrees(
	ctx context.Context,
	l log.Logger,
	workingDir string,
	gitExpressions filter.GitExpressions,
) (*Worktrees, error)

NewWorktrees creates a new Worktrees for a given set of Git filters.

Note that it is the responsibility of the caller to call Cleanup on the Worktrees object when it is no longer needed.

func (*Worktrees) Cleanup

func (w *Worktrees) Cleanup(ctx context.Context, l log.Logger) error

Cleanup removes all created Git worktrees and their temporary directories.

func (*Worktrees) DisplayPath

func (w *Worktrees) DisplayPath(worktreePath string) string

DisplayPath translates a worktree path to the equivalent path in the original repository for user-facing output. This is useful for logging and reporting where users expect to see paths relative to their working directory, not temporary worktree paths. If the path is not within a worktree, it returns the path unchanged.

func (*Worktrees) Stacks

func (w *Worktrees) Stacks() StackDiff

Stacks returns a slice of stacks that can be found in the diffs found in worktrees.

This can be useful, as stacks need to be discovered in worktrees, generated, then diffed on-disk to find changed units.

They are returned as added, removed, and changed stacks, respectively.

func (*Worktrees) WorkingDir

func (w *Worktrees) WorkingDir(ctx context.Context, worktreePath string) string

WorkingDir returns the path within a worktree that corresponds to the user's original working directory. This is used for display purposes after discovery completes.

Jump to

Keyboard shortcuts

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