はじめに
手順は9割以下のサイトと同じです。やってみたら少しだけ詰まったので、差分をメモしています
目的
issue番号をブランチ名にしているので、それをcommitメッセージにも追加することであとから辿りやすくしたい
手順
hooksディレクトリの確認
本来なら.git/hooks
ディレクトリがある。ない場合はリポジトリrootでgit init
コマンドを実行する
任意のリポジトリ内の.git/hooks/commit-msg.sample
を.git/hooks/commit-msg
にリネームする
直接ファイル作成をするとcommit時に正しく起動しなかったので、.sample
ファイルをリネームした
commit-msgファイルを変更
#!/usr/bin/env ruby message_file = ARGV[0] message = File.read(message_file, :encoding => Encoding::UTF_8) current_branch = `git branch | grep '*'`.chomp.sub('* ', '') current_branch = current_branch[current_branch.rindex("/")+1 .. current_branch.length] newmessage = message.sub(/branchname/, current_branch) File.write(message_file, newmessage)
SourceTreeの設定からコミットテンプレートを変更する
メッセージが置き換わらない
hookのスクリプトが動いていない
$ pwd <repo>/.git/hooks $ chmod +x commit-msg