Roger Binns
Roger Binns

Reputation: 3348

How to use a relative pathname to a Mercurial hook

I have a script that is in the top level of my working copy and would like to use it as a Mercurial hook. If I use an absolute pathname to the hook then everything is fine, but I want a relative pathname so the whole thing can be easily moved around, used in other working copies and other developers can copy the hgrc as is.

/space/project/.hg/hgrc contains

[hooks]
update = genid

The genid script is at /space/project/genid

The hook is invoked just fine if I am in /space/project but if my current directory is /space/project/src/tools then 'hg update' will give an error as the hook cannot be found.

Upvotes: 5

Views: 969

Answers (3)

pyfunc
pyfunc

Reputation: 66729

In certain cases, environment variables are expanded in mercurial configuration. So you can check out if you can use a environment variable.

[hooks]
update = $MercurialHooks/genid

See Faq (12) in https://www.mercurial-scm.org/wiki/TipsAndTricks

Upvotes: 2

JonnyRaa
JonnyRaa

Reputation: 8038

I had the same problem and couldnt resolve it. The workaround was easy though! I versioned the file in the repo and just copied it to my .hg folder! Not ideal but it isnt that likely to change and other repo users can still get a copy of the file

Upvotes: 0

Roger Binns
Roger Binns

Reputation: 3348

Python hooks cannot use a relative path. Script hooks can like this:

[hooks]
update = ./genid

Upvotes: 2

Related Questions