Skip to content

Instantly share code, notes, and snippets.

@brb
Created August 1, 2013 08:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brb/6129507 to your computer and use it in GitHub Desktop.
Save brb/6129507 to your computer and use it in GitHub Desktop.
Git hook for appending an issue id into commit messages. The issue id is taken from branch name which should be in a "foobar-ISSUE-ID" format.
#!/bin/bash
regexp=".*-([A-Z].*-[0-9]*)"
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [[ "$branch" =~ $regexp ]]; then
refs_id=${BASH_REMATCH[1]}
if [ "$2" = message ]; then
echo -ne "\n${refs_id}" >> "$1"
else
sed -i "1s/^$/\n\n${refs_id}/g" "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment