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

Ulrich Thomas Gabor ulrich.thomas.gabor at googlemail.com
Mon Jul 11 21:01:54 UTC 2016


Hi

> Am 11.07.2016 um 22:26 schrieb Ethan Furman <ethan at stoneleaf.us>:
> 
> On 07/11/2016 10:24 AM, Ulrich Thomas Gabor via Mercurial wrote:
> 
>> 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.
> 
> I use:
> 
> [hooks]
> pretxncommit.blacklist = /usr/local/bin/hgblacklist
> pretxncommit.sanity = /usr/local/bin/hgsanity
> 
> to do various checks.  If the hook raises any kind of error the commit is rolled back.

Indeed, at the time pretxncommit is executed the changeset is already created and one can look into that to get a list of those files, which are part of the commit:

def pretxncommit(ui, repo, node, **kwargs):
        print repo[node].files()
        exit(1)

But, as far as I understand, at this time it is too late to change the changeset?

I would like to aid the user in cleaning up his proposed changeset as best as possible. This sometimes requires changing files, which should be included in the changeset. With a precommit hook this is easy, as the changeset has not been constructed yet, and whatever the hook changes is automatically included in the commit. Additionally I do not want to check all changed files, when the user just wants to commit a subset.

I still don't see how I can achieve that?

Best
Ulrich

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial/attachments/20160711/3fe001c1/attachment-0002.html>


More information about the Mercurial mailing list