LoginSignup
1
0

More than 5 years have passed since last update.

branch名にuser storyのidを入れてコミットメッセージにuser storyのURLを自動で貼る

Last updated at Posted at 2015-08-30

追記: 実際使ってみたら上手く動作しなかったため、調べ直して使用するhookを変更しました。Qiitaでも既出のネタでしたね :sweat:

ここにPivotal Trackerのstoryがあるじゃろ?

これの末尾の「stories/123456789」の部分だけ抜き出すと、

$ git checkout -b stories/123456789

user storyに対応したbranchができるじゃろ?

これを↓の .git/hooks/prepare-commit-msgと組み合わせて

.git/hooks/prepare-commit-msg
#!/bin/bash

story_id=$(git rev-parse --abbrev-ref HEAD | sed -n 's#.*stories/\([0-9]\+\).*#\1#p')
story_url=https://www.pivotaltracker.com/story/show/$story_id

if [ -n "$story_id" ] && ! grep --quiet -e $story_url $1 ; then
  echo >> $1
  echo user story: $story_url >> $1
fi
$ chmod +x .git/hooks/prepare-commit-msg

いつもどおりgit commitすれば、

2015-08-commit-message-with-url.png

user storyへのURL付きコミットメッセージの出来上がりじゃ。

参考

【Github時代のgit hook】issue番号を勝手にcommit commentに入れてくれるやつ - Qiita
How to get current branch name in Git? - Stack Overflow

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0