changeset 9578:341182ac95e4

rebase: return early when source is descendant of destination This only happens when using --base (or no source selection options), as rebase already aborts in this situation when using --source. Without this change you get an abort from the underlying merge, and the repository is in a different state than you started with (the working dir parent is changed).
author Sune Foldager <cryo@cyanite.org>
date Thu, 08 Oct 2009 10:39:43 +0200
parents b91960aed018
children c06e7581bbaa
files hgext/rebase.py tests/test-rebase-scenario-global tests/test-rebase-scenario-global.out
diffstat 3 files changed, 23 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Thu Oct 08 10:07:41 2009 +0200
+++ b/hgext/rebase.py	Thu Oct 08 10:39:43 2009 +0200
@@ -401,6 +401,10 @@
             return None
 
         cwdancestors = set(repo.changelog.ancestors(cwd))
+        if dest in cwdancestors:
+            repo.ui.debug('source is descendant of destination\n')
+            return None
+
         cwdancestors.add(cwd)
         rebasingbranch = cwdancestors - targetancestors
         source = min(rebasingbranch)
--- a/tests/test-rebase-scenario-global	Thu Oct 08 10:07:41 2009 +0200
+++ b/tests/test-rebase-scenario-global	Thu Oct 08 10:39:43 2009 +0200
@@ -70,7 +70,7 @@
 hg rebase -s 3 -d 1 2>&1 | sed 's/\(saving bundle to \).*/\1/'
 hg glog  --template '{rev}: {desc}\n'
 
-echo '% These will fail'
+echo '% These will fail (using --source)'
 createrepo > /dev/null 2>&1
 echo '% E onto D - rebase onto an ancestor'
 hg rebase -s 4 -d 3
@@ -79,4 +79,13 @@
 echo '% E onto B - merge revision with both parents not in ancestors of target'
 hg rebase -s 4 -d 1
 
+echo
+echo '% These will abort gracefully (using --base)'
+echo '% E onto E - rebase onto same changeset'
+hg rebase -b 4 -d 4
+echo '% E onto D - rebase onto an ancestor'
+hg rebase -b 4 -d 3
+echo '% D onto E - rebase onto a descendant'
+hg rebase -b 3 -d 4
+
 exit 0
--- a/tests/test-rebase-scenario-global.out	Thu Oct 08 10:07:41 2009 +0200
+++ b/tests/test-rebase-scenario-global.out	Thu Oct 08 10:39:43 2009 +0200
@@ -127,10 +127,18 @@
 |/
 o  0: A
 
-% These will fail
+% These will fail (using --source)
 % E onto D - rebase onto an ancestor
 abort: source is descendant of destination
 % D onto E - rebase onto a descendant
 abort: source is ancestor of destination
 % E onto B - merge revision with both parents not in ancestors of target
 abort: cannot use revision 4 as base, result would have 3 parents
+
+% These will abort gracefully (using --base)
+% E onto E - rebase onto same changeset
+nothing to rebase
+% E onto D - rebase onto an ancestor
+nothing to rebase
+% D onto E - rebase onto a descendant
+nothing to rebase