[PATCH 1 of 2] rebase: ensure we can abort from a stale rebase

Jason Harris jason.f.harris at gmail.com
Sun Nov 21 12:31:11 CST 2010


# HG changeset patch
# User jfh <jason at jasonfharris.com>
# Date 1290363222 -3600
# Node ID ec298433080bb12de80ad9657abb1bdad65fdcba
# Parent  a9dac2fb64b7ad324669f37798b3abfa3ef53086
rebase: ensure we can abort from a stale rebase

After doing a rebase which fails (due to conflicts, etc), and then removing the
changesets the rebase referenced, we cannot later exit from the rebase by using
rebase --abort.  That is, while rebase is setting up to do the abort of the
previous rebase, an exception is raised since it can't find the previous
changesets in the repo and so the rebase --abort terminates before resetting the
rebasestate.  Repeated uses of rebase --abort will not get around this.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -14,7 +14,7 @@
 http://mercurial.selenic.com/wiki/RebaseExtension
 '''
 
-from mercurial import hg, util, repair, merge, cmdutil, commands
+from mercurial import hg, util, repair, merge, cmdutil, commands, error
 from mercurial import extensions, ancestor, copies, patch
 from mercurial.commands import templateopts
 from mercurial.node import nullrev
@@ -109,11 +109,22 @@
             if srcf or basef or destf:
                 raise util.Abort(
                     _('abort and continue do not allow specifying revisions'))
-
-            (originalwd, target, state, skipped, collapsef, keepf,
+            
+            try:
+                (originalwd, target, state, skipped, collapsef, keepf,
                                 keepbranchesf, external) = restorestatus(repo)
-            if abortf:
-                return abort(repo, originalwd, target, state)
+            except error.RepoLookupError:
+                if abortf:
+                    # We can't even correctly read the rebasestate so delete it
+                    # and really abort
+                    repo.ui.warn(_('previous rebase aborted\n'))
+                    clearstatus(repo)
+                    return 0
+                else:
+                    raise
+            else:
+                if abortf:
+                    return abort(repo, originalwd, target, state)
         else:
             if srcf and basef:
                 raise util.Abort(_('cannot specify both a '


More information about the Mercurial-devel mailing list