简体   繁体   中英

How to mendate pre-commit hook in local system

In all the repository.pre-commit-config.yaml files are added. This pre-commit hook is responsible to validate commit message and if it is not as per standard then it will generate error.

Now when someone commits into local system at the same time hook should be triggered.For the same it is required to install:

pre-commit install --hook-type commit-msg
pre-commit install

If above commands are not executed on any developer's local system then pre-commit will not executed. Of course, there can be guidelines for developer that to install pre-commit related stuff but there are chances to miss it.

So is there any way where it can be enforced to install pre-commit related stuff automatically or if developer has not installed then there can be error that please install pre-commit-hook on local machine before proceeding, without this commit should not work?

For any client-side Git hook , you have the same issue of deployment: you need to deploy to all client:

  • either the hook itself (here installed through a sequence of command)
  • or a git wrapper which, before executing git , checks if the hook is installed and, if not (and if executed inside a Git repository) installs it.

I usually use the second option, considering that my Git users are all from the same company: they install Git with my installation program.

That would not work with an open source project, where the contributors are not from the same organization, but scattered all over the globe.

If you have access to the remote repository, adding a (server-side) pre-receive hook to validate the commit message is recommended: you can reject a push, and add instruction for the developer to install the pre-commit hook then.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM