Pre-commit Hooks
pre-commit is a framework for running automated
checks before each git commit. SPECTRE ships a .pre-commit-config.yaml
that catches common mistakes before they reach the repository.
Installation
Install the pre-commit tool and activate the hooks for your local clone:
pip install pre-commit
pre-commit install
After running pre-commit install, the hooks run automatically every time
you execute git commit.
Configured hooks
The following hooks are enabled:
check-tomlValidates all TOML files (e.g.
pyproject.toml) for syntax errors.detect-private-keyScans staged files for private key patterns and blocks the commit if any are found, preventing accidental exposure of credentials.
end-of-file-fixerEnsures every file ends with exactly one newline character.
no-commit-to-branchPrevents direct commits to the
mainbranch. All changes tomainmust go through a merge request (see Git Workflow).trailing-whitespaceStrips trailing whitespace from all lines.
Running hooks manually
You can run all hooks against every file at any time without making a commit:
pre-commit run --all-files
This is useful to check the full codebase after pulling in upstream changes or before opening a merge request.
Bypassing hooks
If you need to commit without running the hooks (e.g. to save a work-in-progress that does not yet pass all checks), you can skip them with:
git commit --no-verify
Warning
Use this sparingly. The CI pipeline will still enforce all checks on your merge request, so any issues will need to be resolved before the MR can be merged.