Created
March 22, 2022 23:53
-
-
Save Nikoloutsos/ca78836e174882514bbb70877805d6a6 to your computer and use it in GitHub Desktop.
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 | |
| # Used for adding some colors in the console. ๐ | |
| # https://medium.com/@f3igao/get-started-with-git-hooks-5a489725c639 | |
| REDBOLD='\033[0;31;1m' | |
| GREENBOLD='\033[0;32;1m' | |
| NORMAL='\033[0m' | |
| # The below input_file is file ".git/COMMIT_EDITMSG" where commits are stored | |
| INPUT_FILE=$1 | |
| # It will copy the commit string from ".git/COMMIT_EDITMSG" | |
| COMMIT_MESSAGE=`head -n1 $INPUT_FILE` | |
| # Verify message starts with a correct VERB | |
| VERB_REGEX="^(Merge|Add|Drop|Fix|Bump|Make|Start|Stop|Optimize|Document|Refactor|Reformat|Rearrange|Redraw|Reword|Scaffold|fixup!) .+$" | |
| if [[ $COMMIT_MESSAGE =~ $VERB_REGEX ]]; then | |
| echo "โ Detected valid commit message verb" | |
| else | |
| echo "๐ฎโโ๏ธ ${REDBOLD}Hold on! Git hook police here. ${NORMAL}" | |
| echo "Your commit message doesn't start with a valid verb (e.g Add/Refactor/Reward/Document) " | |
| echo "'$COMMIT_MESSAGE' is not adhering to iOS Blueground git rules. ( https://github.com/bluegroundltd/manifesto/blob/master/make/Git_Practices.md#summary-keywords )" | |
| exit 1 | |
| fi | |
| # Verify message contains <= 50 chars | |
| LENGTH_REGEX="^.{1,50}$" | |
| if [[ $COMMIT_MESSAGE =~ $LENGTH_REGEX ]]; then | |
| echo "โ Commit message is <= 50 chars" | |
| else | |
| echo "๐ฎโโ๏ธ ${REDBOLD}Hold on! Git hook police here. ${NORMAL}" | |
| echo "Your commit message exceeds the limit of 50 chars " | |
| echo "'$COMMIT_MESSAGE' is not adhering to iOS Blueground git rules. ( https://github.com/bluegroundltd/manifesto/blob/master/make/Git_Practices.md#summary-keywords )" | |
| exit 1 | |
| fi | |
| # All checks passed! | |
| echo "${GREENBOLD}All commit-msg hook checks passed. ๐${NORMAL}" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment