changeset 19848:577f4c562d52 stable

rebase: catch RepoLookupError at restoring rebase state for abort/continue Before this patch, "rebase --abort"/"--continue" may fail, when rebase state is inconsistent: for example, the root of rebase destination revisions recorded in rebase state file is already stripped manually. Mercurial earlier than 2.7 allows users to do anything other than starting new rebase, even though current rebase is not finished or aborted yet. So, such inconsistent rebase states may be left and forgotten in repositories. This patch catches RepoLookupError at restoring rebase state for abort/continue, and treat such state as "broken".
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 01 Oct 2013 00:35:07 +0900
parents 45c3086880c7
children e7fa36d2ad3a
files hgext/rebase.py tests/test-rebase-abort.t
diffstat 2 files changed, 36 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Tue Oct 01 00:35:07 2013 +0900
+++ b/hgext/rebase.py	Tue Oct 01 00:35:07 2013 +0900
@@ -159,8 +159,19 @@
             if opts.get('tool', False):
                 ui.warn(_('tool option will be ignored\n'))
 
-            (originalwd, target, state, skipped, collapsef, keepf,
-                keepbranchesf, external, activebookmark) = restorestatus(repo)
+            try:
+                (originalwd, target, state, skipped, collapsef, keepf,
+                 keepbranchesf, external, activebookmark) = restorestatus(repo)
+            except error.RepoLookupError:
+                if abortf:
+                    clearstatus(repo)
+                    repo.ui.warn(_('rebase aborted (no revision is removed,'
+                                   ' only broken state is cleared)\n'))
+                    return 0
+                else:
+                    msg = _('cannot continue inconsistent rebase')
+                    hint = _('use "hg rebase --abort" to clear borken state')
+                    raise util.Abort(msg, hint=hint)
             if abortf:
                 return abort(repo, originalwd, target, state)
         else:
--- a/tests/test-rebase-abort.t	Tue Oct 01 00:35:07 2013 +0900
+++ b/tests/test-rebase-abort.t	Tue Oct 01 00:35:07 2013 +0900
@@ -75,6 +75,29 @@
   |
   o  0:draft 'C1'
   
+Test safety for inconsistent rebase state, which may be created (and
+forgotten) by Mercurial earlier than 2.7. This emulates Mercurial
+earlier than 2.7 by renaming ".hg/rebasestate" temporarily.
+
+  $ hg rebase -s 3 -d 2
+  merging common
+  warning: conflicts during merge.
+  merging common incomplete! (edit conflicts, then use 'hg resolve --mark')
+  unresolved conflicts (see hg resolve, then hg rebase --continue)
+  [1]
+
+  $ mv .hg/rebasestate .hg/rebasestate.back
+  $ hg update --quiet --clean 2
+  $ hg --config extensions.mq= strip --quiet "destination()"
+  $ mv .hg/rebasestate.back .hg/rebasestate
+
+  $ hg rebase --continue
+  abort: cannot continue inconsistent rebase
+  (use "hg rebase --abort" to clear borken state)
+  [255]
+  $ hg rebase --abort
+  rebase aborted (no revision is removed, only broken state is cleared)
+
   $ cd ..