fix(state): auto-commit died on dead legacy pathspecs after #107

Since d8e1a13 removed theme-state.json, auto_commit's fixed pathspec
(state.json + both legacy names) made `git commit` abort — unlike
`git diff`, commit errors on a pathspec that matches nothing — so every
per-mutation settings commit was silently "skipped" and state.json
stayed dirty until a lifecycle sweep caught it. Filter the legacy names
down to those git still knows (index or HEAD — a migration's staged
`git rm` still rides along). checks.auto-theme now runs its state dir
as a git repo with autoCommit on and asserts each set/apply lands as
its own commit leaving nothing dirty — the exact post-#107 repo shape
that used to abort. state-sync 0.5.0 → 0.5.1.

V2: nix build .#checks.x86_64-linux.auto-theme (KVM VM run, passed,
including the new git assertions); the built tool was also exercised
against a clone of a real post-#107 machine flake — the set
auto-committed and the tree stayed clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-18 22:30:50 +01:00
parent 8f85097140
commit ac24ac7c34
3 changed files with 42 additions and 6 deletions

View File

@@ -16,7 +16,7 @@
stdenvNoCC.mkDerivation {
pname = "nomarchy-state-sync";
version = "0.5.0";
version = "0.5.1";
src = ./.;

View File

@@ -189,8 +189,17 @@ def auto_commit(message: str) -> None:
if not (FLAKE_DIR / ".git").exists() or shutil.which("git") is None:
return
git = ["git", "-C", str(FLAKE_DIR)]
# Pathspec: preferred name plus any leftover legacy file still staged.
paths = [STATE_NAME, *LEGACY_STATE_NAMES]
# Pathspec: preferred name plus any legacy file git still knows — in the
# index or in HEAD (a migration's staged `git rm` needs the pathspec to
# ride along). Names known to neither MUST be dropped: unlike `git diff`,
# `git commit` aborts on a pathspec that matches nothing, which silently
# killed every auto-commit once the #107 rename removed the legacy files.
def known(name: str) -> bool:
return subprocess.run(git + ["ls-files", "--error-unmatch", "--", name],
capture_output=True).returncode == 0 \
or subprocess.run(git + ["cat-file", "-e", f"HEAD:{name}"],
capture_output=True).returncode == 0
paths = [STATE_NAME] + [n for n in LEGACY_STATE_NAMES if known(n)]
# No-op when the file already matches HEAD (a `set` to the same value).
# On a repo with no commits yet this diff errors — then just commit.
if subprocess.run(git + ["diff", "--quiet", "HEAD", "--"] + paths,