Created
July 18, 2018 22:39
-
-
Save BillyPurvis/d6dea510f842aa4aba519e0bea9328ed to your computer and use it in GitHub Desktop.
A commit-msg hook written with bash to stop badly worded commits!
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/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