Skip to content

Instantly share code, notes, and snippets.

@gorenje
Created June 7, 2011 11:29
Show Gist options
  • Save gorenje/1012062 to your computer and use it in GitHub Desktop.
Save gorenje/1012062 to your computer and use it in GitHub Desktop.
commit-msg goes into .git/hooks/commit-msg (chmod 755)
#!/bin/sh
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
ref=${ref#refs/heads/}
# allow for branch names:
# tick12+12_fubar
# tick12+12-fubar_sd
# ticket12+12-fubar_sd
# ticket12+12+123-fubar_sd
# or tick(et) replaced by issue (redmine conform)
# issue12+12
# etc.
tick_num=$(echo "$ref" | gawk '// { match($0,"(issue|tick(et)?)[_]?([0-9+]+)",a); gsub( "+", " ", a[3]); printf a[3]; }')
if [ "$(cat $1 | grep -v ^#)" == "" ] ; then
# commit message completely empty, commit should be aborted.
exit 0
fi
if [ "$tick_num" != "" ] ; then
echo "" >> $1
for n in $tick_num ; do
echo "refs #"${n} >> $1
done
fi
echo "" >> $1
echo "On branch: ${ref}" >> $1
echo "" >> $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment