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 ¶
- Variables
- func Changed(ctx context.Context, dir, from, to string) ([]string, error)
- func Drop(ctx context.Context, dir, thread string) error
- func RecordRun(ctx context.Context, dir, thread, run string, s Snap) error
- func Toplevel(ctx context.Context, dir string) (string, error)
- func Undo(ctx context.Context, dir, thread string) (backup Snap, restored Snap, err error)
- type Hook
- type Snap
- func ForRun(ctx context.Context, dir, thread, run string) (Snap, error)
- func Latest(ctx context.Context, dir, thread string) (Snap, error)
- func List(ctx context.Context, dir, thread string) ([]Snap, error)
- func Restore(ctx context.Context, dir, ref string) (backup Snap, err error)
- func Snapshot(ctx context.Context, dir, thread string) (Snap, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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).
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 ¶
ForRun returns the snapshot taken before the run started; an error when none was recorded.
func Restore ¶
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 ¶
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.