undo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: BlueOak-1.0.0 Imports: 7 Imported by: 0

Documentation

Overview

internal/undo/undo.go

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSnapshot = errors.New("nothing to undo")

ErrNoSnapshot is returned when no undo snapshot exists.

Functions

func Archive

func Archive(gitDir, snapshotPath string) error

Archive moves a snapshot file to the done/ subdirectory.

func Exists

func Exists(gitDir string) bool

Exists checks if any undo snapshots exist.

func Remove

func Remove(snapshotPath string) error

Remove deletes a snapshot file.

func Save

func Save(gitDir string, snapshot *Snapshot) error

Save persists the snapshot to .git/stack-undo/{timestamp}-{operation}.json.

Types

type BranchState

type BranchState struct {
	SHA            string `json:"sha"`
	StackParent    string `json:"stack_parent,omitempty"`
	StackPR        int    `json:"stack_pr,omitempty"`
	StackForkPoint string `json:"stack_fork_point,omitempty"`
}

BranchState captures the state of a single branch for undo.

type Snapshot

type Snapshot struct {
	Timestamp       time.Time              `json:"timestamp"`
	Operation       string                 `json:"operation"`
	Command         string                 `json:"command"`
	OriginalHead    string                 `json:"original_head"`
	StashRef        string                 `json:"stash_ref,omitempty"`
	Branches        map[string]BranchState `json:"branches"`
	DeletedBranches map[string]BranchState `json:"deleted_branches,omitempty"`
}

Snapshot represents the complete state before a destructive operation.

func List

func List(gitDir string) ([]*Snapshot, error)

List returns all available (non-archived) snapshots, sorted newest first.

func Load

func Load(path string) (*Snapshot, error)

Load reads a snapshot from a specific path.

func LoadLatest

func LoadLatest(gitDir string) (*Snapshot, string, error)

LoadLatest reads the most recent snapshot from .git/stack-undo/. Returns the snapshot, its file path, and any error.

func NewSnapshot

func NewSnapshot(operation, command, originalHead string) *Snapshot

NewSnapshot creates a new snapshot with the current timestamp.

Jump to

Keyboard shortcuts

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