before commit hook; list files to be committed respecting cmd arguments?

Bob Hood bhood2 at comcast.net
Mon Jul 11 19:55:34 UTC 2016


On 7/11/2016 11:24 AM, Ulrich Thomas Gabor via Mercurial wrote:
> Hi
>
> I'd like to write an in-process Python hook that runs a check on the files that will be committed and based on that information has the possibility to abort the commit process.
>
> My first attempt was to use a precommit hook, which can abort a commit, but I did not find a possibility to get a list of all the files, which will be committed. There is repo[None].files(), which lists all the files that have changed, but it does not respect command line arguments. When someone appends file arguments to the hg call (e.g. hg commit -m "lorem" only_this_file.txt) I found no possibility to respect this "filter". The files method always returns all files.
>
> Is there a way to get a list of only those files, which have changed and will actually be processed by mercurial respecting the passed command line arguments?

Just a thought...

The information you need may not actually be available on the server side with 
the precommit hook.  You might want to look using a pretxnchangegroup hook 
instead.  This is called when the commits have been applied to the repository, 
but /before/the transaction is completed.  At that stage, everything you need 
to know is there (including the files that are being added/changed/removed).

If you abort the hook, then the transaction is rolled back, and you can send 
an error to the client.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20160711/f2ffda91/attachment-0002.html>


More information about the Mercurial mailing list