Skip to content

fix(flake): wire core.hooksPath to .githooks for direnv consumers - #1127

Merged
c-vigo merged 4 commits into
devfrom
bugfix/1112-direnv-hookspath
Jul 15, 2026
Merged

c-vigo merged 4 commits into
devfrom
bugfix/1112-direnv-hookspath

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

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.sh runs git config core.hooksPath .githooks). The dev shell now mirrors that: entering the direnv / nix develop shell wires core.hooksPath → .githooks automatically.

Closes #1112

Type of Change

  • feat -- New feature
  • fix -- Bug fix
  • docs -- Documentation only
  • chore -- Maintenance task (deps, config, etc.)
  • refactor -- Code restructuring (no behavior change)
  • test -- Adding or updating tests
  • ci -- CI/CD pipeline changes
  • build -- Build system or dependency changes
  • revert -- Reverts a previous commit
  • style -- Code style (formatting, whitespace)

Modifiers

  • Breaking change (!) -- This change breaks backward compatibility

Changes Made

  • flake.nix: new githooksPathHook fragment in mkProjectShell'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 own devShells.default exercises it. Three guards, each justified in the code comment:
    1. .githooks/ must exist at the git toplevel — only scaffold-shaped repos are touched;
    2. main worktree only (worktree git-dir == common git-dir) — a linked worktree is owned by justfile.worktree, which deliberately unsets core.hooksPath and installs prek hooks directly; this guard keeps the shellHook from fighting that flow;
    3. only when the value differs from .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 .githooks stays the single entry point.
  • tests/test_flake_hooks.py: new TestGithooksPathWiring suite (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 .githooks write while still rejecting any other core.hooksPath mutation.
  • docs/COMMIT_MESSAGE_STANDARD.md (SSoT; assets/workspace/ mirror regenerated by sync-manifest): updated the "if core.hooksPath is unset the guard is silently absent" caveat — both sanctioned environments now wire it automatically.

Changelog Entry

Fixed

  • direnv dev-shell wires core.hooksPath → .githooks automatically (#1112)
    • Devcontainer mode set the hook entry point during setup, but a direnv / nix develop consumer 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 by justfile.worktree's direct prek install), and idempotent re-entry; it only ever sets the sanctioned .githooks value (feat(flake): generate .pre-commit-config.yaml from one flake hook definition, consumer-extensible #908 invariant).

Testing

  • Tests pass locally (just test)
  • Manual testing performed (describe below)

Manual Testing Details

  • TDD: test_default_shellhook_sets_core_hookspath_to_githooks committed 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 current dev (post podman-DooD flake change).
  • End-to-end against temp repos: main worktree + .githooks → set; linked worktree → left unset; no .githooks → untouched; re-entry → idempotent.
  • Tier-0 flake gates nix run .#nix-fast-build -- --flake ".#checks.x86_64-linux" → exit 0 (includes treefmt/nixfmt + dev-shell build + git-hooks check). Downstream scaffold-stub nix flake check ./assets/workspace --override-input vigos "path:$PWD" → all checks passed.
  • prek run --all-files: green.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (edit docs/templates/, then run just docs)
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Part of the commit-action-deployment bug batch. Shared-config semantics note: core.hooksPath lives in the repo's shared config, so entering the main-worktree dev shell sets it repo-wide; in a linked worktree the .githooks entry point then also runs prek run, so hooks stay enforced either way — no functional regression, just an observation.

Refs: #1112

c-vigo added 3 commits July 15, 2026 15:32
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
@c-vigo c-vigo self-assigned this Jul 15, 2026
@c-vigo
c-vigo merged commit 6a8d447 into dev Jul 15, 2026
15 checks passed
@c-vigo
c-vigo deleted the bugfix/1112-direnv-hookspath branch July 15, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant