我试图阻止 git 提交继续使用预提交挂钩。通过阅读手册,当您返回 0 以外的退出代码时,它应该停止。我正在测试 csscomb 命令是否返回错误,如果返回错误,则中断循环并退出,但 git 提交仍然继续通过 来输入消息git commit (-a)。
我已经从https://github.com/filtercake/git-pre-commit-csscomb分叉并修改了下面的脚本
#!/bin/bash
# pre-commit hook to comb staged .sass and .scss files
# save as .git/hooks/pre-commit
# make executable: chmod +x .git/hooks/pre-commit
# sources:
# http://www.hagenburger.net/BLOG/Using-Git-Commit-Hooks-to-Autocompile-Sass-to-CSS.html
# http://stackoverflow.com/questions/8470755/git-pre-commit-hook-add-file-into-index/8471009#8471009
# http://stackoverflow.com/questions/592620/how-to-check-if-a-program-exists-from-a-bash-script/677212#677212
# https://gist.github.com/openam/8406343
# check if sass/scss files are staged for commit
# diff-lines from http://stackoverflow.com/a/12179492/3019532
# takes the line
function diff-lines() {
local path=
local line=
while read; do
esc=$'\033'
if [[ $REPLY =~ ---\ …Run Code Online (Sandbox Code Playgroud)