Git remote/shared pre-commit hook

后端 未结 6 1408
失恋的感觉
失恋的感觉 2020-11-28 06:42

With a one official repository as the remote, and multiple local repositories cloned from it, can a pre-commit hook be scripted on that main repository and be enforced on al

6条回答
  •  心在旅途
    2020-11-28 07:15

    Yes and no.

    If you are writing JavaScript, the best way to do this is with Husky. Husky has a postInstall script that will set up and manage your githooks. You can then configure precommit and prepush scripts in your package.json or a husky dotfile.

    You can use this to run arbitrary scripts. I typically yarn lint and yarn test prepush.


    If you are not using JavaScript, or you cannot use Husky, you can clone commit hooks onto developer machines and check them into a repo, but you cannot force developers to run them.

    To check in your hooks, create a hooks directory somewhere in your repo. Then put your hooks there instead of the usual .git/hooks directory. This is the part you can enforce.

    The other part depends on developer goodwill. To set your hooks folder as the hooksPath, each developer must run:

    git config core.hooksPath hooks

    Now all the hooks in the hooks folder will run as you would expect.

提交回复
热议问题