absorb

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package absorb provides functionality for absorbing staged changes into commits downstack.

Package absorb provides functionality for absorbing staged changes into commits downstack.

Package absorb provides functionality for absorbing staged changes into commits downstack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(ctx *app.Context) error

Abort cleans up from a failed absorb state

func Action

func Action(ctx *app.Context, opts Options, handler Handler) error

Action performs the absorb operation

func GeneratePlanJSON

func GeneratePlanJSON(
	currentBranch string,
	hunkTargets []git.HunkTarget,
	unabsorbedHunks []Unabsorbable,
	newFiles []string,
	eng engine.Engine,
) ([]byte, error)

GeneratePlanJSON creates a machine-readable plan from absorb results

func IsAbsorbInProgress

func IsAbsorbInProgress(ctx *app.Context) bool

IsAbsorbInProgress checks if there's a failed absorb operation that needs cleanup. This is detected by checking for: 1. Presence of absorb stash marker, OR 2. Detached HEAD state with no rebase/merge in progress

func ShowConflict

func ShowConflict(ctx *app.Context) error

ShowConflict shows information about what absorb would do and helps diagnose conflicts. This is useful when absorb fails and you want to understand what was being attempted.

Types

type AbsorbedHunk

type AbsorbedHunk struct {
	File         string `json:"file"`
	Lines        string `json:"lines"`
	TargetBranch string `json:"target_branch"`
	TargetCommit string `json:"target_commit"`
	Content      string `json:"content"`
}

AbsorbedHunk represents a hunk that was successfully absorbed

type Handler

type Handler interface {
	// Start is called at the beginning of absorb
	Start(dryRun bool)

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

	// OnHunkTarget is called when a target is found for a hunk
	OnHunkTarget(file string, commitSHA string, branchName string)

	// OnUnabsorbedHunk is called for hunks that could not be absorbed
	OnUnabsorbedHunk(hunk git.Hunk)

	// OnApply is called when hunks are applied to a branch
	OnApply(branchName string, commitSHA string)

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

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

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

	// PromptConfirm prompts user for confirmation before absorbing
	PromptConfirm(message string) (bool, error)
}

Handler receives events from absorb action

type HunkResult

type HunkResult struct {
	File       string
	CommitSHA  string
	BranchName string
	LineStart  int
	LineEnd    int
}

HunkResult represents the result of absorbing a hunk

type NullHandler

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) OnApply

func (h *NullHandler) OnApply(string, string)

OnApply implements Handler.

func (*NullHandler) OnHunkTarget

func (h *NullHandler) OnHunkTarget(string, string, string)

OnHunkTarget implements Handler.

func (*NullHandler) OnUnabsorbedHunk

func (h *NullHandler) OnUnabsorbedHunk(git.Hunk)

OnUnabsorbedHunk implements Handler.

func (*NullHandler) Start

func (h *NullHandler) Start(bool)

Start implements Handler.

type Options

type Options struct {
	All     bool
	DryRun  bool
	Force   bool
	Patch   bool
	JSON    bool // Output machine-readable JSON summary
	Restack RestackMode
}

Options contains options for the absorb command

type PlanJSON

type PlanJSON struct {
	CurrentBranch string             `json:"current_branch"`
	Absorbed      []AbsorbedHunk     `json:"absorbed"`
	Unabsorbable  []UnabsorbableHunk `json:"unabsorbable"`
	NewFiles      []string           `json:"new_files"`
	Stack         []StackNode        `json:"stack"`
}

PlanJSON is the machine-readable absorb plan for LLM consumption

type RestackMode added in v0.21.0

type RestackMode string

RestackMode controls which branches are restacked after absorb.

const (
	RestackAll     RestackMode = "all"
	RestackCurrent RestackMode = "current"
	RestackScope   RestackMode = "scope"
	RestackNone    RestackMode = "none"
)

func NormalizeRestackMode added in v0.21.0

func NormalizeRestackMode(mode RestackMode) RestackMode

NormalizeRestackMode canonicalizes user-supplied restack mode input, defaulting to RestackAll when empty and folding case so `--restack ALL` works.

func (RestackMode) Validate added in v0.21.0

func (m RestackMode) Validate() error

type Result

type Result struct {
	Absorbed    int
	Unabsorbed  int
	BranchCount int
}

Result contains the result of the absorb action

type StackNode

type StackNode struct {
	Name      string `json:"name"`
	Parent    string `json:"parent,omitempty"`
	IsTrunk   bool   `json:"is_trunk,omitempty"`
	IsCurrent bool   `json:"is_current,omitempty"`
}

StackNode represents a branch in the stack structure

type Step

type Step string

Step represents a step in the absorb process

const (
	StepStaging    Step = "staging"
	StepParsing    Step = "parsing"
	StepFinding    Step = "finding"
	StepConfirming Step = "confirming"
	StepApplying   Step = "applying"
	StepRestacking Step = "restacking"
)

Absorb step constants

type Unabsorbable added in v0.21.0

type Unabsorbable struct {
	Hunk   git.Hunk
	Reason UnabsorbableReason
}

Unabsorbable represents a hunk that could not be absorbed and why.

type UnabsorbableHunk

type UnabsorbableHunk struct {
	File    string `json:"file"`
	Lines   string `json:"lines"`
	Reason  string `json:"reason"`
	Content string `json:"content"`
}

UnabsorbableHunk represents a hunk that could not be absorbed

type UnabsorbableReason added in v0.21.0

type UnabsorbableReason string

UnabsorbableReason describes why a hunk could not be absorbed.

const (
	ReasonCommutesWithAll UnabsorbableReason = "commutes_with_all"
	ReasonUnknownBranch   UnabsorbableReason = "unknown_branch"
	ReasonBinary          UnabsorbableReason = "binary"
	ReasonNewFile         UnabsorbableReason = "new_file"
	ReasonDeletedFile     UnabsorbableReason = "deleted_file"
	ReasonUnsupported     UnabsorbableReason = "unsupported"
)

func (UnabsorbableReason) Description added in v0.21.0

func (r UnabsorbableReason) Description() string

Description returns a user-friendly explanation for why a hunk could not be absorbed.

func (UnabsorbableReason) Tip added in v0.21.0

func (r UnabsorbableReason) Tip() string

Tip returns a short actionable hint for this unabsorbable reason.

Jump to

Keyboard shortcuts

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