Mercurial > hg
comparison mercurial/dispatch.py @ 29129:e6dfb0e4eeef
dispatch: add fail-* family of hooks
The post-* family of hooks will not run in case a command fails (i.e.
raises an exception). This makes it inconvenient to hook into events
such as doing something in case of a failed push.
We catch all exceptions to run the failure hook. I am not sure if this
is too aggressive, but tests apparently pass.
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 28 Apr 2016 10:37:47 -0400 |
parents | f1081aea19b1 |
children | 12769703d4ba |
comparison
equal
deleted
inserted
replaced
29128:e521cb13d354 | 29129:e6dfb0e4eeef |
---|---|
631 | 631 |
632 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): | 632 def runcommand(lui, repo, cmd, fullargs, ui, options, d, cmdpats, cmdoptions): |
633 # run pre-hook, and abort if it fails | 633 # run pre-hook, and abort if it fails |
634 hook.hook(lui, repo, "pre-%s" % cmd, True, args=" ".join(fullargs), | 634 hook.hook(lui, repo, "pre-%s" % cmd, True, args=" ".join(fullargs), |
635 pats=cmdpats, opts=cmdoptions) | 635 pats=cmdpats, opts=cmdoptions) |
636 ret = _runcommand(ui, options, cmd, d) | 636 try: |
637 # run post-hook, passing command result | 637 ret = _runcommand(ui, options, cmd, d) |
638 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), | 638 # run post-hook, passing command result |
639 result=ret, pats=cmdpats, opts=cmdoptions) | 639 hook.hook(lui, repo, "post-%s" % cmd, False, args=" ".join(fullargs), |
640 result=ret, pats=cmdpats, opts=cmdoptions) | |
641 except Exception: | |
642 # run failure hook and re-raise | |
643 hook.hook(lui, repo, "fail-%s" % cmd, False, args=" ".join(fullargs), | |
644 pats=cmdpats, opts=cmdoptions) | |
645 raise | |
640 return ret | 646 return ret |
641 | 647 |
642 def _getlocal(ui, rpath, wd=None): | 648 def _getlocal(ui, rpath, wd=None): |
643 """Return (path, local ui object) for the given target path. | 649 """Return (path, local ui object) for the given target path. |
644 | 650 |