safegit v0.26.0
On this page

safegit: a concurrency-safe Git wrapper CLI that isolates commits via per-invocation indexes, enabling multiple AI agent sessions to share one repo.

#safegit

Concurrency-safe git operations for multi-session worktrees.

#API Reference

safegit exposes its functionality through a set of subcommands designed for scripted and interactive use. Each command is documented below with its flags, arguments, and behavior. The reference is auto-generated from the source tree and reflects the current state of the codebase.

#.

Package main is the entry point for the safegit CLI, a concurrency-safe git wrapper that isolates commits via per-invocation temporary indexes.

#ScrubVerifyPolicyResult

Go go
type ScrubVerifyPolicyResult struct

ScrubVerifyPolicyResult is the per-policy result for JSON output.

#ScrubVerifyResult

Go go
type ScrubVerifyResult struct

ScrubVerifyResult is the top-level JSON output for scrub verify.

#Recipe

Go go
type Recipe struct

Recipe is the raw TOML schema for a scrub recipe file.

#RecipeOperation

Go go
type RecipeOperation struct

RecipeOperation is a single operation within a recipe.

#ParsedRecipe

Go go
type ParsedRecipe struct

ParsedRecipe is the validated, compiled form of a Recipe.

#RewriteAuthorResult

Go go
type RewriteAuthorResult struct

RewriteAuthorResult is the JSON output for rewrite-author in execute mode.

#RewriteAuthorDryRunResult

Go go
type RewriteAuthorDryRunResult struct

RewriteAuthorDryRunResult is the JSON output for rewrite-author --dry-run.

#RewriteMapStart

Go go
type RewriteMapStart struct

RewriteMapStart is the phase-"start" record.

#RewriteMapRefs

Go go
type RewriteMapRefs struct

RewriteMapRefs is the phase-"refs" record.

#RewriteMapComplete

Go go
type RewriteMapComplete struct

RewriteMapComplete is the phase-"complete" record.

#AnnotationRewriteFunc

Go go
type AnnotationRewriteFunc func(ctx context.Context, shaMap map[string]string) ([]TagRewrite, int, error)

AnnotationRewriteFunc rewrites tag annotation text after refs have been updated. It receives the old-to-new SHA map for commit reference remapping and returns the tag rewrite records it produced plus the count of tags whose annotations were rewritten, so Finalize can persist and expose them.

#VerifyFunc

Go go
type VerifyFunc func(ctx context.Context) error

VerifyFunc performs command-specific post-rewrite verification (e.g., re-scanning for secrets, comparing author snapshots).

#RewriteResult

Go go
type RewriteResult struct

RewriteResult collects the outputs of a history rewrite so that Finalize can execute the shared post-rewrite pipeline (ref updates, cleanup, verification, oplog, push hint).

#ScanResult

Go go
type ScanResult struct

ScanResult is the JSON output for safegit scan.

#ScanMatchJSON

Go go
type ScanMatchJSON struct

ScanMatchJSON is a single match in JSON output.

#ScrubFileResult

Go go
type ScrubFileResult struct

ScrubFileResult is the JSON output for scrub file in execute mode.

#ScrubFileDryRunResult

Go go
type ScrubFileDryRunResult struct

ScrubFileDryRunResult is the JSON output for scrub file --dry-run.

#TagBodyTransformFunc

Go go
type TagBodyTransformFunc func(refname, header, body string) (newBody string, err error)

TagBodyTransformFunc transforms the body of an annotated tag. It receives the tag's refname, full header text, and body text. It returns the new body (or the same body if no change is needed) and any error.

#ScrubMatchResult

Go go
type ScrubMatchResult struct

ScrubMatchResult is the JSON output for scrub match in execute mode.

#ScrubMatchDryRunResult

Go go
type ScrubMatchDryRunResult struct

ScrubMatchDryRunResult is the JSON output for scrub match --dry-run.

