move

package
v0.17.14 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 12 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 *app.Context, opts Options, h Handler) error

Action performs the move operation

func BuildRebaseSpecs

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

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

func SelectOntoInteractive

func SelectOntoInteractive(ctx *app.Context, sourceBranch string) (string, []engine.RebaseSpec, error)

SelectOntoInteractive shows an interactive branch selector for choosing the "onto" branch and returns precomputed rebase specs for the final selection. This uses a compact inline bubbletea model that combines selection and confirmation.

Types

type Handler

type Handler interface {
	// Start is called at the beginning of move
	Start(sourceBranch, oldParent, newParent string)

	// 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.
	// 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 *app.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(*app.Context, string) (string, []engine.RebaseSpec, error)

PromptSelectOnto implements Handler. Returns error for null handler.

func (*NullHandler) Start

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

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 *app.Context, source string) (*Selection, error)

PrepareSelection builds the data needed for interactive onto validation.

func (*Selection) Descendants

func (s *Selection) Descendants() []engine.Branch

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