Skip to content

ci: let pre-commit own git hooks (disable trunk hook actions) - #207

Merged
helly25 merged 2 commits into
mainfrom
ci/pre-commit-owns-git-hooks
Jul 1, 2026
Merged

ci: let pre-commit own git hooks (disable trunk hook actions)#207
helly25 merged 2 commits into
mainfrom
ci/pre-commit-owns-git-hooks

Conversation

@helly25

@helly25 helly25 commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Problem

clang-format wasn't auto-formatting new C++ files locally. Root cause: trunk was the git-hooks managercore.hooksPath pointed at trunk's cache, so pre-commit's framework hook (which owns clang-format) could never install or run on commit, and trunk's own commit hook runs trunk fmt, which by design excludes clang-format. New files landed with 4-space indent.

Fix

Disable trunk's three git-hook actions so trunk stops claiming core.hooksPath:

  • trunk-announce, trunk-check-pre-push, trunk-fmt-pre-commitactions.disabled

With those off, trunk git-hooks sync reports "not managing your git hooks" and pre-commit install can own .git/hooks/{pre-commit,pre-push}. Trunk still runs standalone via trunk check and the CI trunk job. Verified: after the change, real git commits run the pre-commit hooks (both commits in this PR did).

Per-clone step: run pre-commit install (was blocked before because trunk held core.hooksPath).

Regression guard

A CI step in the trunk job asserts trunk never re-seizes the hooks — it rejects any enabled trunk git-hook action in .trunk/trunk.yaml and, when trunk is present, syncs hooks and requires core.hooksPath not point into trunk's cache. This is the only place the check is reliable: a pre-commit hook can't run if trunk owns the hook path, and a trunk custom linter runs in an isolated sandbox blind to the real git config (both were tried and don't work).

Also included (staged)

  • .clangd: add -std=c++20 to the clangd compile flags.
  • .trunk/trunk.yaml: routine linter version bumps (checkov, prettier, trivy, trufflehog).

helly25 added 2 commits July 1, 2026 20:34
Trunk was the git-hooks manager (core.hooksPath -> trunk's cache), so
pre-commit's framework hook -- which owns clang-format -- never ran on
commit and new C++ files landed unformatted. Disable trunk's three
git-hook actions (trunk-announce, trunk-check-pre-push, trunk-fmt-pre-commit)
so trunk stops claiming core.hooksPath; pre-commit then owns .git/hooks
via `pre-commit install`. Trunk still runs standalone via `trunk check`
and the CI trunk job.

Also carries routine trunk linter version bumps (checkov, prettier,
trivy, trufflehog) and adds -std=c++20 to the .clangd compile flags.
Add a step to the CI `trunk` job that fails if trunk could seize the git
hooks from pre-commit: it rejects any enabled trunk git-hook action in
.trunk/trunk.yaml and, when trunk is available, syncs hooks and requires
core.hooksPath not point into trunk's cache.

This is the only place the check is reliable: a pre-commit hook can't run
if trunk owns the hook path, and a trunk custom linter runs in an isolated
sandbox blind to the real git config.
@helly25
helly25 requested a review from Fab-Cat July 1, 2026 21:14
@helly25
helly25 merged commit 26af368 into main Jul 1, 2026
38 checks passed
@helly25
helly25 deleted the ci/pre-commit-owns-git-hooks branch July 1, 2026 22:25
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.

2 participants