Skip to content

Instantly share code, notes, and snippets.

@pakman198
Created March 16, 2020 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pakman198/ec7640539b1932d81adfcb03d0c31a29 to your computer and use it in GitHub Desktop.
Save pakman198/ec7640539b1932d81adfcb03d0c31a29 to your computer and use it in GitHub Desktop.
git commit-msg hook
#!/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