Skip to content

Switch pre-commit hooks from .githooks to prek#231

Merged
wesm merged 3 commits intomainfrom
feat/prek-precommit
Mar 28, 2026
Merged

Switch pre-commit hooks from .githooks to prek#231
wesm merged 3 commits intomainfrom
feat/prek-precommit

Conversation

@wesm
Copy link
Copy Markdown
Owner

@wesm wesm commented Mar 28, 2026

Summary

  • Replace manual .githooks/pre-commit script with prek for hook management
  • Split make lint into lint (auto-fix for local dev) and lint-ci (no fix for CI)
  • Setup: make install-hooks (requires brew install prek)

🤖 Generated with Claude Code

Replace the manual .githooks/pre-commit script with prek for hook
management, matching the pattern used in roborev. The prek hook runs
`make fmt lint` which now auto-fixes with `golangci-lint --fix`.

- Add prek.toml with local system hook for fmt + lint
- Split lint into `lint` (--fix, local dev) and `lint-ci` (CI)
- Replace `setup-hooks` with `install-hooks` (prek install)
- Update CI workflow to use `make lint-ci`
- Remove .githooks/pre-commit (prek manages .git/hooks/ directly)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 28, 2026

roborev: Combined Review (3ad1981)

Verdict: Changes introduce blocking Makefile regressions and a medium-risk pre-commit behavior mismatch that can commit unfixed code.

High

  • Makefile (targets lint, lint-ci, install-hooks)

    • The shell if keyword appears to have been replaced with cmd/msgvault/cmd/verify.go, which makes those recipe lines invalid shell syntax and will cause the targets to fail.
    • Fix: Restore @if ! command ... in those targets.
  • Makefile (target install-hooks)

    • The git command appears to have been replaced with .gitignore in the command that unsets core.hooksPath, so hook installation cleanup will fail.
    • Fix: Restore @git config --unset core.hooksPath.

Medium

  • prek.toml:8-12, Makefile (lint target)
    • The pre-commit flow now runs mutating commands (go fmt ./... and golangci-lint run --fix ./...) without re-staging rewritten files or explicitly failing when edits occur. That can leave fixes only in the working tree while the commit still contains the pre-fix index.
    • Fix: Make the hook check-only (gofmt -l, lint without --fix) or explicitly fail/re-stage when files are modified.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 28, 2026

roborev: Combined Review (978b29c)

Verdict: Changes introduce two high-severity regressions in the hook/lint workflow that should be fixed before merge.

High

  • Hook can modify files without restaging them, so commits may succeed with stale indexed content rather than the formatter/linter output.
    Location: prek.toml:10, Makefile:65
    Details: The new pre-commit hook runs make fmt lint, and make lint now uses golangci-lint run --fix ./.... Because these commands can rewrite tracked files during pre-commit and the hook does not restage them, the hook no longer reliably guarantees that the committed snapshot is formatted and lint-clean.
    Suggested fix: Make the hook check-only (gofmt -l, golangci-lint run) or explicitly restage any files changed by formatting/lint autofixes before allowing the commit to proceed.

  • Makefile contains broken shell commands that will cause hook/lint targets to fail.
    Location: Makefile:61, Makefile:69, Makefile:78, Makefile:82
    Details: There appears to be a bad text replacement in the shell recipes:

    • if was changed to cmd/msgvault/cmd/verify.go, which makes the shell syntax invalid for make lint, make lint-ci, and make install-hooks.
    • git config was changed to .gitignore config, which will fail and prevent cleanup of the old core.hooksPath setting.
      Suggested fix: Restore @if in the affected recipes and restore @git config at Makefile:82.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

Only unset core.hooksPath when it points to the old .githooks directory.
If set to something else, error with guidance instead of silently removing
the developer's custom hook configuration.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@roborev-ci
Copy link
Copy Markdown

roborev-ci bot commented Mar 28, 2026

roborev: Combined Review (bdb91fc)

PR introduces a useful hook migration, but it currently breaks key Make targets and weakens pre-commit enforcement in existing clones.

High

  • Makefile:61, 69, 78
    • Malformed shell if statements: if appears to have been replaced with cmd/msgvault/cmd/verify.go, which will cause make lint, make lint-ci, and make install-hooks to fail.
    • Fix: Replace @cmd/msgvault/cmd/verify.go ! command -v with @if ! command -v.

Medium

  • .githooks/pre-commit (deleted), Makefile:74

    • Existing clones that previously ran make setup-hooks may still have core.hooksPath=.githooks; after this change, that path no longer contains a pre-commit hook, so hook enforcement silently disappears until each developer manually reruns setup.
    • Fix: Keep a compatibility stub in .githooks/pre-commit that fails with a clear make install-hooks message, or preserve the old hook during the migration window.
  • prek.toml:10-12, Makefile:60-70

    • The new prek hook runs make fmt lint on every commit with pass_filenames = false and always_run = true, so even a docs-only or small staged change can rewrite or fail on unrelated unstaged Go work elsewhere in the tree. This regresses the prior staged-Go-files-only behavior.
    • Fix: Scope the hook to staged Go files, either by passing filenames into a wrapper or by restoring the previous git diff --cached filtering before formatting/linting.

Synthesized from 3 reviews (agents: codex, gemini | types: default, security)

@wesm
Copy link
Copy Markdown
Owner Author

wesm commented Mar 28, 2026

I'm fine with leaving things as is.

@wesm wesm merged commit 93134d6 into main Mar 28, 2026
4 checks passed
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