Created
April 22, 2014 05:51
-
-
Save PallCreaker/11166664 to your computer and use it in GitHub Desktop.
GitHubのissue番号を自動でcommitに書き、issue番号がないコミットははじくようにするgit hooksまとめ! ref: http://qiita.com/PallCreaker/items/c91bc201fb8562c8fbd3
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
[pall@pall:~](79_imgAddAltTag)$ git st | |
# On branch 79_imgAddAltTag | |
# Changes to be committed: | |
# (use "git reset HEAD <file>..." to unstage) | |
# | |
# modified: README.md | |
# | |
[pall@kazumasa:~](79_imgAddAltTag)$ git commit -m "test" | |
コミットにチケット情報入れてーーー |
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
$ cd レポジトリのトップの階層に | |
$ vim .git/hooks/commit-msg | |
$ chmod +x .git/hooks/commit-msg |
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 | |
#チケットに関するログが記載されているかのチェック | |
exp="(?:close|closed|closes|fix|fixed|fixes|addresses|references|refs|re|see)" | |
exp=$exp".?(#[0-9]+(?:(?:[, &]+| *and *)#[0-9]+)*)" | |
grep -E "$exp" $1 > /dev/null | |
if [ $? -ne 0 ]; then | |
echo 'コミットにチケット情報入れてーーー' | |
exit 1 | |
fi |
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
[pall@pall:~](79_imgAddAltTag)$ git commit | |
1 refs#79 | |
2 | |
3 # Please enter the commit message for your changes. Lines starting | |
4 # with '#' will be ignored, and an empty message aborts the commit. | |
5 # On branch 79_imgAddAltTag | |
6 # Changes to be committed: | |
7 # (use "git reset HEAD <file>..." to unstage) | |
8 # | |
9 # modified: README.md | |
10 # |
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
$ cd レポジトリのトップの階層に | |
$ vim .git/hooks/prepare-commit-msg | |
$ chmod +x .git/hooks/prepare-commit-msg |
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 | |
if [ "$2" == "" ] ; then | |
mv $1 $1.tmp | |
echo "refs #`git branch | grep "*" | awk '{print $2}' | sed -e "s/^\([0-9]*\).*/\1/g"`" > $1 | |
cat $1.tmp >> $1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment