git

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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

func JoinPaths(paths []string) string

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

func RemoteToHTTPS(raw string) string

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

func ValidateArg(arg string) error

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

func ValidatePath(path string) error

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

func ValidateRef(ref string) error

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

func ValidateRepoRelativePath(path string) error

ValidateRepoRelativePath validates a repository-relative path for mutating git operations that must never accept absolute filesystem paths.

func WorktreePath

func WorktreePath(repoRoot, branch string) string

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 BlameLine

type BlameLine struct {
	Date    time.Time
	Hash    string
	Author  string
	Content string
	LineNo  int
}

BlameLine represents a single line from git blame output.

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 NewCache

func NewCache(maxAge time.Duration) *Cache

NewCache creates a Cache with the given maximum age for cached data.

func (*Cache) GetBranches

func (c *Cache) GetBranches() ([]Branch, bool)

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) Invalidate

func (c *Cache) Invalidate()

Invalidate clears all cached data.

func (*Cache) SetBranches

func (c *Cache) SetBranches(branches []Branch)

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

func NewClient(repoDir string) (*Client, error)

NewClient creates a new Client for the repository at repoDir. It verifies that git is installed and the directory exists.

func NewClientWithCache

func NewClientWithCache(repoDir string, cache *Cache) (*Client, error)

NewClientWithCache creates a new Client with caching enabled.

func (*Client) BisectBad

func (c *Client) BisectBad(ctx context.Context) (string, error)

BisectBad marks the current revision as bad. Returns the next revision to test or a message indicating the bisect is done.

func (*Client) BisectGood

func (c *Client) BisectGood(ctx context.Context) (string, error)

BisectGood marks the current revision as good. Returns the next revision to test or a message indicating the bisect is done.

func (*Client) BisectReset

func (c *Client) BisectReset(ctx context.Context) error

BisectReset ends the bisect session and returns to the original HEAD.

func (*Client) BisectStart

func (c *Client) BisectStart(ctx context.Context, bad, good string) error

BisectStart begins a bisect session between a bad and good commit.

func (*Client) Blame

func (c *Client) Blame(ctx context.Context, path string) ([]BlameLine, error)

Blame returns line-by-line blame information for a file.

func (*Client) BranchCreate

func (c *Client) BranchCreate(ctx context.Context, name, base string) error

BranchCreate creates a new branch from base (or HEAD if base is empty).

func (*Client) BranchDelete

func (c *Client) BranchDelete(ctx context.Context, name string, force bool) error

BranchDelete deletes a branch. Use force=true for -D (force delete).

func (*Client) BranchList

func (c *Client) BranchList(ctx context.Context) ([]Branch, error)

BranchList returns all local and remote branches.

func (*Client) BranchRename

func (c *Client) BranchRename(ctx context.Context, oldName, newName string) error

BranchRename renames a branch from oldName to newName. If oldName is empty, renames the current branch.

func (*Client) Checkout

func (c *Client) Checkout(ctx context.Context, ref string) error

Checkout switches branches or restores working tree files.

func (*Client) CherryPick

func (c *Client) CherryPick(ctx context.Context, commitHash string) error

CherryPick applies a commit by hash to the current branch.

func (*Client) Commit

func (c *Client) Commit(ctx context.Context, msg string, opts CommitOpts) (string, error)

Commit creates a new commit with the given message and options. Returns the commit hash on success.

func (*Client) Diff

func (c *Client) Diff(ctx context.Context, opts DiffOpts) ([]FileDiff, error)

Diff returns file diffs for the repository.

func (*Client) DiffFileNames added in v0.0.2

func (c *Client) DiffFileNames(ctx context.Context, commitA, commitB string) ([]string, error)

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

func (c *Client) DiffTreeFiles(ctx context.Context, hash string) ([]string, error)

DiffTreeFiles returns the list of files changed in a commit.

func (*Client) DiscardAllUnstaged

func (c *Client) DiscardAllUnstaged(ctx context.Context) error

DiscardAllUnstaged discards all unstaged changes in the working tree.

func (*Client) DiscardFile

func (c *Client) DiscardFile(ctx context.Context, path string) error

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) Fetch

func (c *Client) Fetch(ctx context.Context, opts FetchOpts) error

Fetch downloads objects and refs from a remote.

func (*Client) IgnoredPaths

func (c *Client) IgnoredPaths(ctx context.Context) ([]string, error)

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) IsRepo

func (c *Client) IsRepo(ctx context.Context) (bool, error)

IsRepo checks whether the working directory is inside a git repository.

func (*Client) Log

func (c *Client) Log(ctx context.Context, opts LogOpts) ([]Commit, error)

Log returns commits from git log.

func (*Client) Merge

func (c *Client) Merge(ctx context.Context, branch string, opts MergeOpts) error

Merge merges a branch into the current branch.

func (*Client) MergeAbort

func (c *Client) MergeAbort(ctx context.Context) error

MergeAbort aborts a merge in progress.

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, opts PullOpts) error

Pull fetches and integrates changes from a remote.

func (*Client) Push

func (c *Client) Push(ctx context.Context, opts PushOpts) error

Push pushes commits to a remote.

func (*Client) Rebase

func (c *Client) Rebase(ctx context.Context, onto string, opts RebaseOpts) error

Rebase rebases the current branch onto the given ref.

func (*Client) RebaseAbort

func (c *Client) RebaseAbort(ctx context.Context) error

RebaseAbort aborts a rebase in progress.

func (*Client) RebaseContinue

func (c *Client) RebaseContinue(ctx context.Context) error

RebaseContinue continues a rebase in progress.

func (*Client) Reflog

func (c *Client) Reflog(ctx context.Context, ref string, limit int) ([]ReflogEntry, error)

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) RemoteAdd

func (c *Client) RemoteAdd(ctx context.Context, name, url string) error

RemoteAdd adds a new remote with the given name and URL.

func (*Client) RemoteList

func (c *Client) RemoteList(ctx context.Context) ([]Remote, error)

RemoteList returns all configured remotes with their fetch and push URLs.

func (*Client) RemoteRemove

func (c *Client) RemoteRemove(ctx context.Context, name string) error

RemoteRemove removes a remote by name.

func (*Client) RepoDir

func (c *Client) RepoDir() string

RepoDir returns the repository working directory.

func (*Client) RepoRoot

func (c *Client) RepoRoot(ctx context.Context) (string, error)

RepoRoot returns the top-level directory of the repository.

func (*Client) Reset

func (c *Client) Reset(ctx context.Context, ref string, mode ResetMode) error

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

func (c *Client) Revert(ctx context.Context, hash string) error

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

func (c *Client) RevertAbort(ctx context.Context) error

RevertAbort aborts an in-progress revert and restores the previous state.

func (*Client) RevertContinue

func (c *Client) RevertContinue(ctx context.Context) error

RevertContinue continues a revert after conflicts have been resolved.

func (*Client) Stage

func (c *Client) Stage(ctx context.Context, paths []string) error

Stage adds files to the index.

func (*Client) StageHunk

func (c *Client) StageHunk(ctx context.Context, path string, hunk Hunk) error

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

func (c *Client) StageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error

StageLine stages a single diff line from an unstaged hunk by constructing a synthetic patch containing only that line's change.

func (*Client) StashApply

func (c *Client) StashApply(ctx context.Context, index int) error

StashApply applies (but does not remove) the stash entry at the given index.

func (*Client) StashDrop

func (c *Client) StashDrop(ctx context.Context, index int) error

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) StashPop

func (c *Client) StashPop(ctx context.Context, index int) error

StashPop applies and removes the stash entry at the given index.

func (*Client) StashPush

func (c *Client) StashPush(ctx context.Context, opts StashOpts) error

StashPush creates a new stash entry.

func (*Client) StashShow

func (c *Client) StashShow(ctx context.Context, index int) (string, error)

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

func (c *Client) TagCreate(ctx context.Context, name, ref, message string) error

TagCreate creates a new tag. If message is non-empty, creates an annotated tag.

func (*Client) TagDelete

func (c *Client) TagDelete(ctx context.Context, name string) error

TagDelete removes a tag.

func (*Client) TagList

func (c *Client) TagList(ctx context.Context) ([]Tag, error)

TagList returns all tags in the repository.

func (*Client) TagListRemote

func (c *Client) TagListRemote(ctx context.Context, remote string) ([]Tag, error)

TagListRemote discovers tags on a remote using ls-remote. It returns tags that exist on the remote but not locally.

func (*Client) TagPush

func (c *Client) TagPush(ctx context.Context, remote, name string) error

TagPush pushes a single tag to a remote.

func (*Client) TagPushAll

func (c *Client) TagPushAll(ctx context.Context, remote string) error

TagPushAll pushes all tags to a remote.

func (*Client) Unstage

func (c *Client) Unstage(ctx context.Context, paths []string) error

Unstage removes files from the index (resets to HEAD).

func (*Client) UnstageHunk

func (c *Client) UnstageHunk(ctx context.Context, path string, hunk Hunk) error

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

func (c *Client) UnstageLine(ctx context.Context, path string, hunk Hunk, lineIdx int) error

UnstageLine unstages a single diff line from a staged hunk by constructing a synthetic patch and applying it in reverse.

func (*Client) WorktreeAdd

func (c *Client) WorktreeAdd(ctx context.Context, path, branch string) error

WorktreeAdd creates a new worktree at the given path for the specified branch.

func (*Client) WorktreeList

func (c *Client) WorktreeList(ctx context.Context) ([]Worktree, error)

WorktreeList returns all worktrees for the repository.

func (*Client) WorktreeRemove

func (c *Client) WorktreeRemove(ctx context.Context, path string, force bool) error

WorktreeRemove removes a worktree at the given path.

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 FetchOpts

type FetchOpts struct {
	Remote string
	Prune  bool
	Tags   bool
	All    bool
}

FetchOpts configures a git fetch operation.

type FileDiff

type FileDiff struct {
	Path     string
	OldPath  string // For renames
	Hunks    []Hunk
	IsBinary bool
}

FileDiff represents the diff output for a single file.

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 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

type IgnoreChecker interface {
	IgnoredPaths(ctx context.Context) ([]string, error)
}

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 MergeOpts

type MergeOpts struct {
	Message string
	NoFF    bool
	FFOnly  bool
	Squash  bool
}

MergeOpts configures a git merge 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.

func (*OpQueue) Exec

func (q *OpQueue) Exec(ctx context.Context, fn func() error) error

Exec runs fn while holding the queue lock. Only one index-mutating operation can run at a time per repository. The context is checked before acquiring the lock; if the context is already cancelled the operation is skipped.

type PullOpts

type PullOpts struct {
	Remote   string
	Branch   string
	Rebase   bool
	NoRebase bool
}

PullOpts configures a git pull operation.

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

type ReflogEntry struct {
	Date    time.Time
	Hash    string
	Action  string
	Message string
}

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 Remote

type Remote struct {
	Name     string
	FetchURL string
	PushURL  string
}

Remote represents a configured git remote.

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.

const (
	ResetSoft  ResetMode = "soft"
	ResetMixed ResetMode = "mixed"
	ResetHard  ResetMode = "hard"
)

type ResetOps

type ResetOps interface {
	Reset(ctx context.Context, ref string, mode ResetMode) error
}

ResetOps provides reset operations with mode control.

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

type StashEntry struct {
	Date    time.Time
	Message string
	Branch  string
	Hash    string
	Index   int
}

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

type StatusBranch struct {
	OID      string
	Head     string
	Upstream string
	Ahead    int
	Behind   int
}

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.

type Worktree

type Worktree struct {
	Path   string
	Head   string
	Branch string
	Bare   bool
}

Worktree represents a git worktree entry.

type WorktreeOps

type WorktreeOps interface {
	WorktreeList(ctx context.Context) ([]Worktree, error)
	WorktreeAdd(ctx context.Context, path, branch string) error
	WorktreeRemove(ctx context.Context, path string, force bool) error
}

WorktreeOps provides worktree operations.

Jump to

Keyboard shortcuts

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