Skip to content

Instantly share code, notes, and snippets.

@jcf
Forked from tfe/commit-msg.sh
Created June 2, 2009 09:30
Show Gist options
  • Save jcf/122159 to your computer and use it in GitHub Desktop.
Save jcf/122159 to your computer and use it in GitHub Desktop.
#!/opt/local/bin/bash
# .git/hooks/commit-msg
exec < /dev/tty
commit_message=$1
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
branch=${ref#refs/heads/}
# Exit if commit message empty
if [[ ! -n $(grep '^[^#]' "$1" | sed -e 's/^ *//g;s/ *$//g') ]]; then
echo >&2 Aborting commit due to empty commit message.
exit 1
fi
# Check branch name is in the format 123-ticket-name
if [[ $branch =~ ^([0-9]+)-.*$ ]]; then
lighthouse_ticket=${BASH_REMATCH[1]}
echo "Update state of ticket #${lighthouse_ticket}? "
echo "(o)pen"
echo "(h)old"
echo "(r)esolved"
echo "Hit return to use the existing state: "
state=""
read state_selection
case $state_selection in
"o")
state=" state:open"
;;
"h")
state=" state:hold"
;;
"r")
state=" state:resolved"
;;
esac
echo >&2 "[#${lighthouse_ticket}${state}]" >> "$1"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment