Last active
August 29, 2015 14:23
-
-
Save iberianpig/084567b6399dad4cde65 to your computer and use it in GitHub Desktop.
ブランチ名がNUMBER_TITLEの時に、自動でコミットメッセージに[#NUMBER]を付与するフックスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sed -i -e "2i \\\n$msg\\n" $1
がmac os xで動いてないぽい