comparison hgext/rebase.py @ 25070:bd98d073a34f stable

rebase: clear merge when aborting before any rebasing (issue4661) The check of the inrebase function was not correct, and it failed to consider the situation in which nothing has been rebased yet, *and* the working dir had been updated away from the initial revision. But this is easy to fix. Given the rebase state, we know exactly where we should be standing: on the first unrebased commit. We check that instead. I also took the liberty to rename the function, as "inrebase" doesn't really describe the situation: we could still be in a rebase state yet the user somehow forcibly updated to a different revision. We also check that we're in a merge state, since an interrupted merge is the only "safe" way to interrupt a rebase. If the rebase got interrupted by power loss or whatever (so there's no merge state), it's still safer to not blow away the working directory.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sun, 10 May 2015 10:57:24 -0400
parents 4ec40a4db64a
children d1bd0fd07ee6 91c2278c68a3
comparison
equal deleted inserted replaced
25069:01ad8daae5be 25070:bd98d073a34f
839 except IOError, err: 839 except IOError, err:
840 if err.errno != errno.ENOENT: 840 if err.errno != errno.ENOENT:
841 raise 841 raise
842 raise util.Abort(_('no rebase in progress')) 842 raise util.Abort(_('no rebase in progress'))
843 843
844 def inrebase(repo, originalwd, state): 844 def needupdate(repo, state):
845 '''check whether the working dir is in an interrupted rebase''' 845 '''check whether we should `update --clean` away from a merge, or if
846 somehow the working dir got forcibly updated, e.g. by older hg'''
846 parents = [p.rev() for p in repo.parents()] 847 parents = [p.rev() for p in repo.parents()]
847 if originalwd in parents: 848
849 # Are we in a merge state at all?
850 if len(parents) < 2:
851 return False
852
853 # We should be standing on the first as-of-yet unrebased commit.
854 firstunrebased = min([old for old, new in state.iteritems()
855 if new == nullrev])
856 if firstunrebased in parents:
848 return True 857 return True
849
850 for newrev in state.itervalues():
851 if newrev in parents:
852 return True
853 858
854 return False 859 return False
855 860
856 def abort(repo, originalwd, target, state, activebookmark=None): 861 def abort(repo, originalwd, target, state, activebookmark=None):
857 '''Restore the repository to its original state. Additional args: 862 '''Restore the repository to its original state. Additional args:
875 "can't strip\n")) 880 "can't strip\n"))
876 cleanup = False 881 cleanup = False
877 882
878 if cleanup: 883 if cleanup:
879 # Update away from the rebase if necessary 884 # Update away from the rebase if necessary
880 if inrebase(repo, originalwd, state): 885 if needupdate(repo, state):
881 merge.update(repo, originalwd, False, True, False) 886 merge.update(repo, originalwd, False, True, False)
882 887
883 # Strip from the first rebased revision 888 # Strip from the first rebased revision
884 rebased = filter(lambda x: x >= 0 and x != target, state.values()) 889 rebased = filter(lambda x: x >= 0 and x != target, state.values())
885 if rebased: 890 if rebased: