# HG changeset patch # User Matt Mackall # Date 2008-01-18 15:03:17 # Node ID 2c565b9598b8780cfb1ee10a6226e8f5d0743f4f # Parent 838fa52abcc184c3d0d9a7b333b82f1f2af35352 hooks: fix pre- and post- hooks specified in .hg/hgrc We were looking up hooks in the wrong ui object. Also, we weren't handling hooks to commands without a repo. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -354,12 +354,12 @@ def _dispatch(ui, args): d = lambda: func(ui, *args, **cmdoptions) # run pre-hook, and abort if it fails - ret = hook.hook(ui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) + ret = hook.hook(lui, repo, "pre-%s" % cmd, False, args=" ".join(fullargs)) if ret: return ret ret = _runcommand(ui, options, cmd, d) # run post-hook, passing command result - hook.hook(ui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), + hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), result = ret) return ret diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -71,7 +71,11 @@ def _pythonhook(ui, repo, name, hname, f def _exthook(ui, repo, name, cmd, args, throw): ui.note(_("running hook %s: %s\n") % (name, cmd)) env = dict([('HG_' + k.upper(), v) for k, v in args.iteritems()]) - r = util.system(cmd, environ=env, cwd=repo.root) + if repo: + cwd = repo.root + else: + cwd = os.getcwd() + r = util.system(cmd, environ=env, cwd=cwd) if r: desc, r = util.explain_exit(r) if throw: