Files
oam/knowledge base/pre-commit.md
2024-01-09 19:21:38 +01:00

1.8 KiB

Pre-commit

Table of contents

  1. TL;DR
  2. Local hooks
  3. Troubleshooting
    1. Some files are skipped during a run
  4. Further readings

TL;DR

# Install.
pip install --user 'pre-commit'  # has currently issues with `pipx`
brew install 'pre-commit'

# Generate a very basic configuration.
pre-commit sample-config > '.pre-commit-config.yaml'

# Manually run checks.
pre-commit run --all-files
pre-commit run "ansible-lint" --files "ansible/"

# Automatically run checks at every commit.
pre-commit install

# Update all hooks to the latest version available.
# It is *not* always the latest *stable* release.
pre-commit autoupdate

# Skip checks on commit.
SKIP="check_id" git commit -m "foo"
git commit --no-verify -m "foo"

Config file example.

Local hooks

# .pre-commit-config.yaml
repos:
  - repo: local
    hooks:
      - id: do-something-with-make-once
        name: Do something with GNU Make once
        language: system
        entry: make do-something
        pass_filenames: false
        require_serial: true
      - id: call-script-passing-files
        name: Call a local script passing files as arguments
        language: script
        entry: path/to/script.sh

Troubleshooting

Some files are skipped during a run

Check they are tracked (have been added to the repository).

Further readings