Skip to content

Instantly share code, notes, and snippets.

@BillyPurvis
Created July 18, 2018 22:39
Show Gist options
  • Select an option

  • Save BillyPurvis/d6dea510f842aa4aba519e0bea9328ed to your computer and use it in GitHub Desktop.

Select an option

Save BillyPurvis/d6dea510f842aa4aba519e0bea9328ed to your computer and use it in GitHub Desktop.
A commit-msg hook written with bash to stop badly worded commits!
#!/bin/sh
shopt -s nocasematch # Case insensitive matching
shopt -s extglob
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
regex='^(fix(es)?|change(s)?|merge(s)?|update(s)?|add(s)?|remove(s)?)[[:space:]].+[a-zA-Z?!${}()@].'
# Get commit Message
file=`cat $1`
# Test commit message conforms to regex requirements.
if ! [[ $file =~ $regex ]]; then
echo "${RED} Commit messages must be prefixed with singular or plural fix, change, merge, add. \n Example 'Adds new API connection input to dash'"
exit 1;
else
echo "${GREEN}Nice commit 👍 ${NC}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment