Created
March 16, 2020 00:52
-
-
Save pakman198/ec7640539b1932d81adfcb03d0c31a29 to your computer and use it in GitHub Desktop.
git commit-msg hook
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 | |
MSG_FILE=$1 | |
FILE_CONTENT="$(cat $MSG_FILE)" | |
# Initialize constants here | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[0;33m' | |
no_color='\033[0m' | |
export REGEX='^(HTL[0-9]+:|Merge) .+' | |
export ERROR_MSG="Aborting commit. Your commit message must include a JIRA issue ( HTL-123: ) or 'Merge'" | |
echo "\n${yellow}Executing pre-commit hook${no_color}\n" | |
echo $MSG_FILE | |
echo $FILE_CONTENT | |
if [[ $FILE_CONTENT =~ $REGEX ]]; then | |
exit 0 | |
else | |
echo "\nBad commit \"$FILE_CONTENT\"" | |
echo "${red}${ERROR_MSG}\n${no_color}" | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment