Skip to content

Instantly share code, notes, and snippets.

@ironprice91
Created June 8, 2016 14:14
Show Gist options
  • Select an option

  • Save ironprice91/fca6997834f56a1201164dcb470690f8 to your computer and use it in GitHub Desktop.

Select an option

Save ironprice91/fca6997834f56a1201164dcb470690f8 to your computer and use it in GitHub Desktop.
#!/bin/bash
MSG_FILE=$1
TYPE_STR=$2
MSG_STR=$(cat ${MSG_FILE})
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
TICKET_NUMBER=$(git symbolic-ref --short HEAD)
TICKET_NUMBER="${TICKET_NUMBER##*/}"
if [ $BRANCH_NAME != '(no branch)' ] && [ "${TYPE_STR}" = "message" ]; then
echo -e "\nChecking commit log...\nMessage Type: ${TYPE_STR}\n"
if [[ "${MSG_STR}" =~ ^(TICKET\-) ]]; then
echo "Commit log valid."
elif [[ "${TICKET_NUMBER}" =~ ^(TICKET\-) ]]; then
echo -e "Commiting to branch $TICKET_NUMBER"
sed -i .bak -e "1s/^/$TICKET_NUMBER :: /" $1
else
echo -e "Error: Your commit log must start with a JIRA ticket!\n"
exit 1;
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment