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

move

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: 11 Imported by: 0

Documentation

Overview

Package move provides functionality for moving branches to different parents in the stack.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Action

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

Action performs the move operation

func BuildRebaseSpecs

func BuildRebaseSpecs(ctx context.Context, eng Engine, out output.Output, source, onto string, oldParent *engine.Branch, oldParentRev string, descendants engine.Branches) []engine.RebaseSpec

BuildRebaseSpecs builds the rebase specifications for validating/executing the move. Exported so it can be used by the selection validation callback.

Types

type Deps added in v0.30.1

type Deps struct {
	Engine Engine
	actions.MutationDeps
}

Deps are the collaborators move 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.BranchValidationEngine
	actions.OwnershipEngine
	Trunk() engine.Branch
	IsTrunk(branch engine.Branch) bool
	Graph(ctx context.Context, strategy engine.SortStrategy) *engine.StackGraph
	SortBranchesTopologically(ctx context.Context, branches engine.Branches) engine.Branches
	GetRevision(ctx context.Context, branch engine.Branch) (string, error)
	GetAllCommits(ctx context.Context, branch engine.Branch) (git.Commits, error)
	GetDivergencePoint(ctx context.Context, branchName string) (string, error)
	BatchRevisions(ctx context.Context, branches engine.Branches) engine.RevisionMap
	BatchDivergencePoints(ctx context.Context, branches engine.Branches) engine.RevisionMap
	ValidateRebases(ctx context.Context, specs []engine.RebaseSpec) (*engine.RebaseValidation, error)
	ReparentBranch(ctx context.Context, branch engine.Branch, newParent engine.Branch) error
	AssignBranchesToNewStack(ctx context.Context, root engine.Branch, branches engine.Branches) (string, error)
	RenameBranch(ctx context.Context, oldBranch, newBranch engine.Branch) error
	MarkBranchesForPRBodyUpdate(ctx context.Context, branchNames []string) error
}

Engine lists exactly the engine methods move (and interactive target selection) call.

type Handler

type Handler interface {
	// Start is called at the beginning of move
	Start(move handler.Reparent)

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

	// OnRename is called when a branch is renamed due to scope change
	OnRename(oldName, newName string)

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

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

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

	// PromptRename prompts user to confirm branch rename due to scope change
	PromptRename(oldName, oldScope, newScope string) (bool, error)

	// PromptConfirmMove displays a preview of the move and asks for confirmation.
	// Returns true to proceed with the move, false to cancel.
	// If the preview reports conflicts, returning true means the user has opted
	// to proceed and resolve conflicts manually via `stackit continue`.
	// In non-interactive mode, returns true (auto-confirm).
	PromptConfirmMove(preview Preview) (bool, error)

	// PromptSelectOnto prompts user to select a new parent when --onto is not provided.
	// Returns the selected branch and any precomputed rebase specs.
	PromptSelectOnto(ctx context.Context, sourceBranch string) (string, []engine.RebaseSpec, error)
}

Handler receives events from move 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) OnRename

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

OnRename implements Handler.

func (*NullHandler) PromptConfirmMove

func (h *NullHandler) PromptConfirmMove(Preview) (bool, error)

PromptConfirmMove implements Handler. Returns true (auto-confirm) for null handler.

func (*NullHandler) PromptRename

func (h *NullHandler) PromptRename(string, string, string) (bool, error)

PromptRename implements Handler.

func (*NullHandler) PromptSelectOnto

func (h *NullHandler) PromptSelectOnto(context.Context, string) (string, []engine.RebaseSpec, error)

PromptSelectOnto implements Handler. Returns error for null handler.

func (*NullHandler) Start

func (h *NullHandler) Start(handler.Reparent)

Start implements Handler.

type Options

type Options struct {
	Source      string // Branch to move (defaults to current branch)
	Onto        string // Branch to move onto
	SkipConfirm bool   // Skip confirmation prompt (--yes flag)
	DryRun      bool   // If true, only shows what would happen without making changes
	AutoRename  bool   // Auto-rename branch when scope changes (non-interactive mode)
	// RebaseSpecs optionally provides precomputed specs (e.g. from interactive selection).
	RebaseSpecs []engine.RebaseSpec
}

Options contains options for the move command

type Preview

type Preview struct {
	SourceBranch     string   // Branch being moved
	OldParent        string   // Current parent branch
	NewParent        string   // Target parent branch
	Commits          []string // Commit subjects that will be moved
	Descendants      []string // Descendant branches that will be restacked
	HasConflicts     bool     // Whether the move will cause conflicts
	ConflictBranch   string   // Which branch would have conflicts (if any)
	ConflictError    string   // Error message describing the conflict
	ConflictingFiles []string // Files that have conflicts (if any)
}

Preview contains information about the planned move for confirmation

type Result

type Result struct {
	SourceBranch string
	OldParent    string
	NewParent    string
	Renamed      bool
	NewName      string
}

Result contains the result of the move action

type Selection

type Selection struct {
	// contains filtered or unexported fields
}

Selection contains precomputed data for validating potential move targets.

func PrepareSelection

func PrepareSelection(ctx context.Context, eng Engine, out output.Output, source string) (*Selection, error)

PrepareSelection builds the data needed for interactive onto validation.

func (*Selection) Descendants

func (s *Selection) Descendants() engine.Branches

Descendants returns the descendant branches (including the source).

func (*Selection) OldParent

func (s *Selection) OldParent() *engine.Branch

OldParent returns the current parent branch (nil if trunk).

func (*Selection) OldParentRev

func (s *Selection) OldParentRev() string

OldParentRev returns the captured old parent revision.

func (*Selection) ValidateOnto

func (s *Selection) ValidateOnto(ctx context.Context, onto string) (*engine.RebaseValidation, []string, []engine.RebaseSpec, error)

ValidateOnto validates a potential move target and returns validation, commits, and rebase specs.

type Step

type Step string

Step represents a step in the move process

const (
	StepValidating  Step = "validating"
	StepReparenting Step = "reparenting"
	StepRestacking  Step = "restacking"
)

Move step constants

Jump to

Keyboard shortcuts

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