Adding HG_DEST for post-clone hook
Ludovic Chabant
ludovic at chabant.com
Tue Jan 8 05:11:40 UTC 2019
> That wasn't a yes/no question, but apparently clone hooks act
> differently than other hooks, in this regard. Looking at CWD would
> answer your question for other hooks.
Clone hooks don't act differently because there are no clone hooks per-se... the only thing that exists (and that the OP uses) is the post-clone hook which actually is a generic "post-<command>" hook, so whatever it passes to the hook'ed script is generic and has no specific knowledge of the command.
It still passes the CWD/args/options that were passed to the original command... so a hacky way to do this is to abuse $HG_PATS and python:
#!/usr/bin/python
import os.path
import ast
import sys
pats = ast.literal_eval(' '.join(sys.argv[1:]))
if len(pats) == 1:
print(os.path.abspath(os.path.basename(pats[0])))
else:
print(os.path.abspath(pats[1]))
It deserializes $HG_PATS (which is the string representation of a python list) into a real python list and then if you invoked "hg clone origin" it takes the filename of "origin" and makes it absolute (since this python script executes in the same CWD as the clone command) or, if you invoked "hg clone origin dest", just takes "dest" and makes it absolute.
Of course the script needs a bit more error handling and such, but that's probably the best that can be done without making a Mercurial patch that adds a proper post-clone hook.... which might actually be not significantly harder than writing that script in the first place :)
--
l u d o .
. 8 0 17 80
More information about the Mercurial
mailing list