diff --git a/.config/make/pre-commit.mak b/.config/make/pre-commit.mak index 716b182f4..c23adc230 100644 --- a/.config/make/pre-commit.mak +++ b/.config/make/pre-commit.mak @@ -3,9 +3,10 @@ .NOTPARALLEL: pre-commit pre-pr dev-check .PHONY: setup-hooks -setup-hooks: ## Set up git hooks +setup-hooks: ## Install the configured pre-commit hooks @echo "🔧 Setting up git hooks..." - chmod +x .git/hooks/pre-commit + pre-commit validate-config + pre-commit install @echo "✅ Git hooks setup complete!" .PHONY: doc-paths-check diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 947c4ffbb..083bf9dff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,9 +3,9 @@ repos: - repo: local hooks: - - id: rustfs-dev-check - name: rustfs dev-check - entry: make dev-check + - id: rustfs-fmt-check + name: Rust formatting + entry: cargo fmt --all --check language: system types: [rust] pass_filenames: false diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 13bf35c08..4af869ef5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -109,24 +109,17 @@ affected boundaries and risks. CI still runs its configured repository gates. ### 🔒 Git Pre-commit Hooks (optional) -Git hooks are **not** versioned in this repository, so a fresh clone has no -active pre-commit hook. If you add your own `.git/hooks/pre-commit` (a good -choice is a one-liner that runs `make pre-commit`), you can mark it executable -with: +The optional hook uses the checked-in `.pre-commit-config.yaml`. Install [pre-commit](https://pre-commit.com/#installation), then run this from the checkout or a linked worktree: ```bash make setup-hooks ``` -Or manually: +The hook runs `cargo fmt --all --check` when staged files include Rust source. It does not compile the workspace or run tests. Fix formatting with `cargo fmt --all`, inspect and stage the result, then commit again. -```bash -chmod +x .git/hooks/pre-commit -``` +`pre-commit install` resolves Git's hook directory for linked worktrees and preserves an existing hook in migration mode. If you use `core.hooksPath`, keep that hook manager and integrate `pre-commit run` there; the installer refuses to silently replace that configuration. -With or without a hook, follow the verification tiers in `AGENTS.md`. Run the -applicable scoped checks, and reserve `make pre-pr` for broad cross-module -changes whose impact cannot be bounded by those checks. +A local hook provides early formatting feedback. With or without it, follow the verification tiers in `AGENTS.md`, run relevant behavioral tests, and satisfy the CI merge gates. `make pre-commit` and `make dev-check` remain explicit broader commands. ### 📝 Formatting Configuration @@ -138,31 +131,11 @@ fn_call_width = 90 single_line_let_else_max_width = 100 ``` -### 🚫 Commit Prevention - -If you set up a pre-commit hook and your code doesn't meet the formatting requirements, the hook will: - -1. **Block the commit** and show clear error messages -2. **Provide exact commands** to fix the issues -3. **Guide you through** the resolution process - -Example output when formatting fails: - -``` -❌ Code formatting check failed! -💡 Please run 'cargo fmt --all' to format your code before committing. - -🔧 Quick fix: - cargo fmt --all - git add . - git commit -``` - ### 🔄 Development Workflow 1. **Make your changes** 2. **Format your code**: `make fmt` or `cargo fmt --all` -3. **Run the fast gate**: `make pre-commit` (no clippy, no tests) +3. **Select relevant checks** using the validation tier in `AGENTS.md`; use `make pre-commit` when its broader fast gate adds useful coverage 4. **Commit your changes**: `git commit -m "your message"` 5. **Complete the applicable multi-role adversarial review** for non-exempt changes (see `AGENTS.md`) 6. **Run applicable scoped checks before opening/updating a PR**; consider @@ -206,11 +179,12 @@ Configure your IDE to: #### Pre-commit hook not running? ```bash -# Check if hook is executable -ls -la .git/hooks/pre-commit - -# Make it executable if needed -chmod +x .git/hooks/pre-commit +pre-commit validate-config +pre-commit run --all-files +# Inspect any configured hook manager; do not overwrite it. +git config --get core.hooksPath +# Install if no separate hook manager is configured. +make setup-hooks ``` #### Formatting issues?