Skip to content

pre-commit

  • Website
  • GitHub
  • 2k commits, 13k ⭐

  • Supported hooks
  • Cached hooks: ~/.cache/pre-commit
  • Custom hooks (see below): ~/projects/git/pre-commit/pre-commit-config-varac

Install:

sudo apt install pre-commit

Usage:

pre-commit sample-config > .pre-commit-config.yaml
pre-commit install
pre-commit run --all-files
pre-commit run --all-files --show-diff-on-failure

Skip hooks:

SKIP=terraform_fmt,terraform_validate,terraform_tflint pre-commit ...

General hooks

Good documentation including expected stdin/parameters

Global hooks activated by:

git config --global core.hooksPath ~/.config/git/hooks

Filtering files with types

Filtering files with types

Identify file type discovered by pre-commit:

$ identify-cli setup.py
["file", "non-executable", "python", "text"]

Issues

Global hooks / include statement

Workarounds:

Integrations / plugins / shared hooks

Ansible

cat ~/projects/git/pre-commit/custom/ansible.yaml >> .pre-commit-config.yaml

Chef

https://github.com/mattlqx/pre-commit-ruby

YAML

Docker

cat ~/projects/git/pre-commit/custom/docker.yaml >> .pre-commit-config.yaml

Kubernetes

Kubeval:

cat ~/projects/git/pre-commit/custom/kubeval.yaml >> .pre-commit-config.yaml

Gitlab Ci Linter

See ../gitlab/ci.md

Check for secret material

see security/passwords/linting.md

gitmoji

https://gitmoji.carloscuesta.me/ https://hackernoon.com/using-github-as-a-team-the-holy-grail-of-commit-messages-f5b10c925d62

Other tools

https://github.com/zeke/semantic-pull-requests: Stale, last commit 2021

pre-commit in CI

Container images

Gitlab CI Templates