pre-commit¶
A framework for managing and maintaining multi-language pre-commit hooks.
安装:
pip install pre-commit
# 验证
$ pre-commit --version
Quick start:
1. Install pre-commit
$ pre-commit --version
pre-commit 3.7.1
2. Add a pre-commit configuration
create a file named .pre-commit-config.yaml
$ cat .pre-commit-config.yaml:
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
3. Install the git hook scripts
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
# now pre-commit will run automatically on git commit!
4. (optional) Run against all the files
示例¶
Some out-of-the-box hooks for pre-commit: https://github.com/pre-commit/pre-commit-hooks
MetaGPT: https://github.com/geekan/MetaGPT/blob/main/.pre-commit-config.yaml