Option 1:
As mentioned, the direct way to do this with Git is with hook-commit-message .
However, there are problems with this strategy that need to be considered. From chapter 7.4 Pro Git:
[Client side scripts] arent passed with the project clone, you have to distribute these scripts differently, and then your users copy them into their .git / hooks and make them an executable. You can distribute these hooks within the project or in a separate project, but there is no way to automatically configure.
Option 2:
As mentioned by Tom Morris , use a commit pattern .
Option 3:
You can make a custom Git build that includes your additional instructions. The instructions included in the current commit message are hardcoded in the Git source code. See $GIT_SRC/builtin/commit.c starting at line 655 .
This method is probably not preferred since you will have to apply the patch every time a new version of Git is released.
Option 4:
Create a patch for Git that adds this feature and sends it to the mailing list. If you (or others) decide to try this, I will first ask for advice from the list on how to proceed.
Mercurial:
Hook scripts in Mercurial behave similarly. From Chapter 10 Mercurial: The Complete Guide:
In Mercurial, interceptors are not reviewed, controlled, or distributed when you clone or retrieve from the repository. The reason for this is simple: the hook is a completely arbitrary part of the executable code. It works under your user identity, with your privilege level on your machine.
It would be extremely reckless for any distributed version control system to intercept with control, as this is a suitable way to undermine the user accounts of the revision of the control system.
Tim Henigan
source share