init hook

Angel Ezquerra angel.ezquerra at gmail.com
Mon Apr 2 09:11:34 CDT 2012


On Mon, Apr 2, 2012 at 3:18 PM, Simon King <simon at simonking.org.uk> wrote:
> On Mon, Apr 2, 2012 at 1:23 PM, Angel Ezquerra Moreu
> <angel.ezquerra at gmail.com> wrote:
>> Hi,
>>
>> recently someone sent a patch to the TortoiseHg mailing list which
>> would make tortoisehg create an empty .hgtags file when a repo is
>> initialized (in the same manner that TortoiseHg already can create a
>> .hgignore file for you at init time).
>>
>> The patch has been rejected, since most of us did not believe that it
>> makes much sense, given that the .hgtags file will be automatically
>> created by mercurial when the first tag is added.
>>
>> However, this got me thinking that this particular user's "problem"
>> could have been easily solved if there was an "init" hook that was run
>> when a repo is initialized. I don't think that hook currently exists.
>> Would it make sense to add one?
>>
>> Cheers,
>>
>> Angel
>
> Every mercurial command can have pre-<command> and post-<command> hooks:
>
> # In ~/.hgrc:
> [hooks]
> post-init = env
>
>
> $: hg init testrepo | grep HG
> HG_RESULT=0
> HG_OPTS={'insecure': None, 'mq': None, 'remotecmd': '', 'ssh': ''}
> HG_ARGS=init testrepo
> HG=/usr/local/bin/hg
> HG_PATS=['testrepo']
>
> It's not *quite* as convenient as you probably want, since you'll need
> to parse the repository location out of HG_ARGS or HG_PATS, but it's
> doable.
>
> http://selenic.com/hg/file/4fe81ba56863/mercurial/dispatch.py#l461
>
> Hope that helps,
>
> Simon

Thank you Simon, that works great!

I thought that the pre- and post- hooks only worked with existing
hooks, but the doc says pretty clearly that it applies to all
mercurial commands.

Thanks!

Angel


More information about the Mercurial-devel mailing list