#ScrubPolicy

Go go
type ScrubPolicy struct

ScrubPolicy records a scrub operation's pattern so that future verification can confirm the secret remains absent from the object store.

#ScrubRunResult

Go go
type ScrubRunResult struct

ScrubRunResult is the JSON output for scrub run in execute mode.

#ScrubRunDiffEntry

Go go
type ScrubRunDiffEntry struct

ScrubRunDiffEntry is a single blob diff in --diff preview output.

#ScrubRunDiffResult

Go go
type ScrubRunDiffResult struct

ScrubRunDiffResult is the JSON output for scrub run --diff.

#MessageDiffEntry

Go go
type MessageDiffEntry struct

MessageDiffEntry is a commit message diff in --diff preview output.

#ScrubRunDryRunOpResult

Go go
type ScrubRunDryRunOpResult struct

ScrubRunDryRunOpResult holds per-operation match counts for --dry-run output.

#ScrubRunDryRunResult

Go go
type ScrubRunDryRunResult struct

ScrubRunDryRunResult is the JSON output for scrub run --dry-run.

#TagRewrite

Go go
type TagRewrite struct

TagRewrite records how a tag ref was updated during history rewriting.

#CommitTransform

Go go
type CommitTransform struct

CommitTransform describes how a commit should be rewritten. Zero/empty fields mean "keep the original value."

#TransformFunc

Go go
type TransformFunc func(ctx context.Context, sha string, info git.CommitInfo, remappedParents []string, shaMap map[string]string) (CommitTransform, error)

TransformFunc is called for each commit during a rewrite walk. It receives the original commit SHA, its parsed info, the already-remapped parent SHAs, and the growing old-to-new SHA map (which includes identity entries for already-walked unchanged commits; transforms must treat it as read-only — the walker owns it). It returns a CommitTransform describing what (if anything) to change.

#BuildRecipeBlobContent

Go go
func BuildRecipeBlobContent(ctx context.Context, recipe *ParsedRecipe, blobSHAs []string, blobAllowedOps map[string]map[int]bool) (map[string][]byte, error)

BuildRecipeBlobContent applies a parsed recipe to a set of blobs, producing a mapping from old blob SHA to modified content bytes. It reads each blob, applies recipe operations in memory, and returns only blobs whose content changed. No objects are written to the object store -- this is purely in-memory content computation for dry-run and diff use cases.

blobAllowedOps optionally restricts which operations apply to each blob. When nil, all operations apply to all blobs. When set, only operations whose index is in blobAllowedOps[blobSHA] are applied to that blob. This is used to enforce per-operation scope filters from recipe TOML files.

#RewriteResult.Finalize

Go go
func (r *RewriteResult) Finalize(ctx context.Context, flags globalFlags, cmd string, annotationRewriteFunc AnnotationRewriteFunc, verifyFunc VerifyFunc) error

Finalize runs the shared post-rewrite pipeline. The execution order is:

0. Persist the rewrite-map "start" record (commit map + pre-rewrite remote-tracking state) BEFORE any refs move, so a crash at any later step leaves the mapping recoverable 1. updateRefs — update branch and tag refs to point at rewritten commits 2. annotationRewriteFunc — rewrite tag annotation text (nil to skip) 2.5. Persist the rewrite-map "refs" record (all tag rewrites) 3. SyncMainIndexWithWorktree — sync the shared index with rewritten HEAD 4. untrackProtectedPaths — remove tracked-but-gitignored files from index 5. cleanupAfterRewrite — expire tainted reflog entries, repack, prune 6. verifyFunc — command-specific verification (nil to skip) 7. Resolve new HEAD SHA 8. Resolve current ref 8.5. Persist the rewrite-map "complete" record (new HEAD, cleanup status) 9. oplog.Append — record the operation 9.5. Append scrub policy to the untracked policy file 10. Push hint — print rlsbl-aware or default push instructions

Search