Skip to content

Instantly share code, notes, and snippets.

@amirzenoozi
Created July 17, 2022 05:59
Show Gist options
  • Save amirzenoozi/ed80483d33e5a71185f1cb3319525cb8 to your computer and use it in GitHub Desktop.
Save amirzenoozi/ed80483d33e5a71185f1cb3319525cb8 to your computer and use it in GitHub Desktop.
Check Commit Message Before Commit Change
#!/bin/sh
# Check This https://regex101.com/r/jkAuu3/1
commit_regex='(((feat|fix|chore|refactor|style|test|docs)(((\w{0,15})))?))(:.\S.*)';
error_msg="Aborting commit. Your commit message format is invalid, please check the references."
commit_message="$1";
if ! grep -iqE "$commit_regex" "$commit_message";
then
echo "$error_msg" >&2
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment