3

What are all steps required to validate commit message with set of regular expressions? We want to work in semi-centralized set-up so I need a solution for the developer clone (local repository) and for our central clone (global repository). I read about Mercurial Hooks but I am a little bit lost how to put all things together.

For local repository I need a way to distribute validation script across my developers. I know that hooks do not propagate when cloning so I need to a way to "enable" them in each fresh clone. It would be done as a part of our PrepareEnvironement.bat script that we run anyway on each clean clone.

To be double safe I need similar validation on my global repository. It should not be possible to push into global repository commit that are not validating. I can configure it manually - it is one time job.

I am on Windows so installing anything except TortoiseHG should not be required. It was already a fight to get Mercurial deployed. Any other dependencies are not welcomed.

Vadim Kotov
  • 7,103
  • 8
  • 44
  • 57
Michal Sznajder
  • 9,088
  • 4
  • 40
  • 62
  • I just found http://stackoverflow.com/questions/2451560/how-do-you-access-the-commit-message-in-a-mercurial-in-process-hook and https://bitbucket.org/dls/commit-msg-check-hook/src/ebaacb377171/commit-msg-check-hook.py. It looks like a start... – Michal Sznajder Sep 21 '11 at 21:11
  • What kind of validation do you want to perform ? The answer really depends on this... And what do you mean by "local" or "global" repositories ? There's no such things in Mercurial, I think you will have to describe your particular setup. BTW, you can install nearly all UNIX tools on Windows... – krtek Sep 21 '11 at 22:04

1 Answers1

2

You can use the Spellcheck example as a starting point. In each developer's configuration, you need to use the following hooks:

pretxnchangegroup - Runs after a group of changesets has been brought into local from another repository, but before it becomes permanent.

pretxncommit - Runs after a new changeset has been created in local, but before it becomes permanent.

For the centralized repo, I think you only need the pretxnchangegroup hook unless commits can happen on the server, too. However, you will need the Histedit extension for each of the developers if the remote repo is the one rejecting one or more of the changesets being pushed. This extension allows them to "edit" already committed changesets. I would think in most cases, the local hooks will catch the issue, but like you said, "just in case."

More details about handling events with hooks can be found in the Hg Book.

Sumo
  • 3,900
  • 20
  • 40