Can Git hook scripts be managed along with the repository?

前端 未结 11 1164
独厮守ぢ
独厮守ぢ 2020-11-22 14:00

We\'d like to make a few basic hook scripts that we can all share -- for things like pre-formatting commit messages. Git has hook scripts for that that are normally stored

11条回答
  •  温柔的废话
    2020-11-22 14:22

    For Nodejs users a simple solution is to update package.json with

    {
      "name": "name",
      "version": "0.0.1",
      ......
      "scripts": {
        "preinstall": "git config core.hooksPath hooks", 
    

    The preinstall will run before

    npm install

    and redirects git to look for hooks inside the .\hooks (or whatever name you choose) directory. This directory should mimic .\.git\hooks in terms of file name (minus the .sample) and structure.

    Imagine Maven and other build tools will have an equivalent to preinstall.

    It should also work across all platforms.

    If you need any more info see https://www.viget.com/articles/two-ways-to-share-git-hooks-with-your-team/

提交回复
热议问题