What git hook is used to check for pressed commit messages?

I need to check the commit messages that are pushed to the remote server so that the developers do not post enough details (line length) or only the ticket number.

I thought that the update hook would work for this, but it doesn’t seem to, but it only works for the link that was clicked earlier. When I tried to push a new branch, it rejected because I could not find the link. I suspect that it can only work against the last commit in the pressed series as well.

What will be the right choice for this task?

Excerpt:

#!/usr/bin/env php <?php define('MINIMUM_MESSAGE_LENGTH', 10); $exit = 0; // default exit code -> success $ref = $argv[1]; $commitMessage = exec('git log -1 ' . $ref . ' --pretty=format:%s'); $commitMessage = trim($commitMessage); // validations & exit($exit) follow; 

yep is PHP but the question is agnostic language

+5
source share
2 answers

Enforcing policies means "server side hook".

  • A client cache , like pre-commit , can be circumvented and not just deployed.
  • A server-side is deployed once (on the Git repository server), and you're done.

There is an example in the Git Pro book (" Customizing Git - Example Git-Enforced Policy "), which should work for new branches as well as for legacy branches.

You will find other examples in How to check for commit messages for push? "

+4
source

You are correct, the update hook does not work. If you need to enforce the standard dispatch message, you must use the pre-hook. It will run before the latch is made, and make sure it is standard, and then continue and create the commit. Here is an example of a pre-hook hook

https://github.com/git/git/blob/master/templates/hooks--pre-commit.sample

For more info on git hooks check this out

http://githooks.com/

0
source

All Articles