Create global pre-commit hooks for entire team

六月ゝ 毕业季﹏ 提交于 2019-12-21 11:34:09

问题


How can I create a global pre-commit hook that is available for everyone in the team to use? Basically, I want that anytime someone clones the remote repository he should get this global pre-commit hook by default.

I came across this change default git hooks, Git commit hooks - global settings and this https://coderwall.com/p/jp7d5q where it suggests to create a template directory having common hooks and set init.templatedir to point to this directory. However this is useful only for setting default hooks for yourself on your own machine. How can the pre-commit hook be made available to entire team by default?


回答1:


How can the pre-commit hook be made available to entire team by default?

It can not, as I explained in "Difference between pre-push and pre-receive hook in git?"

And from a security standpoint, that'd be really kind of scary - no one should have the ability to force me to execute certain scripts whenever I run certain git commands

So:

  • using a shared template folder is one way, but supposed all users do know about the --template option of git clone.
  • adding the hooks in a dedicated folder of the repo itself is another, but each user has to decide to symlink those script to their own hooks.

But in any case, remember that a git commit --no-verify would bypass the pre-commit hook anyway.

That is why a server-side hook is safer (as discussed in "Difference between pre-push and pre-receive hook in git?") and will catch all bad commits pushed to a blessed repo.

That is not say a pre-commit hook is useless: if you can convince the users to activate it, it will help catch error sooner, which is a good thing.
But it cannot be enforced "automatically".




回答2:


Luckily there is not a way to force hooks to people upon clone.

If there was, you could write a post-receive hook with rm -rf / in it and wipe people's hard disk on pull



来源:https://stackoverflow.com/questions/25062860/create-global-pre-commit-hooks-for-entire-team

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!