checkpoint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const Cap = 50

Cap on stored checkpoints per repo. Older entries pruned.

Variables

This section is empty.

Functions

func LatestStashRef

func LatestStashRef(ctx context.Context) string

LatestStashRef returns sha of stash@{0} (the just-pushed stash).

Types

type FileBackup

type FileBackup struct {
	Path       string `json:"path"`
	BackupPath string `json:"backup_path"`
}

FileBackup records a single file backed up before overwrite.

type Op

type Op struct {
	ID              string            `json:"id"`
	Timestamp       time.Time         `json:"timestamp"`
	Command         string            `json:"command"`
	OpType          string            `json:"op_type"`
	Branch          string            `json:"branch,omitempty"`
	HeadBefore      string            `json:"head_before,omitempty"`
	HeadAfter       string            `json:"head_after,omitempty"`
	BackupRef       string            `json:"backup_ref,omitempty"`
	StashRef        string            `json:"stash_ref,omitempty"`
	Remote          string            `json:"remote,omitempty"`
	RemoteBranch    string            `json:"remote_branch,omitempty"`
	RemoteSHABefore string            `json:"remote_sha_before,omitempty"`
	RemoteSHAAfter  string            `json:"remote_sha_after,omitempty"`
	PRNumber        string            `json:"pr_number,omitempty"`
	PRURL           string            `json:"pr_url,omitempty"`
	FilesWritten    []FileBackup      `json:"files_written,omitempty"`
	Args            map[string]string `json:"args,omitempty"`
	Reversible      bool              `json:"reversible"`
	ReasonIfNot     string            `json:"reason_if_not,omitempty"`
	Status          string            `json:"status"`
	Note            string            `json:"note,omitempty"`
}

Op is a single recorded mutation. Status: pending|done|failed|undone. OpType: commit|rebase|merge|stash|push|pr_create|file_write.

type Recorder

type Recorder struct {
	Store    *Store
	RepoRoot string
}

Recorder wraps Store with helpers to capture git state and create backups.

func NewRecorder

func NewRecorder(repoRoot string) *Recorder

func (*Recorder) BackupFile

func (r *Recorder) BackupFile(op *Op, path string) error

BackupFile copies file to .gitmate/backups/<id>/<flat-path> and records it. Used before overwriting a file (e.g., conflict resolution write).

func (*Recorder) Begin

func (r *Recorder) Begin(ctx context.Context, command, opType string) *Op

Begin creates an Op with a fresh ID, captures HEAD + branch, and returns it. Caller fills extra fields then calls Commit/Fail.

func (*Recorder) CaptureRemoteSha

func (r *Recorder) CaptureRemoteSha(ctx context.Context, op *Op, remote, branch string)

CaptureRemoteSha records the remote tip so an undo can force-with-lease back.

func (*Recorder) Commit

func (r *Recorder) Commit(ctx context.Context, op *Op) error

Commit finalizes Op as done, captures HEAD-after, and persists.

func (*Recorder) CreateBackupRef

func (r *Recorder) CreateBackupRef(ctx context.Context, op *Op)

CreateBackupRef sets refs/gitmate/backup/<id> to current HEAD so destructive rebase/merge can be reset later. Best-effort; failure does not block op.

func (*Recorder) Fail

func (r *Recorder) Fail(ctx context.Context, op *Op, errMsg string)

Fail marks Op failed and persists. Cleans up backup ref since op did not land.

func (*Recorder) MarkIrreversible

func (r *Recorder) MarkIrreversible(op *Op, reason string)

MarkIrreversible sets reversible=false with reason.

type Store

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

Store persists Ops as JSON in <repo>/.gitmate/checkpoints.json.

func NewStore

func NewStore(repoRoot string) *Store

func (*Store) Append

func (s *Store) Append(op Op) error

Append adds op to store. Caller fills fields beforehand.

func (*Store) Get

func (s *Store) Get(id string) (*Op, error)

Get fetches op by id.

func (*Store) LastUndoable

func (s *Store) LastUndoable() (*Op, error)

LastUndoable returns most recent op that can still be undone.

func (*Store) List

func (s *Store) List() ([]Op, error)

List returns ops newest-first.

func (*Store) Path

func (s *Store) Path() string

func (*Store) Update

func (s *Store) Update(op Op) error

Update overwrites op with matching ID.

Jump to

Keyboard shortcuts

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