rollback

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rollback provides a commit chain browser for M31A sessions. It lists session commits, supports soft and hard resets to any point in the chain, and creates backup branches before destructive operations.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidHash = errors.New("invalid commit hash")

ErrInvalidHash is returned when a commit hash is not found in the repository.

Functions

This section is empty.

Types

type Rollback

type Rollback struct {
	// contains filtered or unexported fields
}

Rollback provides safe commit rollback operations.

func New

func New(g *git.Git) *Rollback

New creates a new Rollback instance backed by the given git wrapper.

func (*Rollback) Chain

func (r *Rollback) Chain(limit int) ([]RollbackEntry, error)

Chain returns up to `limit` commits newest-first with their diffs to HEAD. If limit <= 0, defaults to 20. The current HEAD is at index 0. Returns an empty slice for empty repos without error.

func (*Rollback) CurrentHead

func (r *Rollback) CurrentHead() (string, error)

CurrentHead returns the full SHA of the current HEAD commit.

func (*Rollback) HardReset

func (r *Rollback) HardReset(hash string) (*RollbackResult, error)

HardReset performs a git reset --hard to the given commit. If uncommitted changes exist, they are stashed first. C-11: Creates a timestamped backup branch before the destructive reset.

func (*Rollback) HasUncommittedChanges

func (r *Rollback) HasUncommittedChanges() (bool, error)

HasUncommittedChanges returns true if the working tree has uncommitted changes (modified, staged, untracked, or deleted files). Uses porcelain format for reliable, locale-independent parsing.

func (*Rollback) Preview

func (r *Rollback) Preview(hash string) (string, error)

Preview returns the diff between the given commit hash and HEAD. Output is capped at types.BashOutputLimit (50,000 characters).

func (*Rollback) SafeReset

func (r *Rollback) SafeReset(hash string) (*RollbackResult, error)

SafeReset performs a git reset --hard to the given commit and then pops the stash to preserve any uncommitted changes.

func (*Rollback) SoftReset

func (r *Rollback) SoftReset(hash string, onReset func(newHead string) error) (*RollbackResult, error)

SoftReset performs a git reset --soft to the given commit. If uncommitted changes exist, they are stashed first. The onReset callback, if non-nil, is called after the reset succeeds with the new HEAD hash. Use this to sync TASKS.md status updates (M-28).

type RollbackEntry

type RollbackEntry struct {
	CommitInfo    git.CommitInfo `json:"commit_info"`
	Diff          string         `json:"diff"`
	IsCurrent     bool           `json:"is_current"`
	HasCheckpoint bool           `json:"has_checkpoint"`
}

RollbackEntry represents a single commit in the rollback chain.

type RollbackResult

type RollbackResult struct {
	Success        bool   `json:"success"`
	PreviousHead   string `json:"previous_head"`
	NewHead        string `json:"new_head"`
	ChangesStashed bool   `json:"changes_stashed"`
	Message        string `json:"message"`
}

RollbackResult represents the outcome of a reset operation.

Jump to

Keyboard shortcuts

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