From 7f48a2a1c53ceeb5cee8fa25f1ae9f3ef1d6ac32 Mon Sep 17 00:00:00 2001 From: Erich Blume Date: Thu, 4 Jun 2026 12:36:12 -0700 Subject: [PATCH] infra: add cargo-fmt-check pre-push prek hook (mirror CI) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cargo-fmt failure on this PR slipped to CI because the pre-commit prek hooks were never installed in the working clone. The existing cargo-fmt hook reformats in place but only when it runs. Add a pre-push cargo-fmt-check hook (`cargo fmt --all --check`) that mirrors CI's Dagger `check` step exactly, so an unformatted commit is blocked locally before it can reach the runner — even if the pre-commit hook was skipped or not installed. Filtered to .rs pushes so Rust-free pushes pay nothing. Co-Authored-By: Claude Opus 4.8 (1M context) --- docs/changelog.d/prek-fmt-prepush.infra.md | 1 + prek.toml | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 docs/changelog.d/prek-fmt-prepush.infra.md diff --git a/docs/changelog.d/prek-fmt-prepush.infra.md b/docs/changelog.d/prek-fmt-prepush.infra.md new file mode 100644 index 0000000..26cf000 --- /dev/null +++ b/docs/changelog.d/prek-fmt-prepush.infra.md @@ -0,0 +1 @@ +Added a `cargo-fmt-check` pre-push prek hook that runs `cargo fmt --all --check` (mirroring CI's Dagger `check` step) whenever a push touches a `.rs` file. The pre-commit `cargo-fmt` hook reformats in place, but only fires when installed and run; the pre-push check is a last-line guard so an unformatted commit can't reach the runner. Run `prek install --hook-type pre-push` to activate it. diff --git a/prek.toml b/prek.toml index 82ff957..e60082d 100644 --- a/prek.toml +++ b/prek.toml @@ -102,6 +102,22 @@ language = "system" files = '\.rs$' pass_filenames = false +# Pre-push safety net. The pre-commit cargo-fmt hook above reformats in place, +# but only when it is installed and actually runs — a commit made before +# `prek install`, or via a tool that skips hooks, can still carry unformatted +# Rust to CI (where the Dagger `check` step runs `cargo fmt --all --check` and +# fails). This hook re-checks at push time, mirroring CI byte-for-byte, so an +# unformatted commit is blocked locally before it can reach the runner. It runs +# only when the push range touches a .rs file, so Rust-free pushes pay nothing. +[[repos.hooks]] +id = "cargo-fmt-check" +name = "cargo-fmt-check" +entry = "cargo fmt --all --check" +language = "system" +files = '\.rs$' +pass_filenames = false +stages = ["pre-push"] + # GitHub/Forgejo Actions workflow linting [[repos]] repo = "https://github.com/rhysd/actionlint"