Skip to content

Instantly share code, notes, and snippets.

@ivalkeen
Last active August 29, 2015 14:22
Show Gist options
  • Save ivalkeen/66568b4cba5e1c4129ce to your computer and use it in GitHub Desktop.
Save ivalkeen/66568b4cba5e1c4129ce to your computer and use it in GitHub Desktop.
Git hooks
#! /bin/zsh
# if git branch name contains number, add leading [#NNN] to the commit message
# so github will add reference to specific issue
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NUMBER=$(git symbolic-ref --short HEAD | sed "s/[^0-9]//g")
COMMIT_TEXT=$(cat $1)
if [ -n "$BRANCH_NUMBER" ] && ! [[ $COMMIT_TEXT =~ "\[.*#$BRANCH_NUMBER\]" ]]; then
sed -i.bak -e "1s/^/[#$BRANCH_NUMBER] /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment