Skip to content

Instantly share code, notes, and snippets.

@garaemon
Created December 19, 2012 00:34
Show Gist options
  • Save garaemon/4333414 to your computer and use it in GitHub Desktop.
Save garaemon/4333414 to your computer and use it in GitHub Desktop.
git commit-msg hook to insert ticket number to the comments of the commits automatically
#!/bin/bash
BRANCH=$(git symbolic-ref HEAD)
grep '^refs #[0-9]\+: ' $1
if [ $? -eq 0 ]; then
exit
fi
ISSUE=$(echo $BRANCH | sed -e 's/^.*-id-\([0-9]*\)$/#\1/')
if [ "$ISSUE" != "$BRANCH" ]; then
echo "Auto append: $ISSUE"
mv $1 $1.$$
echo -n "$ISSUE: " > $1
cat $1.$$ >> $1
rm $1.$$
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment