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

modify

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 12 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 CheckWorktrees added in v0.2.0

func CheckWorktrees(s *stack.Stack) (*worktree.Context, error)

CheckWorktrees resolves the initiating worktree. Action-specific owner preflight runs after the TUI has produced its plan.

func ClearState

func ClearState(gitDir string) error

ClearState removes the modify state file.

func ConflictOps added in v0.2.0

func ConflictOps(state *StateFile) (git.Ops, string, error)

ConflictOps resolves the native operation's worktree, which can differ from both the invoking worktree and the source branch of a fold.

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 MatchesStack added in v0.2.0

func MatchesStack(state *StateFile, target *stack.Stack) bool

MatchesStack never uses the catalog position as an identity. Older records can be identified by their remote ID or the original snapshot.

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 retained for legacy callers, but is never used as an identity.

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"
	Target      string `json:"target,omitempty"`       // fold receiver, insertion parent, or normalization drop
}

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"` // legacy hint, never an identity
	StartedAt             time.Time         `json:"started_at"`
	Phase                 string            `json:"phase"`
	PriorRemoteStackID    string            `json:"prior_remote_stack_id,omitempty"`
	Snapshot              Snapshot          `json:"snapshot"`
	Plan                  []Action          `json:"plan"`
	Worktrees             *worktree.Context `json:"worktrees,omitempty"`
	StackBranches         []string          `json:"stack_branches"`
	PreviousStackBranches []string          `json:"previous_stack_branches"`
	RenamedBranches       map[string]string `json:"renamed_branches,omitempty"`
	CreatedBranches       map[string]string `json:"created_branches,omitempty"`
	PendingAction         *Action           `json:"pending_action,omitempty"`
	Execution             []Action          `json:"execution,omitempty"`
	NextAction            int               `json:"next_action,omitempty"`
	DesiredOrder          []string          `json:"desired_order"`
	TrunkSHA              string            `json:"trunk_sha,omitempty"`
	PendingHead           string            `json:"pending_head,omitempty"`

	// 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 <common-dir>/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.

func (*StateFile) RecordStack added in v0.2.0

func (s *StateFile) RecordStack(target *stack.Stack)

Jump to

Keyboard shortcuts

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