diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1073,7 +1073,7 @@ raise error.Abort(_(b'current bisect revision is a merge')) if rev: node = repo[scmutil.revsingle(repo, rev, node)].node() - try: + with hbisect.restore_state(repo, state, node): while changesets: # update state state[b'current'] = [node] @@ -1105,9 +1105,6 @@ # update to next check node = nodes[0] mayupdate(repo, node, show_stats=False) - finally: - state[b'current'] = [node] - hbisect.save_state(repo, state) hbisect.printresult(ui, repo, state, displayer, nodes, bgood) return diff --git a/mercurial/hbisect.py b/mercurial/hbisect.py --- a/mercurial/hbisect.py +++ b/mercurial/hbisect.py @@ -11,6 +11,7 @@ from __future__ import absolute_import import collections +import contextlib from .i18n import _ from .node import ( @@ -180,6 +181,15 @@ raise error.Abort(_(b'cannot bisect (no known bad revisions)')) +@contextlib.contextmanager +def restore_state(repo, state, node): + try: + yield + finally: + state[b'current'] = [node] + save_state(repo, state) + + def get(repo, status): """ Return a list of revision(s) that match the given status: