git hook: ensure each merge into the master has a message also the automatic merges

﹥>﹥吖頭↗ 提交于 2019-12-03 20:37:04

as promised here is my solution. Past this in your commit.msg hook and adapt to your needs.

#!/bin/bash
# give me the branch I am currently working on
mybranch=`git rev-parse --abbrev-ref HEAD`

# Depending on the branch we do different validation
if [ $mybranch = master ]; then
regex="^[^Merge|^#].{71,}"
message="ERROR: Commit message is too short."
else
regex="^(PMS|GKM)-[0-9]{3,4}\s\:\s.{10,}"
message="ERROR: Commit message is missing the Ticketnumber in the format GKM-nnnn: or PMS-nnnn :."
fi

test "" != "$(grep -E $regex "$1")" || {
    cat $1 >&2
    echo >&2 $message
    exit 1
}

Depending on the branch I choose different regular expressions and matching error messages.

This ensures for any branch not being master, that the message starts with a ticket number. For the master branch we don't need a ticket number, but a longer commit message.

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