如果用户的提交消息未遵循某些准则,我想警告用户,然后为他们提供编辑其提交消息,忽略警告或取消提交的选项。问题是我似乎无法访问stdin。
以下是我的commit-msg文件:
function verify_info {
if [ -z "$(grep '$2:.*[a-zA-Z]' $1)" ]
then
echo >&2 $2 information should not be omitted
local_editor=`git config --get core.editor`
if [ -z "${local_editor}" ]
then
local_editor=${EDITOR}
fi
echo "Do you want to"
select CHOICE in "edit the commit message" "ignore this warning" "cancel the commit"; do
case ${CHOICE} in
i*) echo "Warning ignored"
;;
e*) ${local_editor} $1
verify_info "$1" $2
;;
*) echo "CHOICE = ${CHOICE}"
exit 1
;;
esac
done
fi
}
verify_info "$1" "Scope"
if [ $# -ne 0 ];
then
exit $#
fi
verify_info "$1" "Affects"
if [ $# -ne 0 ];
then
exit $#
fi
exit 0
当我将范围信息保留为空白时,以下是输出:
Scope information should not be omitted
Do you want to:
1) edit the commit message 3) cancel the commit
2) ignore this warning
#?
该消息是正确的,但实际上并没有停止输入。我也尝试过使用更简单的“读取”命令,它也有同样的问题。似乎问题在于,此时git可以控制stdin并提供自己的输入。我该如何解决?