Skip to content

Instantly share code, notes, and snippets.

@aaronstaves
Created August 4, 2014 22:01
Show Gist options
  • Save aaronstaves/eca5dd4b692f6cfb34b9 to your computer and use it in GitHub Desktop.
Save aaronstaves/eca5dd4b692f6cfb34b9 to your computer and use it in GitHub Desktop.
JIRA branch names commit hooks
#!/bin/bash
line=`head -n 1 "$1"`
if [[ ${#line} == 0 ]]
then
echo "No commit message, commit aborted"
exit -1
else
exit 0
fi
# Put in BASE_DIR/.git/hooks/commit-msg. Make Executable.
#!/bin/bash
branch=`git rev-parse --abbrev-ref HEAD`
branchRegex='([A-Z_]+?)(-[0-9]+)'
if [[ $branch =~ $branchRegex ]]
then
sed -i "1s/^/\n\n${BASH_REMATCH[1]}${BASH_REMATCH[2]}/" $1
fi
# Put in BASE_DIR/.git/hooks/prepare-commit-msg. Make executable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment