Run simple sanity checks and linting before allowing to Git commit.
Also used in CI/CD workflows.
See also the DevOps-Bash-tools repo's checks/ directory full of generic check scripts.
On Mac:
brew install pre-commit
or using Python pip:
pip install pre-commit
Have pre-commit
automatically run for all Git commits.
In your git repo checkout:
pre-commit install
which creates a script .git/hooks/pre-commit
.
All my direnv .envrc
files automatically install pre-commit
and the pre-commit hooks to the local git
repo checkout as soon as you cd
in to any git checkout directory.
Create a .pre-commit-config.yaml
at the root of your Git repo.
Here is a template to start from:
HariSekhon/Templates - .pre-commit-config.yaml
wget https://github.com/HariSekhon/Templates/blob/master/.pre-commit-config.yaml
Run against all files when adding checks to see the current state of your repo contents:
pre-commit run --all-files
Reproduce what a pull request check is doing locally to debug and fix your PRs to pass, using this script from the DevOps-Bash-tools repo:
precommit_run_changed_files.sh
Update all config hooks to the latest release tag on the default branch:
pre-commit autoupdate
Note: this will update hashref fixed to normal versioned tags which are slightly vulnerable to those repos not getting hacked and their tags replaced. GitHub security practices recommend fixing to hashrefs