Documentation
¶
Overview ¶
Package snapshot provides git worktree-based snapshots for hermetic planning. Each layer source is pinned to a commit hash, and the planner reads from a detached worktree at that hash. This guarantees immutability during planning: uncommitted changes, staged files, and untracked files are invisible.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckClean ¶
func CheckClean(sources []tree.LayerSource) ([]string, error)
CheckClean verifies that all unique repositories in the given sources have clean working trees. Returns an error listing all dirty repos if any are found.
Parameters:
- sources: layer sources to check
Returns:
- []string: layer names that are dirty (nil if all clean)
- error: git command failure
func Hashes ¶
Hashes returns a layer→hash map from the given snapshots. Suitable for recording in GraphContext.CommitHashes.
Parameters:
- snapshots: pinned snapshots
Returns:
- map[string]string: layer name to full commit hash
func IsDirty ¶
IsDirty reports whether the working tree at repoPath has uncommitted changes. Checks for staged, unstaged, and untracked files via `git status --porcelain`.
Parameters:
- repoPath: path to the git repository
Returns:
- bool: true if the working tree has uncommitted changes
- error: git command failure
func RewriteSources ¶
func RewriteSources(sources []tree.LayerSource, snapshots []*Snapshot) []tree.LayerSource
RewriteSources returns a copy of sources with SourceRoot rewritten to point at the corresponding worktree path. Each source's SourceRoot is the repo path plus a subdirectory (e.g., /repo/Home); the rewrite replaces the repo prefix with the worktree path, preserving the subdirectory.
Parameters:
- sources: original layer sources
- snapshots: pinned snapshots from PinAll
Returns:
- []tree.LayerSource: sources with SourceRoot pointing to worktree paths
Types ¶
type Snapshot ¶
type Snapshot struct {
// Layer is the layer name ("base", "team", "personal").
Layer string
// RepoPath is the original repository path.
RepoPath string
// CommitHash is the full commit hash this worktree is pinned to.
CommitHash string
// WorktreePath is the path to the detached worktree directory.
WorktreePath string
}
Snapshot represents a git worktree pinned to a specific commit.
func Pin ¶
Pin creates a detached git worktree pinned to HEAD for the given repository. The worktree is placed under ${XDG_CACHE_HOME}/devlore/snapshots/<layer>-<hash[:12]>/.
Parameters:
- repoPath: path to the git repository
- layer: layer name for directory naming ("base", "team", "personal")
Returns:
- *Snapshot: the pinned snapshot
- error: git command failure or directory creation error
func PinAll ¶
func PinAll(sources []tree.LayerSource) ([]*Snapshot, func(), error)
PinAll pins each unique repository from the given layer sources. Repositories are deduplicated by path — base, team, and personal may share a repo. Returns the snapshots and a cleanup function that closes all of them.
Parameters:
- sources: layer sources from CollectLayerSources
Returns:
- []*Snapshot: one snapshot per unique repository
- func(): cleanup function that closes all snapshots
- error: first pinning error encountered