lefthook
v1.10.0
Node.js,Ruby,Python和许多其他类型的项目的Git Hooks经理。
文档
阅读介绍帖子
使用GO (> = 1.23):
go install github.com/evilmartians/lefthook@latest使用NPM :
npm install lefthook --save-dev对于Ruby :
gem install lefthook对于Python :
pip install lefthook安装指南具有更多的安装Lefthook的方法:APT,Brew,Winget等。
配置钩子,安装一次,然后忘记它:依靠下面的魔法。
# Configure your hooks
vim lefthook.yml
# Install them to the git project
lefthook install
# Enjoy your work with git
git add -A && git commit -m ' ... ' lefthook.yml配置选项的配置。给您更高的速度。文档
pre-push :
parallel : true如果您想要自己的列表。定制和预构建示例。
pre-commit :
commands :
frontend-linter :
run : yarn eslint {staged_files}
backend-linter :
run : bundle exec rubocop --force-exclusion {all_files}
frontend-style :
files : git diff --name-only HEAD @{push}
run : yarn stylelint {files}如果要过滤文件列表。您可以在此处找到更多的Glog模式示例。
pre-commit :
commands :
backend-linter :
glob : " *.rb " # glob filter
exclude : ' (^|/)(application|routes).rb$ ' # regexp filter
run : bundle exec rubocop --force-exclusion {all_files}如果要在相对路径中执行命令
pre-commit :
commands :
backend-linter :
root : " api/ " # Careful to have only trailing slash
glob : " *.rb " # glob filter
run : bundle exec rubocop {all_files}如果Oneline命令不够,则可以执行文件。文档
commit-msg :
scripts :
" template_checker " :
runner : bash如果要控制一组命令。文档
pre-push :
commands :
packages-audit :
tags :
- frontend
- linters
run : yarn lint
gems-audit :
tags :
- backend
- security
run : bundle audit如果您在Docker环境中。文档
pre-commit :
scripts :
" good_job.js " :
runner : docker run -it --rm <container_id_or_name> {cmd}如果您是前端/后端开发人员,并且想跳过不必要的命令或将某些内容替补进入Docker。文档
# lefthook-local.yml
pre-push :
exclude_tags :
- frontend
commands :
packages-audit :
skip : true如果您想直接运行挂钩组。
$ lefthook run pre-commit如果您想直接运行特定的命令组。
fixer :
commands :
ruby-fixer :
run : bundle exec rubocop --force-exclusion --safe-auto-correct {staged_files}
js-fixer :
run : yarn eslint --fix {staged_files} $ lefthook run fixer您可以控制使用输出选项的Lefthook打印。
output :
- execution
- failure检查示例