git commit -a bypasses git hook when it shouldn't

喜夏-厌秋 提交于 2019-12-12 01:55:08

问题


I have a git hook for commit-msg which works quite happily when I run

git commit -m "MSG HERE"

but if I run

git commit -a

Which triggers committing using your text editor it skips the hook.

Any suggestions on how to fix this?

My hook is as follows

#!/bin/bash
if ! egrep -q 'DAVE-[0-9]+' $1 ; then
     echo "No Jira Issue Number found" >&2
     exit 1
fi

if [[ "$(wc -c $1 | awk '{print $1}')" -le 20 ]] ; then
     echo "Commit message too short" >&2
     exit 1
fi

回答1:


I can't reproduce your problem, so my guess here is that there's a misunderstanding -- the commit-msg hook runs after you specified your message, ie. after you close the commit text editor, not before, so you will only notice the changes in your git log.

EDIT:

Are you sure you're not counting comment lines? These would easily blow up the message to above 20 characters. Use something like cat $1|grep -vE '^#'|wc -c|awk ....



来源:https://stackoverflow.com/questions/27983784/git-commit-a-bypasses-git-hook-when-it-shouldnt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!