Skip to main content

clean_worktree_rev

Function clean_worktree_rev 

Source
pub fn clean_worktree_rev(dir: &Path) -> Option<String>
Expand description

Fingerprint a local flake directory’s git state for eval-cache keying.

Returns Some(head_rev) iff dir is a git worktree with NO uncommitted changes to TRACKED files (clean) — the committed rev then fully identifies everything a git flake’s self.rev/self.lastModified exposes AND the tree’s tracked content (a git flake’s source excludes untracked files, so they are correctly ignored here, matching nix’s flake-source semantics).

Returns None when the tree is DIRTY (its self.dirtyShortRev hashes the whole working tree — content the eval-cache key cannot cheaply capture) or is not a git repo. The caller treats None as “do not cache”, so a stale self-derived byte (e.g. darwin-system-…dirty served after a commit) can never be returned from the cache across a git-state change.

Uses git diff --quiet HEAD (exit 0 = clean, 1 = dirty, other = not-a-repo / no-HEAD) — the cheapest reliable tracked-changes check.