Created
September 7, 2012 05:42
-
-
Save saturday06/3663511 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# -*- coding: utf-8 -*- | |
# ブランチ名に、ここで指定した文字が含まれる場合、この文字に続く数値がチケット番号であるとする | |
# 例えば PREFIX=ticket- とし、 ticket-123 というブランチで作業した場合、123がチケット番号とする | |
PREFIX=ticket/ | |
commit_msg_path=$1 | |
# ブランチ名を取得 | |
branch_name="`git branch | grep -F "*" | awk '{print $2}'`" | |
echo $0: branch_name=$branch_name | |
# issue_idを取得 | |
command="echo $branch_name | grep -E '$PREFIX[0-9]+' | sed 's%.*$PREFIX\\([0-9]\\+\\).*%\\1%'" | |
issue_id=`eval $command` | |
# issue_idが取得出来なかったら終了 | |
if [ "$issue_id" = "" ]; then | |
echo $0: issue_id not found | |
exit 0 | |
fi | |
# コミットメッセージのヘッダーを組み立て | |
echo $0: issue_id=$issue_id | |
header="refs #$issue_id" | |
echo $0: header=$header | |
# すでに$headerがコミットメッセージに含まれていたら終了 | |
cat $commit_msg_path | grep --only-matching "refs #[0-9]+" | grep "^$header$" | |
if [ $? -eq 0 ]; then | |
echo $0: header=$header already written | |
exit 0 | |
fi | |
# コミットメッセージを加工 | |
echo $0: commit_msg_path=$commit_msg_path | |
temp_commit_msg_path=$commit_msg_path.foobar.$$.tmp | |
cp $commit_msg_path $temp_commit_msg_path | |
echo "$header " | tr -d '\n' | cat - $temp_commit_msg_path > $commit_msg_path | |
rm $temp_commit_msg_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment