[PATCH STABLE] rebase: ignore negative state when updating back to original wc parent

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Dec 2 20:21:30 UTC 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1417547198 28800
#      Tue Dec 02 11:06:38 2014 -0800
# Branch stable
# Node ID dcda24083017b829f38f8f58a96704f3a72e4961
# Parent  2b1ffaaab01f4068f4e1b1291654bf49d334d5d9
rebase: ignore negative state when updating back to original wc parent

The state mapping also contains some magic negative value (detached parent,
ignored revision). Blindly reading state leads to unfortunate usage of such
value as update destination. We now filter them out.

We do minor alteration of the test to catch this.

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -447,10 +447,13 @@ def rebase(ui, repo, **opts):
             targetnode = repo[target].node()
 
         # restore original working directory
         # (we do this before stripping)
         newwd = state.get(originalwd, originalwd)
+        if newwd < 0:
+            # original directory is a parent of rebase set root or ignored
+            newwd = originalwd
         if newwd not in [c.rev() for c in repo[None].parents()]:
             ui.note(_("update back to initial working directory parent\n"))
             hg.updaterepo(repo, newwd, False)
 
         if not keepf:
diff --git a/tests/test-rebase-scenario-global.t b/tests/test-rebase-scenario-global.t
--- a/tests/test-rebase-scenario-global.t
+++ b/tests/test-rebase-scenario-global.t
@@ -298,12 +298,16 @@ Check rebasing public changeset
 
   $ hg rebase -d 5 -b 6 --keep
 
 Check rebasing mutable changeset
 Source phase greater or equal to destination phase: new changeset get the phase of source:
+  $ hg id -n
+  5
   $ hg rebase -s9 -d0
   saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2b23e52411f4-backup.hg (glob)
+  $ hg id -n # check we updated back to parent
+  5
   $ hg log --template "{phase}\n" -r 9
   draft
   $ hg rebase -s9 -d1
   saved backup bundle to $TESTTMP/a7/.hg/strip-backup/2cb10d0cfc6c-backup.hg (glob)
   $ hg log --template "{phase}\n" -r 9


More information about the Mercurial-devel mailing list