diff --git a/hgext3rd/conflictinfo.py b/hgext3rd/conflictinfo.py --- a/hgext3rd/conflictinfo.py +++ b/hgext3rd/conflictinfo.py @@ -55,15 +55,17 @@ ['rebasestate', {'cmd': 'rebase', 'to_continue': 'rebase --continue', 'to_abort': 'rebase --abort'}], - ['merge/state', {'cmd': 'merge', - 'to_continue': 'merge --continue', - 'to_abort': 'update --clean'}], ['shelvedstate', {'cmd': 'unshelve', 'to_continue': 'unshelve --continue', 'to_abort': 'unshelve --abort'}], ['histedit-state', {'cmd': 'histedit', 'to_continue': 'histedit --continue', 'to_abort': 'histedit --abort'}], + # merge should be last, because some of the above leave their own state and + # a merge state in some pathological cases, and need to be aborted first. + ['merge/state', {'cmd': 'merge', + 'to_continue': 'merge --continue', + 'to_abort': 'update --clean'}], ] def extsetup(ui): @@ -72,7 +74,7 @@ # Returns which command got us into the conflicted merge state. Since these # states are mutually exclusive, we can use the existence of any one statefile # as proof of culpability. -def _findconflictcommand(repo): +def findconflictcommand(repo): for path, data in CONFLICTSTATES: if repo.vfs.exists(path): return data @@ -114,7 +116,7 @@ if info is not None: pathconflicts.append(info) - cmd = _findconflictcommand(repo) + cmd = findconflictcommand(repo) formatter.startitem() formatter.write('conflicts', '%s\n', fileconflicts) formatter.write('pathconflicts', '%s\n', pathconflicts) diff --git a/hgext3rd/continue.py b/hgext3rd/continue.py new file mode 100644 --- /dev/null +++ b/hgext3rd/continue.py @@ -0,0 +1,48 @@ +# +# Copyright 2017 Facebook, Inc. +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +"""continues an interrupted command (figures out what command you interupted) +""" + +from mercurial import ( + cmdutil, + dispatch, + error, + extensions, + registrar +) + +from mercurial.i18n import _ + +from hgext3rd.conflictinfo import findconflictcommand + +cmdtable = {} +command = registrar.command(cmdtable) +testedwith = 'ships-with-fb-hgext' + +def _rerun(ui, repo, cmd): + req = dispatch.request(cmd, ui=ui, repo=repo) + dispatch.dispatch(req) + +@command('continue', [], _('hg continue')) +def continuecmd(ui, repo, *revs, **opts): + """continues an interrupted command + """ + cmd = findconflictcommand(repo) + if cmd is None: + raise error.Abort(_('nothing to continue')) + + _rerun(ui, repo, cmd['to_continue'].split(' ')) + +@command('abort', [], _('hg abort')) +def abortcmd(ui, repo, *revs, **opts): + """aborts an interrupted command + """ + cmd = findconflictcommand(repo) + if cmd is None: + raise error.Abort(_('nothing to abort')) + + _rerun(ui, repo, cmd['to_abort'].split(' ')) diff --git a/hgext3rd/undo.py b/hgext3rd/undo.py --- a/hgext3rd/undo.py +++ b/hgext3rd/undo.py @@ -124,7 +124,8 @@ # upstream change. repo.invalidatevolatilesets() safelog(repo, command) - del os.environ['_undologactive'] + if '_undologactive' in os.environ: + del os.environ['_undologactive'] return result