Skip to content

Instantly share code, notes, and snippets.

@chris-gunawardena
Created February 18, 2016 23:32
Show Gist options
  • Save chris-gunawardena/0eb61c0cad23ddefddd1 to your computer and use it in GitHub Desktop.
Save chris-gunawardena/0eb61c0cad23ddefddd1 to your computer and use it in GitHub Desktop.
Goes inside /.git/hooks
#!/bin/bash
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop test)
fi
BRANCH_NAME=$(git symbolic-ref --short HEAD)
#echo $BRANCH_NAME
JIRA_NUMBER=$(echo $BRANCH_NAME | sed -ne 's/.*\/\([A-Z]\{1,6\}-[0-9]\{1,6\}\).*/\1/p')
#echo $JIRA_NUMBER
IS_BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
#echo $IS_BRANCH_EXCLUDED
if [ -n "$JIRA_NUMBER" ] && ! [[ $IS_BRANCH_EXCLUDED -eq 1 ]]; then
sed -i.bak -e "1s/^/$JIRA_NUMBER /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment