worktrees

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 21 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 contains stacks whose terragrunt.stack.hcl was added in the git diff.
	Added []*component.Stack
	// Removed contains stacks whose terragrunt.stack.hcl was removed in the git diff.
	Removed []*component.Stack
	// Changed contains stacks whose terragrunt.stack.hcl was modified in the git diff.
	Changed []StackDiffChangedPair
	// ReadingAffected contains stacks whose terragrunt.stack.hcl did not change directly,
	// but that read files which did. These are identified during stack generation and need
	// to be walked for unit-level changes.
	ReadingAffected []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 WorktreeOpts added in v1.0.1

type WorktreeOpts struct {
	WorkingDir     string
	GitExpressions filter.GitExpressions
	Experiments    experiment.Experiments
}

WorktreeOpts contains parameters for NewWorktrees.

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, error)

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 maps Git expression strings to their corresponding worktree pairs.
	WorktreePairs map[string]WorktreePair

	// OriginalWorkingDir is the user's working directory before worktrees were created.
	OriginalWorkingDir string
	// ReadingAffectedStacks holds stacks identified during generation as affected by
	// changes to files they read, even though the stack file itself did not change in
	// the git diff. These are included in Stacks().ReadingAffected so that the worktree
	// discovery phase walks them for unit-level changes.
	ReadingAffectedStacks []StackDiffChangedPair
	// 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,
	opts WorktreeOpts,
) (*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