Skip to content

Instantly share code, notes, and snippets.

@JonnyPickard
Last active July 11, 2017 19:11
Show Gist options
  • Save JonnyPickard/e7215bd331d54e11bfdcdeb229c7ca28 to your computer and use it in GitHub Desktop.
Save JonnyPickard/e7215bd331d54e11bfdcdeb229c7ca28 to your computer and use it in GitHub Desktop.
git `commit-msg` pre commit hook JIRA regex check.
#!/bin/bash
# This is a simple bash script to regex check the start of a git commit
# message for a JIRA tag.
# This is usefull for the pre commit `commit-msg` git hook.
# Obviously feel free to tailor it to your specific use case.
# Finally make sure you remember chmod the file to give execute permissions.
# Enjoy =]
regex="^[A-Z]{1,4}[-]{1}[1-9]{1,3}"
var="PLSV-359"
var2="Incorrect jira tag"
var3="S-9"
if [[ "$var" =~ $regex ]]
then
echo "matches"
else
echo "doesn't match!"
fi
if [[ "$var" =~ $regex ]]
then
echo "PLSV-359 matches"
fi
if [[ "$var2" =~ $regex ]]
then
echo "Incorrect jira tag matches"
fi
if [[ "$var3" =~ $regex ]]
then
echo "S-9 matches"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment