Can I "break" an hg working copy in such a way that it must be reverted before commit?

StackOverflow https://stackoverflow.com/questions/23228229

  •  07-07-2023
  •  | 
  •  

Question

I have a utility script that will configure the local developer instance to mimic a specific production one - copy over the correct connection strings, client files, etc - thereby making it easy to investigate certain issues.

Because this is all done locally this changes files in the working directory. The first thing the script does therefore is print out a big fat warning to caution developers not to commit and revert changes when they are done. However it is possible to forget or miss this warning as cruft from my build system scrolls by and I wonder if its possible to go further.

Is it possible to do something to the hg repo so that a commit will be rejected and the developer would have to revert first?

I realize there are some variables to the question as far as revert what and commit what but given that I'm not even sure that this is possible, I am willing to take close-with-caveats for an answer.

Was it helpful?

Solution

This is exactly what hooks are for. You would need a precommit hook on every repo or possibly the pretxnchangegroup.

By creating a precommit hook (script) that checks for a specific file or a specific change, you can fail the commit and print out whatever warning you need. The return value of the script indicates to mercurial if the transaction is valid or not.

Use the following generic sample to check for the presence of certain files that would be committed, before accepting or rejecting the changesets.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top