Skip to content

Latest commit

 

History

History
90 lines (58 loc) · 2.08 KB

pre-commit.md

File metadata and controls

90 lines (58 loc) · 2.08 KB

Pre-Commit

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.

Install

On Mac:

brew install pre-commit

or using Python pip:

pip install pre-commit

Install Git Hooks

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.

Config

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

Run against all files when adding checks to see the current state of your repo contents:

pre-commit run --all-files

Run on changed files in branch

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 Config Hooks

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