hgext/rebase.py
branchstable
changeset 25070 bd98d073a34f
parent 24870 4ec40a4db64a
child 25075 d1bd0fd07ee6
child 25101 91c2278c68a3
--- a/hgext/rebase.py	Sun May 10 10:02:15 2015 -0400
+++ b/hgext/rebase.py	Sun May 10 10:57:24 2015 -0400
@@ -841,16 +841,21 @@
             raise
         raise util.Abort(_('no rebase in progress'))
 
-def inrebase(repo, originalwd, state):
-    '''check whether the working dir is in an interrupted rebase'''
+def needupdate(repo, state):
+    '''check whether we should `update --clean` away from a merge, or if
+    somehow the working dir got forcibly updated, e.g. by older hg'''
     parents = [p.rev() for p in repo.parents()]
-    if originalwd in parents:
+
+    # Are we in a merge state at all?
+    if len(parents) < 2:
+        return False
+
+    # We should be standing on the first as-of-yet unrebased commit.
+    firstunrebased = min([old for old, new in state.iteritems()
+                          if new == nullrev])
+    if firstunrebased in parents:
         return True
 
-    for newrev in state.itervalues():
-        if newrev in parents:
-            return True
-
     return False
 
 def abort(repo, originalwd, target, state, activebookmark=None):
@@ -877,7 +882,7 @@
 
     if cleanup:
         # Update away from the rebase if necessary
-        if inrebase(repo, originalwd, state):
+        if needupdate(repo, state):
             merge.update(repo, originalwd, False, True, False)
 
         # Strip from the first rebased revision