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

modify

package
v0.0.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	PhaseApplying      = "applying"
	PhaseConflict      = "conflict"
	PhasePendingSubmit = "pending_submit"
)

Variables

This section is empty.

Functions

func ApplyPlan

func ApplyPlan(
	cfg *config.Config,
	gitDir string,
	s *stack.Stack,
	sf *stack.StackFile,
	nodes []modifyview.ModifyBranchNode,
	currentBranch string,
	updateBaseSHAs func(*stack.Stack),
) (*modifyview.ApplyResult, *modifyview.ConflictInfo, error)

ApplyPlan executes the staged modifications on the stack. updateBaseSHAs is called after rebasing to refresh branch SHAs in the stack metadata. It returns an ApplyResult on success or a ConflictInfo if a rebase conflict occurs.

func CheckNoMergeQueuePRs

func CheckNoMergeQueuePRs(cfg *config.Config, s *stack.Stack) error

CheckNoMergeQueuePRs checks that no unmerged PR in the stack is currently queued.

func CheckStackLinearity

func CheckStackLinearity(cfg *config.Config, s *stack.Stack) error

CheckStackLinearity verifies that the stack has unambiguous commit-to-branch mapping. For each adjacent pair (parent, child), checks: 1. parent tip is an ancestor of child tip 2. no merge commits exist in the range parent..child

func CheckStateGuard

func CheckStateGuard(gitDir string) error

CheckStateGuard checks if a modify state file exists with phase "applying" and returns an error if so. This is used as a guard at the top of commands that should not run while a modify is in progress.

func ClearState

func ClearState(gitDir string)

ClearState removes the modify state file.

func ContinueApply

func ContinueApply(
	cfg *config.Config,
	gitDir string,
	updateBaseSHAs func(*stack.Stack),
) error

ContinueApply resumes a modify operation after the user resolves a rebase conflict. It finishes the in-progress git rebase, then continues the cascading rebase for remaining branches stored in the state file.

func SaveState

func SaveState(gitDir string, state *StateFile) error

SaveState writes the modify state file atomically (write to temp, then rename).

func StateExists

func StateExists(gitDir string) bool

StateExists returns true if a modify state file exists.

func StatePath

func StatePath(gitDir string) string

StatePath returns the full path to the modify state file.

func Unwind

func Unwind(cfg *config.Config, gitDir string, snapshot Snapshot, stackIndex int, sf *stack.StackFile, plan []Action) error

Unwind restores the stack to its pre-modify state using the snapshot. stackIndex is the index of the stack in sf.Stacks at modify start time.

func UnwindFromStateFile

func UnwindFromStateFile(cfg *config.Config, gitDir string) error

UnwindFromStateFile restores the stack from a modify state file (for --abort).

Types

type Action

type Action struct {
	Type        string `json:"type"` // "drop", "fold_down", "fold_up", "move", "rename"
	Branch      string `json:"branch"`
	NewPosition int    `json:"new_position,omitempty"` // for "move"
	NewName     string `json:"new_name,omitempty"`     // for "rename"
}

Action represents a single staged action from the TUI.

func BuildPlan

func BuildPlan(nodes []modifyview.ModifyBranchNode) []Action

BuildPlan converts the TUI's staged actions into a list of Actions suitable for storage in the state file.

type BranchSnapshot

type BranchSnapshot struct {
	Name     string `json:"name"`
	TipSHA   string `json:"tip_sha"`
	Position int    `json:"position"`
}

BranchSnapshot stores the state of a single branch before modification.

type Snapshot

type Snapshot struct {
	Branches      []BranchSnapshot `json:"branches"`
	StackMetadata json.RawMessage  `json:"stack_metadata"`
}

Snapshot captures the pre-modify state for unwind/recovery.

func BuildSnapshot

func BuildSnapshot(s *stack.Stack) (Snapshot, error)

BuildSnapshot captures the current state of the stack for unwind/recovery.

type StateFile

type StateFile struct {
	SchemaVersion      int       `json:"schema_version"`
	StackName          string    `json:"stack_name"`
	StackIndex         int       `json:"stack_index"` // index in StackFile.Stacks at modify start
	StartedAt          time.Time `json:"started_at"`
	Phase              string    `json:"phase"` // "applying", "conflict", or "pending_submit"
	PriorRemoteStackID string    `json:"prior_remote_stack_id,omitempty"`
	Snapshot           Snapshot  `json:"snapshot"`
	Plan               []Action  `json:"plan"`

	// Conflict state — populated when phase is "conflict"
	ConflictBranch    string            `json:"conflict_branch,omitempty"`
	ConflictType      string            `json:"conflict_type,omitempty"` // "rebase" or "cherry_pick"
	RemainingBranches []string          `json:"remaining_branches,omitempty"`
	OriginalBranch    string            `json:"original_branch,omitempty"`
	OriginalRefs      map[string]string `json:"original_refs,omitempty"`

	// Cherry-pick conflict context — which fold was in progress
	FoldBranch string `json:"fold_branch,omitempty"` // branch being folded
	FoldTarget string `json:"fold_target,omitempty"` // branch receiving the cherry-pick

	// AffectsPRs records whether any action so far has affected a branch with
	// a PR.  Persisted across conflict boundaries so ContinueApply can combine
	// it with checks on remaining branches.
	AffectsPRs bool `json:"affects_prs,omitempty"`
}

StateFile holds the state of an in-progress or pending-submit modify operation. It is stored at .git/gh-stack-modify-state.

func LoadState

func LoadState(gitDir string) (*StateFile, error)

LoadState reads the modify state file from the git directory. Returns nil, nil if the file does not exist.

Jump to

Keyboard shortcuts

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