Skip to content

Instantly share code, notes, and snippets.

@szkrd
Created July 16, 2014 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szkrd/c0cd847288ac261da916 to your computer and use it in GitHub Desktop.
Save szkrd/c0cd847288ac261da916 to your computer and use it in GitHub Desktop.
git commit message hook lite
#!/bin/sh
# halp!!4
if [ $# -eq 0 ] || [ $1 == "--help" ] || [ $1 == "-h" ] || [ $1 == "/?" ]; then
echo "check ticket offline, using regexp; usage:"
echo "script (-v) [filename]"
echo "-v = verbose, optional; dumps messages, not just the exit codes"
echo "filename = name of the file containing the commit message, required"
exit 0
fi
# is verbose?
if [ $1 == "-v" ]; then
VERBOSE=1
FILENAME=$2
else
VERBOSE=0
FILENAME=$1
fi
# error exit
die () {
echo "ERROR: Jira ticket ID not found!"
exit 1
}
# da magic
TICKET=`cat $FILENAME | grep -E -e'\[[a-zA-Z]+-[0-9]+\]' | head -n1 | sed -n 's/.*\[//p' | sed -n 's/].*//p'`
if [ "$TICKET" == "" ]; then
if [ $VERBOSE -eq 1 ]; then echo "no ticket pattern found"; fi
die
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment