Format pass + pre-commit hook to run cargo fmt #2

Merged
crowmaki merged 3 commits from git-hook-cargo-fmt into main 2026-08-21 17:15:15 +00:00
Collaborator

Adds a one-time cargo fmt pass and a versioned pre-commit hook that keeps the workspace rustfmt-clean.

Format pass

  • Runs cargo fmt across the lexer crate (4 files, pure formatting, no behaviour change; the 8-test suite still passes, cargo fmt --check now clean).

Pre-commit hook

  • New .githooks/pre-commit (mode 755, versioned in-repo so every clone can share it): runs cargo fmt --check and blocks the commit if any Rust is unformatted. It does not auto-stage; the author runs cargo fmt, stages with git add, then commits, keeping the index exactly what they intended.
  • Sources ~/.cargo/env first (cargo is only on the PATH after activation on this box).
  • Fast-paths out when no .rs files are staged.
  • Enable for a clone with: git config core.hooksPath .githooks (documented in AGENTS.md).

Verified end-to-end: the hook aborts (exit 1) on a staged unformatted file with a clear message, and passes on a clean tree.

Adds a one-time cargo fmt pass and a versioned pre-commit hook that keeps the workspace rustfmt-clean. ## Format pass - Runs `cargo fmt` across the `lexer` crate (4 files, pure formatting, no behaviour change; the 8-test suite still passes, `cargo fmt --check` now clean). ## Pre-commit hook - New `.githooks/pre-commit` (mode 755, versioned in-repo so every clone can share it): runs `cargo fmt --check` and **blocks** the commit if any Rust is unformatted. It does **not** auto-stage; the author runs `cargo fmt`, stages with `git add`, then commits, keeping the index exactly what they intended. - Sources `~/.cargo/env` first (cargo is only on the PATH after activation on this box). - Fast-paths out when no `.rs` files are staged. - Enable for a clone with: `git config core.hooksPath .githooks` (documented in AGENTS.md). Verified end-to-end: the hook aborts (exit 1) on a staged unformatted file with a clear message, and passes on a clean tree.
One-time format pass over the lexer crate so the codebase is rustfmt-clean
before enabling the pre-commit hook (see next commit). Pure formatting; no
behaviour change — the 8-test suite still passes.
Ship a versioned pre-commit hook (.githooks/pre-commit) that runs `cargo fmt`
over the workspace and re-stages only the .rs files it touched, so no commit
lands unformatted. Registers via `core.hooksPath` (documented in AGENTS.md) and
sources ~/.cargo/env since cargo is only on the PATH after activation.
Verified: the hook fires on commit and is a no-op on a clean tree.
Switch the pre-commit hook to the blocking style: run cargo fmt --check and
abort the commit if any Rust is unformatted, instead of auto-staging the
format result. The author now runs cargo fmt, stages with git add, then
commits, keeping the index exactly what they intended.

Verified end-to-end: the hook aborts (exit 1) on a staged unformatted file
with a clear message, and passes on a clean tree.
crowmaki approved these changes 2026-08-21 17:14:18 +00:00
crowmaki deleted branch git-hook-cargo-fmt 2026-08-21 17:15:16 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
crowmaki/catlang!2
No description provided.