gitsafe

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitsafe takes restorable snapshots of a git working tree without touching what belongs to the user: no commit on a branch, no change to the index or the stash list. A snapshot is a commit object (tracked and untracked, non-ignored files as they were) kept alive by a ref under refs/harness/snapshots/<thread>/<n>; Restore puts the tree, HEAD and the staged state back as they were. The harness takes one at the start of every run of the local backend so an agent's changes can be undone.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotRepo = errors.New("gitsafe: not a git repository")

ErrNotRepo is returned when the directory is not inside a git work tree (callers skip snapshots then).

Functions

func Changed

func Changed(ctx context.Context, dir, from, to string) ([]string, error)

Changed lists the paths whose content differs between two refs.

func Drop

func Drop(ctx context.Context, dir, thread string) error

Drop deletes the thread's snapshots and backups.

func RecordRun

func RecordRun(ctx context.Context, dir, thread, run string, s Snap) error

RecordRun remembers s as the snapshot taken before the run started.

func Toplevel

func Toplevel(ctx context.Context, dir string) (string, error)

Toplevel is the root of the work tree containing dir, or ErrNotRepo.

func Undo

func Undo(ctx context.Context, dir, thread string) (backup Snap, restored Snap, err error)

Undo restores the thread's latest snapshot.

Types

type Hook

type Hook struct {
	Dir string
}

Hook is an agent.RunStartHook that snapshots the repository of Dir before each run (nothing happens when Dir is not a git repository).

func (Hook) BeforeRun

func (h Hook) BeforeRun(ctx context.Context, run *store.Run)

BeforeRun implements agent.RunStartHook.

type Snap

type Snap struct {
	// Ref is refs/harness/snapshots/<thread>/<n>.
	Ref string
	// Commit is the snapshot commit (the working tree, with untracked files).
	Commit string
	// Head is the commit HEAD pointed at ("" in a repository without commits).
	Head string
	// Branch is the checked-out branch ("" when detached).
	Branch string
	// IndexTree is the tree of the staged state ("" if it could not be recorded).
	IndexTree string
	// Dir is the top level of the repository.
	Dir string
}

Snap is one snapshot.

func ForRun

func ForRun(ctx context.Context, dir, thread, run string) (Snap, error)

ForRun returns the snapshot taken before the run started; an error when none was recorded.

func Latest

func Latest(ctx context.Context, dir, thread string) (Snap, error)

Latest is the thread's most recent snapshot.

func List

func List(ctx context.Context, dir, thread string) ([]Snap, error)

List returns the thread's snapshots, oldest first.

func Restore

func Restore(ctx context.Context, dir, ref string) (backup Snap, err error)

Restore puts the repository containing dir back as it was at the snapshot ref (a ref of Snapshot, or any commit-ish): files changed, deleted or added since are reverted (ignored files are left alone), the branch is moved back to the recorded HEAD when commits were made since, and the staged state is restored. Before changing anything it saves the current state under refs/harness/backups/<thread>/<n>, returned so the undo can be undone.

func Snapshot

func Snapshot(ctx context.Context, dir, thread string) (Snap, error)

Snapshot records the working tree of the repository containing dir under refs/harness/snapshots/<thread>/<n> and returns it. Ignored files are not part of it. When nothing changed since the thread's latest snapshot, that snapshot is returned. It returns ErrNotRepo outside a repository.

Jump to

Keyboard shortcuts

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