On this page
Package index manages per-invocation temporary git indexes so each safegit invocation stages into its own index seeded from HEAD, avoiding contention.
#internal/index
#internal/index
Package index manages per-invocation temporary git indexes so each safegit invocation stages into its own index seeded from HEAD, avoiding contention. No safegit operation writes to the shared .git/index; all staging goes through temporary indexes created here.
#TmpIndex
type TmpIndex structTmpIndex represents a per-invocation temporary index directory.
#New
func New(ctx context.Context, baseDir string, treeish string) (*TmpIndex, error)New creates a temporary index directory under baseDir/tmp/ and seeds the index from the given treeish.
#NewEmpty
func NewEmpty(baseDir string) (*TmpIndex, error)NewEmpty creates a temporary index directory with an empty index (no tree). Used for root commits in repos with no prior commits. baseDir has the same meaning as in New.
#NewFromFile
func NewFromFile(baseDir, srcIndexPath string) (*TmpIndex, error)NewFromFile creates a temporary index directory whose index starts as a byte copy of an existing index file -- in practice the repository's shared .git/index, which is where git records a conflict resolution the operator has staged. Copying is what keeps safegit's promise never to write to that file: the copy is what gets staged into and written out as a tree, and the original is only ever read.
The copy carries whatever the source held, unmerged stage entries included; a caller that copies a conflicted index and then asks for a tree gets git's own refusal to write one, which is the honest answer.
#GarbageCollectPlan
func GarbageCollectPlan(safegitDir string) ([]string, error)GarbageCollectPlan reports the tmp directories whose owning PID is no longer alive, as full PATHS, and removes nothing.
It is the whole scanner: the caller decides what to do with what it found. That split is what lets safegit doctor diagnose with it, preview with it, and repair with it -- the repair removing each planned path through the effects handle, so a dry run records the removals it would make instead of making them, and machine mode carries them. A scanner that removed as it walked could not be asked what it would do without doing it.
#TmpIndex.Cleanup
func (t *TmpIndex) Cleanup() errorCleanup removes the temporary index directory.