LoginSignup
40
40

More than 5 years have passed since last update.

gitのhookでtags作成

Posted at

git pull とかcheckoutで勝手にtags作成してほしかったので調べた時のをメモ。
プロジェクトのルートディレクトリ直下の.git/hooksディレクトリにhookさせるファイルを置けば良いんだけど毎回置くのも面倒なので勝手に作ってくれる設定

command
cd
mkdir -p .git_tmp/hooks
cd .git_tmp/hooks
touch post-commit # git commit hook
touch post-merge # git merge, git pull hook
touch post-checkout # git checkout hook
touch ctags
chmod +x *

post-系、ctagsの中の記述は以下

post-系
#!/bin/sh
.git/hooks/ctags >/dev/null 2>&1 &
ctags
#!/bin/sh
/usr/local/bin/ctags -R .

git init時に自動的に作成したhooksファイルが作成されるように以下を流す。

command
cd
git config --global init.templatedir '.git_tmp' 

既存のgitプロジェクトにはgit initコマンドを打てば設定したhooksが反映される。既にあるファイルは上書きされないみたいです。

vim-fugitiveを使っている場合

やらなくてもいいんだけど
vim-fugitiveはtagsの読み込み場所を追加してくれているようだ。

.git/tagsを閲覧できるようになっている。
https://github.com/tpope/vim-fugitive/blob/master/plugin/fugitive.vim#L154

tagsが普段見えないところに置ける。せっかくなのでそこに追加してあげる記述方法は以下。

ctags
#!/bin/sh
/usr/local/bin/ctags -R -f .git/tags `pwd`

参考

40
40
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
40
40