LoginSignup
3
1

More than 3 years have passed since last update.

git の hook script を書くときは GIT_DIR が設定されていることに注意

Posted at

git のpost-updateスクリプトのなかで、git pullさせようとして、bashスクリプトの中で以下のコマンドを使った。

git -C /path/to/git/dir pull

この post-update スクリプトをサーバー側で実行しても何もエラーはでなかったが、いざクライアントからサーバーへ push してみるとエラーが出た。

$ git push
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 266 bytes | 266.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0)
remote: fatal: Not a git repository: '.'
To hogehoge.fuga.jp:/path/to/sample.git
   61c35e6..6a9db99  master -> master

GIT_DIR という環境変数が定義されていて、それが優先されているらしい。 post-updateスクリプトに、

unset GIT_DIR

を追加したら期待通りの動作になった。

参考

3
1
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
3
1