Last active
June 20, 2024 12:12
-
-
Save akash1233/5f4ac0c9c5ab17ba65cb1f75e8d88f4e to your computer and use it in GitHub Desktop.
pre-receive git hooks for checking the commit message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# check commit messages for pivotal tracker issue numbers formatted as [#stort-id]along with commit message | |
REGEX="\[#[0-9]*\]" | |
ERROR_MSG="[POLICY] The commit doesn't reference a PIVOTAL tracker issue" | |
while read OLDREV NEWREV REFNAME ; do | |
for COMMIT in `git rev-list $OLDREV..$NEWREV`; | |
do | |
MESSAGE=`git cat-file commit $COMMIT | sed '1,/^$/d'` | |
if ! echo $MESSAGE | grep -iqE "$REGEX"; then | |
echo "$ERROR_MSG: $MESSAGE" >&2 | |
exit 1 | |
fi | |
done | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found this extremely helpful, searched for hours before I found this!!
I wanted to only check the first commit line, adding
q
to the sed command only checks the commit 'message' and not the 'description'sed '1,/^$/d;q'