Created
July 16, 2014 13:42
-
-
Save szkrd/c0cd847288ac261da916 to your computer and use it in GitHub Desktop.
git commit message hook lite
This file contains 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 | |
# 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