Skip to content

Instantly share code, notes, and snippets.

@iberianpig
Last active August 29, 2015 14:23
Show Gist options
  • Save iberianpig/084567b6399dad4cde65 to your computer and use it in GitHub Desktop.
Save iberianpig/084567b6399dad4cde65 to your computer and use it in GitHub Desktop.
ブランチ名がNUMBER_TITLEの時に、自動でコミットメッセージに[#NUMBER]を付与するフックスクリプト
#!/bin/sh
# set to repository/.git/hooks/prepare-commit-msg
# chmod +x prepare-commit-msg
COMMIT_EDITMSG=$1
mv $COMMIT_EDITMSG $COMMIT_EDITMSG.tmp
number=`git branch | grep "*" | awk '{print $2}' | sed -e "s/^\([0-9]*\).*/\1/g"`
msg=""
note="# NOTE: automatically add NUMBER to commit message if you set branch's name like NUMBER_TITLE"
if [ "$2" != "message" ] ; then # without "commit message"
if [ "$number" = "" ] ; then # without NUMBER
msg="\n$note"
echo "$note"
else # with NUMBER
msg="#[#$number]"
fi
else # with "commit message"
if [ "$number" = "" ] ; then # without NUMBER
echo "$note"
else # with NUMBER
msg="[#$number]"
fi
fi
echo $msg >> $COMMIT_EDITMSG
cat $COMMIT_EDITMSG.tmp >> $COMMIT_EDITMSG
rm $COMMIT_EDITMSG.tmp
@iberianpig
Copy link
Author

sed -i -e "2i \\\n$msg\\n" $1
がmac os xで動いてないぽい

@iberianpig
Copy link
Author

上記を利用しないようにした

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment