cargo fmt all check ins

This commit is contained in:
jasonwitty 2025-08-22 11:10:11 -07:00
parent d3fa55e572
commit 155c420a1a
2 changed files with 40 additions and 0 deletions

28
.githooks/pre-commit Normal file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env bash
set -euo pipefail
echo "[pre-commit] Running cargo fmt --all" >&2
if ! command -v cargo >/dev/null 2>&1; then
echo "[pre-commit] cargo not found in PATH" >&2
exit 1
fi
cargo fmt --all
# Stage any Rust files that were reformatted
changed=$(git diff --name-only --diff-filter=M | grep -E '\\.rs$' || true)
if [ -n "$changed" ]; then
echo "$changed" | xargs git add
echo "[pre-commit] Added formatted files" >&2
fi
# Fail if further diffs remain (shouldn't happen normally)
unfmt=$(git diff --name-only --diff-filter=M | grep -E '\\.rs$' || true)
if [ -n "$unfmt" ]; then
echo "[pre-commit] Some Rust files still differ after formatting:" >&2
echo "$unfmt" >&2
exit 1
fi
exit 0

View File

@ -460,6 +460,18 @@ cargo run -p socktop -- ws://127.0.0.1:3000/ws
cargo run -p socktop_agent -- --enableSSL --port 8443 cargo run -p socktop_agent -- --enableSSL --port 8443
``` ```
### Auto-format on commit
A sample pre-commit hook that runs `cargo fmt --all` is provided in `.githooks/pre-commit`.
Enable it (one-time):
```bash
git config core.hooksPath .githooks
chmod +x .githooks/pre-commit
```
Every commit will then format Rust sources and restage them automatically.
--- ---
## Roadmap ## Roadmap