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

fold

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package fold provides functionality for folding stacked branches.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action

func Action(ctx context.Context, deps Deps, opts Options, handler Handler) error

Action performs the fold operation

Types

type Deps added in v0.30.1

type Deps struct {
	Engine Engine
	actions.MutationDeps
}

Deps are the collaborators fold needs. Adapters build them from their own runtime state; the action never sees bootstrap types.

type Engine added in v0.30.1

type Engine interface {
	validation.GitOperationEngine
	actions.OwnershipEngine
	Trunk() engine.Branch
	Graph(ctx context.Context, strategy engine.SortStrategy) *engine.StackGraph
	GetRevision(ctx context.Context, branch engine.Branch) (string, error)
	GetMergeBase(ctx context.Context, rev1, rev2 string) (string, error)
	ShowDiff(ctx context.Context, rr git.RevRange, format git.DiffFormat) (string, error)
	CheckoutBranch(ctx context.Context, branch engine.Branch) error
	Merge(ctx context.Context, revision string, opts engine.MergeOptions) error
	DeleteBranch(ctx context.Context, branch engine.Branch) error
	SetParent(ctx context.Context, branch engine.Branch, parentBranch engine.Branch, mode engine.DivergenceMode) error
	ReparentBranchesToParents(ctx context.Context, moves []engine.BranchParentMove, opts engine.ReparentOpts) error
}

Engine lists exactly the engine methods fold calls: the git-operation precondition checks, the merge/delete/reparent mutations, and the reads the dry-run preview needs.

type Handler

type Handler interface {
	// Start is called at the beginning of fold
	Start(currentBranch, parentBranch string, dryRun bool)

	// OnStep is called for each step in the fold process
	OnStep(step Step, status handler.StepStatus, message string)

	// Complete is called when fold finishes
	Complete(result Result)

	// Cleanup restores terminal state (may be no-op)
	Cleanup()

	// IsInteractive returns true if the handler supports interactive prompts
	IsInteractive() bool
}

Handler receives events from fold action

type NullHandler

type NullHandler struct {
	handler.NullBase
	handler.NullProgress[Step]
}

NullHandler is a no-op handler for when nil is passed. It embeds handler.NullBase for Cleanup() and IsInteractive().

func (*NullHandler) Complete

func (h *NullHandler) Complete(Result)

Complete implements Handler.

func (*NullHandler) Start

func (h *NullHandler) Start(string, string, bool)

Start implements Handler.

type Options

type Options struct {
	Keep       bool // If true, keeps the name of the current branch instead of using the name of its parent
	AllowTrunk bool // If true, allows folding into the trunk branch
	DryRun     bool // If true, only shows what would happen
}

Options contains options for the fold command

type Result

type Result struct {
	FoldedBranch  string
	IntoBranch    string
	ChildrenCount int
}

Result contains the result of the fold action

type Step

type Step string

Step represents a step in the fold process

const (
	StepValidating Step = "validating"
	StepFolding    Step = "folding"
	StepRestacking Step = "restacking"
	StepCleanup    Step = "cleanup"
)

Fold step constants

Jump to

Keyboard shortcuts

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