相关疑难解决方法(0)

如何在commit-msg挂钩中提示用户?

我想警告用户,如果他们的提交消息不遵循某组指南,然后给他们选项来编辑他们的提交消息,忽略警告或取消提交.问题是我似乎无法访问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 …
Run Code Online (Sandbox Code Playgroud)

git hook commit-message

69
推荐指数
3
解决办法
2万
查看次数

标签 统计

commit-message ×1

git ×1

hook ×1