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

Terraform

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

gitleaks

Install:

sudo pacman -S gitleaks

Scan git history:

gitleaks detect -v

Ignore/allow false-positives:

  • Add a # gitleaks:allow at the end of the line with an allowed false-positive
  • For retroactive ignores from already committed false-positives add the fingerprint shown by gitleaks detect -v to a .gitleaksignore, see this repos .gitleaksignore as example

talisman

https://github.com/thoughtworks/talisman/

If you are sure you want to ignore detected secret material:

echo 'aarwolf.yaml # ignore:filecontent' >> .talismanignore

Issues:

git-secrets

Commit message linters

gitlint

Website Config files

Add a default .gitlint file:

gitlint generate-config

Ignore body-is-missing rule:

echo '[general]\nignore=body-is-missing' > .gitlint

Other (noteworthy) commit message linters:

commitlint

https://github.com/conventional-changelog/commitlint

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