Repository navigation
fix(flake): wire core.hooksPath to .githooks for direnv consumers - #1127
Merged
Merged
Conversation
The direnv/`nix develop` path never set `core.hooksPath`, so commit-time hooks were silently inactive until the consumer set it by hand. Add a `TestGithooksPathWiring` suite asserting the base dev-shell shellHook wires `core.hooksPath` -> `.githooks`, guards on a scaffold-shaped `.githooks/` dir and the main worktree, and never unsets it. Refine the #908 opt-in guard to allow the sanctioned `.githooks` set while still rejecting any other hooksPath mutation. Refs: #1112
In direnv / `nix develop` mode the dev-shell never set `core.hooksPath`, so commit-time hooks (pre-commit / commit-msg via prek) were silently inactive until the consumer set it by hand — a local commit could bypass the gate with only CI catching it later. Devcontainer mode already wired it in setup-git-conf.sh. mkProjectShell's base shellHook now runs `git config core.hooksPath .githooks` on shell entry, mirroring the devcontainer and reinforcing the `.githooks` single-entry-point invariant (#908) — it only ever sets `.githooks`, never unsets/resets it or installs into `.git/hooks`. It lives in the shared base so the default `hooks = null` shell and an opted-in shell change identically, keeping the zero-hooks parity. Guarded to a scaffold-shaped repo (`.githooks/` at the git toplevel) and to the main worktree (worktree git-dir == common git-dir), so it leaves non-scaffold consumers untouched and never fights the worktree flow (justfile.worktree deliberately unsets core.hooksPath and installs prek hooks directly in a linked worktree); idempotent on re-entry. Refs: #1112
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In direnv mode the scaffold never set
core.hooksPath, so commit-time hooks (pre-commit / commit-msg via prek) were silently inactive until the consumer set it by hand — a local commit could bypass the gate, with only CI catching violations later. Devcontainer mode already wires it (setup-git-conf.shrunsgit config core.hooksPath .githooks). The dev shell now mirrors that: entering the direnv /nix developshell wirescore.hooksPath→.githooksautomatically.Closes #1112
Type of Change
feat-- New featurefix-- Bug fixdocs-- Documentation onlychore-- Maintenance task (deps, config, etc.)refactor-- Code restructuring (no behavior change)test-- Adding or updating testsci-- CI/CD pipeline changesbuild-- Build system or dependency changesrevert-- Reverts a previous commitstyle-- Code style (formatting, whitespace)Modifiers
!) -- This change breaks backward compatibilityChanges Made
flake.nix: newgithooksPathHookfragment inmkProjectShell's shared base shellHook. Implemented here (not in the scaffolded.envrc) so every direnv consumer gets it on the next flake-pin bump without a re-scaffold, and the devkit's owndevShells.defaultexercises it. Three guards, each justified in the code comment:.githooks/must exist at the git toplevel — only scaffold-shaped repos are touched;justfile.worktree, which deliberately unsetscore.hooksPathand installs prek hooks directly; this guard keeps the shellHook from fighting that flow;.githooks— idempotent on re-entry.The hook only ever sets
.githooks— never unsets/resets it or installs into.git/hooks— reinforcing the feat(flake): generate .pre-commit-config.yaml from one flake hook definition, consumer-extensible #908 invariant that.githooksstays the single entry point.tests/test_flake_hooks.py: newTestGithooksPathWiringsuite (wiring present,.githooks-dir guard, main-worktree guard, never unsets) + the existing feat(flake): generate .pre-commit-config.yaml from one flake hook definition, consumer-extensible #908 guard test refined to allow the sanctioned.githookswrite while still rejecting any othercore.hooksPathmutation.docs/COMMIT_MESSAGE_STANDARD.md(SSoT;assets/workspace/mirror regenerated bysync-manifest): updated the "ifcore.hooksPathis unset the guard is silently absent" caveat — both sanctioned environments now wire it automatically.Changelog Entry
Fixed
core.hooksPath→.githooksautomatically (#1112)nix developconsumer never got it, so commit-time hooks (pre-commit / commit-msg via prek) were silently inactive until set by hand.mkProjectShell's base shellHook now sets it on shell entry, guarded to scaffold-shaped repos (a.githooks/dir), the main worktree (linked worktrees stay owned byjustfile.worktree's direct prek install), and idempotent re-entry; it only ever sets the sanctioned.githooksvalue (feat(flake): generate .pre-commit-config.yaml from one flake hook definition, consumer-extensible #908 invariant).Testing
just test)Manual Testing Details
test_default_shellhook_sets_core_hookspath_to_githookscommitted failing (RED), turned GREEN by the fix.tests/test_flake_hooks.py+tests/test_flake_devshell.py: 38 passed, 1 skipped (FHS-only leak guard, N/A on NixOS host) — implementation run + independent review run, re-run after merging currentdev(post podman-DooD flake change)..githooks→ set; linked worktree → left unset; no.githooks→ untouched; re-entry → idempotent.nix run .#nix-fast-build -- --flake ".#checks.x86_64-linux"→ exit 0 (includes treefmt/nixfmt + dev-shell build + git-hooks check). Downstream scaffold-stubnix flake check ./assets/workspace --override-input vigos "path:$PWD"→ all checks passed.prek run --all-files: green.Checklist
docs/templates/, then runjust docs)CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
Part of the commit-action-deployment bug batch. Shared-config semantics note:
core.hooksPathlives in the repo's shared config, so entering the main-worktree dev shell sets it repo-wide; in a linked worktree the.githooksentry point then also runsprek run, so hooks stay enforced either way — no functional regression, just an observation.Refs: #1112