init hook

Simon King simon at simonking.org.uk
Mon Apr 2 08:18:24 CDT 2012


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


More information about the Mercurial-devel mailing list