Skip to content

Instantly share code, notes, and snippets.

@nishimura
Created December 3, 2010 06:51
Show Gist options
  • Save nishimura/726661 to your computer and use it in GitHub Desktop.
Save nishimura/726661 to your computer and use it in GitHub Desktop.
Add issue id to commit message.
#!/bin/bash
BRANCH=$(git symbolic-ref HEAD)
if [ "$BRANCH" == "refs/heads/master" ]; then
echo "cannot commit on master branch."
echo "please commit on topic branch."
exit 1
fi
grep '^refs #[0-9]\+: ' $1
if [ $? -eq 0 ]; then
exit
fi
ISSUE=$(echo $BRANCH | sed -e 's/^.*-id-\([0-9]\+\)$/refs #\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