Documentation
¶
Overview ¶
Package git wraps the git CLI to provide typed, safe access to git operations. All index-mutating operations are serialised through an OpQueue to prevent concurrent writes from corrupting repository state. Read operations run concurrently against the same queue.
Index ¶
- Constants
- func CheckGitInstalled() error
- func JoinPaths(paths []string) string
- func RemoteToHTTPS(raw string) string
- func ValidateArg(arg string) error
- func ValidatePath(path string) error
- func ValidateRef(ref string) error
- func ValidateRepoRelativePath(path string) error
- func WorktreePath(repoRoot, branch string) string
- type BisectOps
- type BlameLine
- type Branch
- type BranchManager
- type Cache
- type Client
- func (c *Client) BisectBad(ctx context.Context) (string, error)
- func (c *Client) BisectGood(ctx context.Context) (string, error)
- func (c *Client) BisectReset(ctx context.Context) error
- func (c *Client) BisectStart(ctx context.Context, bad, good string) error
- func (c *Client) Blame(ctx context.Context, path string) ([]BlameLine, error)
- func (c *Client) BranchCreate(ctx context.Context, name, base string) error
- func (c *Client) BranchDelete(ctx context.Context, name string, force bool) error
- func (c *Client) BranchList(ctx context.Context) ([]Branch, error)
- func (c *Client) BranchRename(ctx context.Context, oldName, newName string) error
- func (c *Client) Checkout(ctx context.Context, ref string) error
- func (c *Client) CherryPick(ctx context.Context, commitHash string) error
- func (c *Client) Commit(ctx context.Context, msg string, opts CommitOpts) (string, error)
- func (c *Client) Diff(ctx context.Context, opts DiffOpts) ([]FileDiff, error)
- func (c *Client) DiffFileNames(ctx context.Context, commitA, commitB string) ([]string, error)
- func (c *Client) DiffTreeFiles(ctx context.Context, hash string) ([]string, error)
- func (c *Client) DiscardAllUnstaged(ctx context.Context) error
- func (c *Client) DiscardFile(ctx context.Context, path string) error
- func (c *Client) Fetch(ctx context.Context, opts FetchOpts) error
- func (c *Client) IgnoredPaths(ctx context.Context) ([]string, error)
- func (c *Client) InvalidateCache()
- func (c *Client) IsRepo(ctx context.Context) (bool, error)
- func (c *Client) Log(ctx context.Context, opts LogOpts) ([]Commit, error)
- func (c *Client) Merge(ctx context.Context, branch string, opts MergeOpts) error
- func (c *Client) MergeAbort(ctx context.Context) error
- func (c *Client) Pull(ctx context.Context, opts PullOpts) error
- func (c *Client) Push(ctx context.Context, opts PushOpts) error
- func (c *Client) Rebase(ctx context.Context, onto string, opts RebaseOpts) error
- func (c *Client) RebaseAbort(ctx context.Context) error
- func (c *Client) RebaseContinue(ctx context.Context) error
- func (c *Client) Reflog(ctx context.Context, ref string, limit int) ([]ReflogEntry, error)
- func (c *Client) RemoteAdd(ctx context.Context, name, url string) error
- func (c *Client) RemoteList(ctx context.Context) ([]Remote, error)
- func (c *Client) RemoteRemove(ctx context.Context, name string) error
- func (c *Client) RepoDir() string
- func (c *Client) RepoRoot(ctx context.Context) (string, error)
- func (c *Client) Reset(ctx context.Context, ref string, mode ResetMode) error
- func (c *Client) Revert(ctx context.Context, hash string) error
- func (c *Client) RevertAbort(ctx context.Context) error
- func (c *Client) RevertContinue(ctx context.Context) error
- func (c *Client) Stage(ctx context.Context, paths []string) error
- func (c *Client) StageHunk(ctx context.Context, path string, hunk Hunk) error
- func (c *Client) StageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error
- func (c *Client) StashApply(ctx context.Context, index int) error
- func (c *Client) StashDrop(ctx context.Context, index int) error
- func (c *Client) StashList(ctx context.Context) ([]StashEntry, error)
- func (c *Client) StashPop(ctx context.Context, index int) error
- func (c *Client) StashPush(ctx context.Context, opts StashOpts) error
- func (c *Client) StashShow(ctx context.Context, index int) (string, error)
- func (c *Client) Status(ctx context.Context) ([]FileStatus, error)
- func (c *Client) TagCreate(ctx context.Context, name, ref, message string) error
- func (c *Client) TagDelete(ctx context.Context, name string) error
- func (c *Client) TagList(ctx context.Context) ([]Tag, error)
- func (c *Client) TagListRemote(ctx context.Context, remote string) ([]Tag, error)
- func (c *Client) TagPush(ctx context.Context, remote, name string) error
- func (c *Client) TagPushAll(ctx context.Context, remote string) error
- func (c *Client) Unstage(ctx context.Context, paths []string) error
- func (c *Client) UnstageHunk(ctx context.Context, path string, hunk Hunk) error
- func (c *Client) UnstageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error
- func (c *Client) WorktreeAdd(ctx context.Context, path, branch string) error
- func (c *Client) WorktreeList(ctx context.Context) ([]Worktree, error)
- func (c *Client) WorktreeRemove(ctx context.Context, path string, force bool) error
- type Commit
- type CommitOpts
- type DiffLine
- type DiffLineType
- type DiffOpts
- type DiscardOps
- type FetchOpts
- type FileDiff
- type FileStatus
- type GitClient
- type Hunk
- type IgnoreChecker
- type IndexMutator
- type LogOpts
- type MergeOpts
- type MergeRebaseOps
- type OpQueue
- type PullOpts
- type PushOpts
- type RebaseOpts
- type ReflogEntry
- type ReflogOps
- type Remote
- type RemoteListOps
- type RemoteOps
- type ResetMode
- type ResetOps
- type RevertOps
- type StashEntry
- type StashOps
- type StashOpts
- type StatusBranch
- type StatusCode
- type StatusReader
- type Tag
- type TagOps
- type UndoAction
- type UndoManager
- func (u *UndoManager) CanRedo() bool
- func (u *UndoManager) CanUndo() bool
- func (u *UndoManager) NeedsConfirmation() bool
- func (u *UndoManager) PeekRedo() (UndoAction, bool)
- func (u *UndoManager) PeekUndo() (UndoAction, bool)
- func (u *UndoManager) RecordAction(action UndoAction)
- func (u *UndoManager) Redo(ctx context.Context) (string, error)
- func (u *UndoManager) RedoNeedsConfirmation() bool
- func (u *UndoManager) Undo(ctx context.Context) (string, error)
- type Worktree
- type WorktreeOps
Constants ¶
const ( // FieldSep is the ASCII Record Separator (\x1e) used as the field // delimiter in structured git format strings. This allows body text // containing newlines without breaking record boundaries. FieldSep = "\x1e" // RecordEnd is the ASCII Unit Separator (\x1f) used to mark the end // of a record in multi-record git output (e.g., git log). RecordEnd = "\x1f" // ShortHashLen is the standard truncation length for commit short hashes // displayed in the UI. ShortHashLen = 7 )
--------------------------------------------------------------------------- Format constants used across git output parsing ---------------------------------------------------------------------------
Variables ¶
This section is empty.
Functions ¶
func CheckGitInstalled ¶
func CheckGitInstalled() error
CheckGitInstalled verifies git is available on PATH.
func JoinPaths ¶
JoinPaths joins paths with newline separators for storage in UndoAction metadata. Newlines are forbidden in git paths (see ValidatePath), making this a safe separator.
func RemoteToHTTPS ¶
RemoteToHTTPS converts a git remote URL (SSH, HTTPS, or ssh://) to an HTTPS URL suitable for opening in a browser. Returns "" for unrecognised formats or empty input.
func ValidateArg ¶
ValidateArg rejects git arguments containing shell metacharacters. This prevents command injection when constructing git CLI commands. For user-supplied names (branch, tag, remote), also use ValidateRef which additionally rejects leading dashes to prevent option injection.
func ValidatePath ¶
ValidatePath validates a file path for git operations. It rejects shell metacharacters, null bytes, and path traversal attempts. Absolute paths are allowed for read-only callers that intentionally accept repository-anchored absolute paths.
func ValidateRef ¶
ValidateRef validates a git ref (branch name, tag, hash). Allows alphanumeric, dash, underscore, dot, slash, @, ~, ^, and colon. Leading dashes are rejected to prevent option injection (CWE-88).
func ValidateRepoRelativePath ¶
ValidateRepoRelativePath validates a repository-relative path for mutating git operations that must never accept absolute filesystem paths.
func WorktreePath ¶
WorktreePath computes the conventional filesystem path for a new worktree given the repository root and branch name. It follows the grut convention:
<parent-of-repo>/.worktrees/<repo-name>/<branch-slug>
where branch-slug replaces "/" with "-".
Types ¶
type BisectOps ¶
type BisectOps interface {
BisectStart(ctx context.Context, bad, good string) error
BisectGood(ctx context.Context) (string, error)
BisectBad(ctx context.Context) (string, error)
BisectReset(ctx context.Context) error
}
BisectOps provides bisect operations.
type Branch ¶
type Branch struct {
Name string
Upstream string
Hash string
Ahead int
Behind int
IsRemote bool
IsCurrent bool
}
Branch represents a git branch with tracking information.
type BranchManager ¶
type BranchManager interface {
BranchList(ctx context.Context) ([]Branch, error)
BranchCreate(ctx context.Context, name string, base string) error
BranchDelete(ctx context.Context, name string, force bool) error
BranchRename(ctx context.Context, oldName, newName string) error
Checkout(ctx context.Context, ref string) error
}
BranchManager provides branch and checkout operations.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides a single-writer broadcast-reader cache for git data. Readers use RLock; the writer uses Lock. Data is considered fresh if its age is within maxAge.
func (*Cache) GetBranches ¶
GetBranches returns cached branch data and whether it is still fresh.
func (*Cache) GetStatus ¶
func (c *Cache) GetStatus() ([]FileStatus, bool)
GetStatus returns cached status data and whether it is still fresh.
func (*Cache) SetBranches ¶
SetBranches replaces the cached branch data and resets the age.
func (*Cache) SetStatus ¶
func (c *Cache) SetStatus(status []FileStatus)
SetStatus replaces the cached status data and resets the age.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the git CLI and implements GitClient. It shells out to the git binary for all operations.
func NewClient ¶
NewClient creates a new Client for the repository at repoDir. It verifies that git is installed and the directory exists.
func NewClientWithCache ¶
NewClientWithCache creates a new Client with caching enabled.
func (*Client) BisectBad ¶
BisectBad marks the current revision as bad. Returns the next revision to test or a message indicating the bisect is done.
func (*Client) BisectGood ¶
BisectGood marks the current revision as good. Returns the next revision to test or a message indicating the bisect is done.
func (*Client) BisectReset ¶
BisectReset ends the bisect session and returns to the original HEAD.
func (*Client) BisectStart ¶
BisectStart begins a bisect session between a bad and good commit.
func (*Client) BranchCreate ¶
BranchCreate creates a new branch from base (or HEAD if base is empty).
func (*Client) BranchDelete ¶
BranchDelete deletes a branch. Use force=true for -D (force delete).
func (*Client) BranchList ¶
BranchList returns all local and remote branches.
func (*Client) BranchRename ¶
BranchRename renames a branch from oldName to newName. If oldName is empty, renames the current branch.
func (*Client) CherryPick ¶
CherryPick applies a commit by hash to the current branch.
func (*Client) Commit ¶
Commit creates a new commit with the given message and options. Returns the commit hash on success.
func (*Client) DiffFileNames ¶ added in v0.0.2
DiffFileNames returns the list of file names that differ between two refs. It uses three-dot notation (commitA...commitB) to compare via merge-base, showing only the changes introduced on commitB since it diverged from commitA.
func (*Client) DiffTreeFiles ¶
DiffTreeFiles returns the list of files changed in a commit.
func (*Client) DiscardAllUnstaged ¶
DiscardAllUnstaged discards all unstaged changes in the working tree.
func (*Client) DiscardFile ¶
DiscardFile discards unstaged changes for a single file, restoring it to the index state. For untracked files use clean; this only handles tracked modifications.
func (*Client) IgnoredPaths ¶
IgnoredPaths returns paths ignored by .gitignore rules. It uses --ignored=matching so that ignored directories appear as single entries rather than recursing into every contained file.
func (*Client) InvalidateCache ¶
func (c *Client) InvalidateCache()
InvalidateCache clears all cached data.
func (*Client) MergeAbort ¶
MergeAbort aborts a merge in progress.
func (*Client) RebaseAbort ¶
RebaseAbort aborts a rebase in progress.
func (*Client) RebaseContinue ¶
RebaseContinue continues a rebase in progress.
func (*Client) Reflog ¶
Reflog returns reflog entries for the given ref. If ref is empty, defaults to HEAD. Limit controls the maximum number of entries (0 = unlimited).
func (*Client) RemoteList ¶
RemoteList returns all configured remotes with their fetch and push URLs.
func (*Client) RemoteRemove ¶
RemoteRemove removes a remote by name.
func (*Client) Reset ¶
Reset moves the current branch tip to ref and optionally updates the index and working tree based on mode:
- soft: HEAD only — staged changes and working tree are untouched
- mixed: HEAD + index — staged changes become unstaged (default git behavior)
- hard: HEAD + index + working tree — all changes are discarded
func (*Client) Revert ¶
Revert creates a new commit that undoes the changes introduced by the given commit hash. If the revert causes conflicts, the user must resolve them and call RevertContinue, or call RevertAbort to cancel.
func (*Client) RevertAbort ¶
RevertAbort aborts an in-progress revert and restores the previous state.
func (*Client) RevertContinue ¶
RevertContinue continues a revert after conflicts have been resolved.
func (*Client) StageHunk ¶
StageHunk stages a single hunk from an unstaged file by building a patch and applying it to the index via git apply --cached.
func (*Client) StageLine ¶
StageLine stages a single diff line from an unstaged hunk by constructing a synthetic patch containing only that line's change.
func (*Client) StashApply ¶
StashApply applies (but does not remove) the stash entry at the given index.
func (*Client) StashDrop ¶
StashDrop removes the stash entry at the given index without applying it.
func (*Client) StashList ¶
func (c *Client) StashList(ctx context.Context) ([]StashEntry, error)
StashList returns all stash entries.
func (*Client) StashShow ¶
StashShow returns the diff output for the stash entry at the given index.
func (*Client) Status ¶
func (c *Client) Status(ctx context.Context) ([]FileStatus, error)
Status returns the working tree status using porcelain v2 format.
func (*Client) TagCreate ¶
TagCreate creates a new tag. If message is non-empty, creates an annotated tag.
func (*Client) TagListRemote ¶
TagListRemote discovers tags on a remote using ls-remote. It returns tags that exist on the remote but not locally.
func (*Client) TagPushAll ¶
TagPushAll pushes all tags to a remote.
func (*Client) UnstageHunk ¶
UnstageHunk unstages a single hunk from a staged file by building a patch and applying it in reverse via git apply --cached --reverse.
func (*Client) UnstageLine ¶
UnstageLine unstages a single diff line from a staged hunk by constructing a synthetic patch and applying it in reverse.
func (*Client) WorktreeAdd ¶
WorktreeAdd creates a new worktree at the given path for the specified branch.
func (*Client) WorktreeList ¶
WorktreeList returns all worktrees for the repository.
type Commit ¶
type Commit struct {
Hash string
ShortHash string
Author string
AuthorEmail string
Date time.Time
Subject string
Body string
Parents []string // Parent hashes for graph rendering
Refs []string // Branch/tag refs
}
Commit represents a parsed git log entry.
type CommitOpts ¶
type CommitOpts struct {
Fixup string // Commit hash to fixup (--fixup=<hash>)
Author string // Override author "Name <email>"
AllowEmpty bool
Amend bool
RewordOnly bool // When true with Amend, only change message (--only flag)
Sign bool
}
CommitOpts configures a git commit operation.
type DiffLine ¶
type DiffLine struct {
Content string
Type DiffLineType
OldLine int
NewLine int
}
DiffLine represents a single line within a diff hunk.
type DiffLineType ¶
type DiffLineType int
DiffLineType identifies the kind of line in a diff.
const ( DiffLineContext DiffLineType = iota DiffLineAdded DiffLineRemoved )
type DiffOpts ¶
type DiffOpts struct {
Path string // Limit diff to a specific path
CommitA string // Compare two commits
CommitB string
Context int // Lines of context around changes (default 3)
Staged bool // Compare index vs HEAD (--cached)
NameOnly bool // Only show file names
StatOnly bool // Only show stat summary
IgnoreAll bool // Ignore all whitespace changes
}
DiffOpts configures a git diff operation.
type DiscardOps ¶
type DiscardOps interface {
DiscardFile(ctx context.Context, path string) error
DiscardAllUnstaged(ctx context.Context) error
}
DiscardOps provides operations for discarding unstaged changes.
type FileStatus ¶
type FileStatus struct {
Path string
OrigPath string // For renames
StagedStatus StatusCode // Index status
WorktreeStatus StatusCode // Worktree status
}
FileStatus represents the status of a single file from git status.
type GitClient ¶
type GitClient interface {
StatusReader
IndexMutator
BranchManager
RemoteOps
RemoteListOps
WorktreeOps
StashOps
TagOps
MergeRebaseOps
BisectOps
ReflogOps
DiscardOps
RevertOps
ResetOps
}
GitClient composes all sub-interfaces.
type Hunk ¶
type Hunk struct {
Header string
Lines []DiffLine
OldStart int
OldLines int
NewStart int
NewLines int
NoNewlineEOF bool // true when hunk ends with "\ No newline at end of file"
}
Hunk represents a contiguous block of changes in a diff.
type IgnoreChecker ¶
IgnoreChecker can report which paths are ignored by .gitignore rules.
type IndexMutator ¶
type IndexMutator interface {
Stage(ctx context.Context, paths []string) error
Unstage(ctx context.Context, paths []string) error
StageHunk(ctx context.Context, path string, hunk Hunk) error
UnstageHunk(ctx context.Context, path string, hunk Hunk) error
StageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error
UnstageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error
Commit(ctx context.Context, msg string, opts CommitOpts) (string, error)
}
IndexMutator provides index-mutating operations (serialized via queue).
type LogOpts ¶
type LogOpts struct {
Since string // Show commits after this date
Until string // Show commits before this date
Author string // Filter by author
Grep string // Filter by commit message
Path string // Filter by path
Ref string // Starting ref (default HEAD)
MaxCount int // Max number of commits to return
Skip int // Number of commits to skip (for pagination)
All bool // Show all refs
Graph bool // Include graph data
}
LogOpts configures a git log operation.
type MergeRebaseOps ¶
type MergeRebaseOps interface {
Merge(ctx context.Context, branch string, opts MergeOpts) error
MergeAbort(ctx context.Context) error
Rebase(ctx context.Context, onto string, opts RebaseOpts) error
RebaseContinue(ctx context.Context) error
RebaseAbort(ctx context.Context) error
CherryPick(ctx context.Context, commitHash string) error
}
MergeRebaseOps provides merge and rebase operations.
type OpQueue ¶
type OpQueue struct {
// contains filtered or unexported fields
}
OpQueue serializes index-mutating operations to prevent git lock contention. Read-only operations bypass the queue entirely.
type PushOpts ¶
type PushOpts struct {
Remote string
Branch string
Force bool
ForceWith bool // --force-with-lease
SetUpstream bool
Tags bool
}
PushOpts configures a git push operation.
type RebaseOpts ¶
type RebaseOpts struct {
Interactive bool
}
RebaseOpts configures a git rebase operation.
type ReflogEntry ¶
ReflogEntry represents a single reflog entry.
type ReflogOps ¶
type ReflogOps interface {
Reflog(ctx context.Context, ref string, limit int) ([]ReflogEntry, error)
}
ReflogOps provides reflog operations.
type RemoteListOps ¶
type RemoteListOps interface {
RemoteList(ctx context.Context) ([]Remote, error)
RemoteAdd(ctx context.Context, name, url string) error
RemoteRemove(ctx context.Context, name string) error
}
RemoteListOps provides remote listing and management operations.
type RemoteOps ¶
type RemoteOps interface {
Push(ctx context.Context, opts PushOpts) error
Pull(ctx context.Context, opts PullOpts) error
Fetch(ctx context.Context, opts FetchOpts) error
}
RemoteOps provides remote operations.
type ResetMode ¶
type ResetMode string
ResetMode specifies how git reset affects the index and working tree.
type RevertOps ¶
type RevertOps interface {
Revert(ctx context.Context, hash string) error
RevertContinue(ctx context.Context) error
RevertAbort(ctx context.Context) error
}
RevertOps provides commit revert operations.
type StashEntry ¶
StashEntry represents a single stash entry.
type StashOps ¶
type StashOps interface {
StashList(ctx context.Context) ([]StashEntry, error)
StashShow(ctx context.Context, index int) (string, error)
StashPush(ctx context.Context, opts StashOpts) error
StashPop(ctx context.Context, index int) error
StashApply(ctx context.Context, index int) error
StashDrop(ctx context.Context, index int) error
}
StashOps provides stash operations.
type StashOpts ¶
type StashOpts struct {
Message string
Paths []string // Specific paths to stash
KeepIndex bool
Staged bool
}
StashOpts configures a git stash push operation.
type StatusBranch ¶
StatusBranch holds parsed branch info from porcelain v2 header lines.
func ParseStatusBranch ¶
func ParseStatusBranch(output string) StatusBranch
ParseStatusBranch extracts branch metadata from porcelain v2 output.
type StatusCode ¶
type StatusCode byte
StatusCode represents the status of a file in the index or worktree.
const ( StatusUnmodified StatusCode = ' ' StatusModified StatusCode = 'M' StatusAdded StatusCode = 'A' StatusDeleted StatusCode = 'D' StatusRenamed StatusCode = 'R' StatusCopied StatusCode = 'C' StatusUntracked StatusCode = '?' StatusIgnored StatusCode = '!' StatusConflict StatusCode = 'U' )
func (StatusCode) String ¶
func (s StatusCode) String() string
String returns the single-character representation of the status code.
type StatusReader ¶
type StatusReader interface {
Status(ctx context.Context) ([]FileStatus, error)
Diff(ctx context.Context, opts DiffOpts) ([]FileDiff, error)
Log(ctx context.Context, opts LogOpts) ([]Commit, error)
Blame(ctx context.Context, path string) ([]BlameLine, error)
RepoRoot(ctx context.Context) (string, error)
IsRepo(ctx context.Context) (bool, error)
DiffTreeFiles(ctx context.Context, hash string) ([]string, error)
DiffFileNames(ctx context.Context, commitA, commitB string) ([]string, error)
}
StatusReader provides read-only git status queries.
type Tag ¶
type Tag struct {
Date time.Time
Name string
Hash string
Message string // Empty for lightweight tags
Tagger string
IsAnnotated bool
}
Tag represents a git tag.
type TagOps ¶
type TagOps interface {
TagList(ctx context.Context) ([]Tag, error)
TagCreate(ctx context.Context, name, ref, message string) error
TagDelete(ctx context.Context, name string) error
TagListRemote(ctx context.Context, remote string) ([]Tag, error)
TagPush(ctx context.Context, remote, name string) error
TagPushAll(ctx context.Context, remote string) error
}
TagOps provides tag operations.
type UndoAction ¶
type UndoAction struct {
Metadata map[string]string // Additional context keyed by operation type
Type string // "commit", "stage", "unstage", "branch_delete", "checkout", "discard", "revert", "reset", "amend"
RefBefore string // Git ref (hash) before the operation
}
UndoAction represents a recorded git operation that can be undone or redone. The Type field determines the undo strategy; Metadata carries type-specific context (e.g., file paths, branch names, commit messages).
type UndoManager ¶
type UndoManager struct {
// contains filtered or unexported fields
}
UndoManager provides undo/redo functionality for git operations. It maintains in-memory stacks of recorded actions and applies inverse operations on undo. Stacks are not persisted across application restarts. All methods are safe for concurrent use.
func NewUndoManager ¶
func NewUndoManager(client *Client) *UndoManager
NewUndoManager creates a new UndoManager for the given git client.
func (*UndoManager) CanRedo ¶
func (u *UndoManager) CanRedo() bool
CanRedo returns true if there are undone actions that can be reapplied.
func (*UndoManager) CanUndo ¶
func (u *UndoManager) CanUndo() bool
CanUndo returns true if there are actions that can be undone.
func (*UndoManager) NeedsConfirmation ¶
func (u *UndoManager) NeedsConfirmation() bool
NeedsConfirmation returns true if the next undo operation would be destructive and should require user confirmation via a modal dialog.
func (*UndoManager) PeekRedo ¶
func (u *UndoManager) PeekRedo() (UndoAction, bool)
PeekRedo returns the top redo action without removing it.
func (*UndoManager) PeekUndo ¶
func (u *UndoManager) PeekUndo() (UndoAction, bool)
PeekUndo returns the top undo action without removing it. Returns the action and true, or a zero value and false if the stack is empty.
func (*UndoManager) RecordAction ¶
func (u *UndoManager) RecordAction(action UndoAction)
RecordAction pushes a new undoable action onto the stack. Recording a new action clears the redo stack (linear history).
func (*UndoManager) Redo ¶
func (u *UndoManager) Redo(ctx context.Context) (string, error)
Redo re-applies the most recently undone action. Returns a human-readable description, or an error if the redo fails. On failure the action is restored to the redo stack.
func (*UndoManager) RedoNeedsConfirmation ¶
func (u *UndoManager) RedoNeedsConfirmation() bool
RedoNeedsConfirmation returns true if the next redo operation would be destructive and should require user confirmation.
func (*UndoManager) Undo ¶
func (u *UndoManager) Undo(ctx context.Context) (string, error)
Undo reverses the most recent recorded action. Returns a human-readable description of what was undone, or an error if the undo fails. On failure the action is restored to the undo stack so the user can retry.