plan

package
v2.2.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 8 Imported by: 1 module, 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 plan models what a preen run intends to do before anything moves. A plan is data: it can be rendered for approval, edited by the user, and validated against the working tree without touching the repository.

Index

Constants

View Source
const EditHelp = `` /* 522-byte string literal not displayed */

EditHelp lists the commands the approval prompt understands.

Variables

View Source
var (
	// ErrInvalid reports a plan that does not account for the working tree
	// exactly once, or that holds an empty or unnamed commit.
	ErrInvalid = errors.New("invalid plan")
	// ErrNoSuchCommit reports an edit naming a commit number the plan lacks.
	ErrNoSuchCommit = errors.New("no such commit in the plan")
	// ErrNoSuchPath reports an edit naming a path the plan does not carry.
	ErrNoSuchPath = errors.New("no such path in the plan")
	// ErrUsage reports a command typed at the approval prompt that could not
	// be understood.
	ErrUsage = errors.New("cannot read that command")
)

Sentinel errors for plan construction and editing.

Functions

This section is empty.

Types

type Action

type Action struct {
	// Kind is what the command asks for.
	Kind ActionKind
	// Describe is a short account of the edit, echoed back after it applies.
	Describe string
	// Apply changes the plan. It is set only for ActionEdit.
	Apply func(p *Plan) error
}

Action is one parsed command from the approval prompt.

func ParseAction

func ParseAction(line string) (Action, error)

ParseAction reads one command typed at the approval prompt.

The grammar matches how the moves read in English, so "merge 2 into 1" and "move api/server.go to 3" work as written, and the filler words are optional.

type ActionKind

type ActionKind int

ActionKind is what a typed approval-prompt command asks for.

const (
	// ActionEdit changes the plan and stays at the prompt.
	ActionEdit ActionKind = iota
	// ActionApply accepts the plan as shown.
	ActionApply
	// ActionAbort leaves without changing anything.
	ActionAbort
	// ActionShow redisplays the plan.
	ActionShow
	// ActionHelp lists the available commands.
	ActionHelp
)

The actions available at the approval prompt.

type Commit

type Commit struct {
	// Subject is the first line of the message.
	Subject string
	// Body is the optional message body.
	Body string
	// Parts are the file contributions this commit takes, in listing order.
	Parts []Part
}

Commit is one planned commit: a message and the parts it will contain.

func (Commit) Message

func (c Commit) Message() string

Message renders the full commit message.

func (Commit) Paths

func (c Commit) Paths() []string

Paths returns the paths this commit touches.

type Held

type Held struct {
	// Part is the change being left uncommitted.
	Part Part
	// Pattern is the rule that matched the path.
	Pattern string
	// Why names what the path holds, so the report explains the refusal.
	Why string
}

Held is a change preen refused to plan because its path holds generated output, recorded with the reason so the plan can say why.

A held change stays in the working tree exactly as it was, and it still counts toward the coverage check, so holding one back cannot quietly drop work: the plan accounts for it, it is shown before approval, and the content hash the run conserves still includes it.

type Hunk

type Hunk struct {
	// Index is the hunk's position when the plan was built, used for display
	// and for reporting a hunk that later goes missing.
	Index int
	// Body is the hunk's lines without its header, the identity used to find
	// the hunk again at apply time.
	Body string
}

Hunk identifies one hunk a commit takes from a file.

The hunk is identified by its body rather than its position, because committing an earlier hunk shifts the line numbers of every hunk after it. The body is stable across that shift, so it still finds the right hunk in a diff regenerated mid-run.

func HunkAt

func HunkAt(i int, body string) Hunk

HunkAt returns a Hunk identifying the hunk at index i of a file diff.

type Part

type Part struct {
	// Path is the file, relative to the repository root.
	Path string
	// From is the rename source, empty unless the change moves a file.
	From string
	// Kind is what happened to the path.
	Kind repo.Kind
	// Hunks are the file's hunks this commit takes. An empty selection means
	// the whole file.
	Hunks []Hunk
}

Part is one file's contribution to a commit, either the whole file or a chosen subset of its hunks.

func (Part) String

func (p Part) String() string

String renders the part for a plan listing.

func (Part) Whole

func (p Part) Whole() bool

Whole reports whether the part carries the file's entire change.

type Plan

type Plan struct {
	// Base is the commit the run resets to, empty for a working-tree-only run.
	Base string
	// Backup is the recovery ref created before anything moved.
	Backup string
	// MergeSummary is the mandatory merge audit line for any run that resets.
	MergeSummary string
	// Absorbed are the existing commits the run will redo.
	Absorbed []repo.Commit
	// Commits are the planned commits, in the order they will be recorded.
	Commits []Commit
	// Leftover are changes deliberately left uncommitted.
	Leftover []Part
	// Held are changes left uncommitted because they hold generated output,
	// each with the pattern that caught it.
	Held []Held
	// Push is the exact force push a published rewrite will run, empty for any
	// run that does not publish.
	Push string
	// Debris are lines that look like leftovers from the session, reported so
	// they can be dealt with before they are committed. They are never removed
	// automatically.
	Debris []string
	// Covers is the change set the plan was built against, kept so an edit can
	// be revalidated without surveying the repository again.
	Covers []repo.Change
}

Plan is the full intent of a run.

func (*Plan) DropPath

func (p *Plan) DropPath(path string) error

DropPath removes a path from every commit and records it as deliberately left uncommitted, which keeps the plan accounting for the whole tree.

func (*Plan) LeavePath

func (p *Plan) LeavePath(change Part) error

LeavePath records a change as deliberately left uncommitted whether or not a commit holds it yet. DropPath alone cannot do that for a change no commit took, which is what a grouping answer that leaves a scratch file out entirely produces.

func (*Plan) MergeInto

func (p *Plan) MergeInto(from, into int) error

MergeInto folds commit number from into commit number into, keeping the destination's message and appending the source's parts.

func (*Plan) MovePath

func (p *Plan) MovePath(path string, to int) error

MovePath reassigns every part for a path to another commit.

func (Plan) Render

func (p Plan) Render(w io.Writer) error

Render writes the plan for approval. It leads with what will move, since the reset and the backup ref are what a reader needs to judge the risk, then lists the commits in the order they will be recorded.

func (*Plan) Reorder

func (p *Plan) Reorder(order []int) error

Reorder rearranges the commits into the given 1-based order, which must be a permutation of the existing numbers.

func (Plan) Resets

func (p Plan) Resets() bool

Resets reports whether the plan moves the branch, which is what makes the merge audit and the backup ref mandatory.

func (Plan) Revalidate

func (p Plan) Revalidate() error

Revalidate checks the plan against the change set it was built for, which is how an edit is rejected before it can lose work.

func (*Plan) Reword

func (p *Plan) Reword(number int, subject string) error

Reword replaces a commit's subject, leaving its body and parts alone.

func (*Plan) SplitByFile

func (p *Plan) SplitByFile(number int) error

SplitByFile breaks a commit into one commit per file it touches, keeping the original subject with the path appended so each is still named.

func (Plan) Validate

func (p Plan) Validate(changes []repo.Change) error

Validate checks that the plan is internally coherent and covers exactly the supplied set of changes: every change lands in a commit, a leftover, or a held path, nothing lands twice, and no commit is empty.

This is the check that keeps a grouping mistake from silently dropping work, and it runs before the repository is touched. Held paths are counted here for that reason: a path preen declines to commit is still a path it has to account for out loud.

Jump to

Keyboard shortcuts

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