Skip to content

Instantly share code, notes, and snippets.

@PallCreaker
Created April 22, 2014 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PallCreaker/11166664 to your computer and use it in GitHub Desktop.
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
[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"
コミットにチケット情報入れてーーー
$ cd レポジトリのトップの階層に
$ vim .git/hooks/commit-msg
$ chmod +x .git/hooks/commit-msg
#!/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
[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 #
$ cd レポジトリのトップの階層に
$ vim .git/hooks/prepare-commit-msg
$ chmod +x .git/hooks/prepare-commit-msg
#!/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