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檢查示例