config ベースで Git hook を共有する

🪝
note

Git 2.54 で、従来の hooks に加えて config を設定することでも hook を設定できるようになった。

例えば TS で oxlint を使うような場合なら、 .gitconfig として次のようなファイルを作っておき、

[hook "oxlint"]
	event = pre-commit
	command = pnpm exec oxlint src

これを package.json の postinstall あたりで設定するようにしておく。

{
  "scripts": {
    "postinstall": "git config --local include.path ../.gitconfig && git hook list pre-commit"
  },
}

こうしておくと pnpm i などをしたタイミングで Git hook も設定される。適用を個人に任せたり別で実行するかなんかは好み。

yaakai.to