Skip to content

Instantly share code, notes, and snippets.

@KyMidd
Created October 7, 2021 01:07
Show Gist options
  • Select an option

  • Save KyMidd/d948c6b3b6050ade3170f64e890e69a0 to your computer and use it in GitHub Desktop.

Select an option

Save KyMidd/d948c6b3b6050ade3170f64e890e69a0 to your computer and use it in GitHub Desktop.
# Check every commit message since ancestor for regex match
for commit in $BRANCH_COMMITS; do
if git log --max-count=1 --format=%B $commit | tr '[a-z]' '[A-Z]' | grep -iqE "$msg_regex"; then
: #If commit matches regex, commit is valid, do nothing
else
# If commit doesn't match regex, commit isn't valid, print commit info
echo "************"
printf "Invalid commit message: \"%s\" and hash: %s\n" "$(git log --max-count=1 --format=%B $commit)" "$commit"
echo "************"
# Set this variable to trigger rejection if any commit fails regex
invalidCommit=true
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment