rebase: allow rebase to ancestor (issue3010)
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Mon, 19 Sep 2011 16:57:13 +0200
changeset 15132 81f76098211e
parent 15131 7c26ce9edbd2
child 15133 b1c62c754bf8
rebase: allow rebase to ancestor (issue3010) We only deny rebasing onto direct parent. Thanks to the ancestor argument of merge. the "implementation" of this feature only consist in loosing the check and imply detach when rebasing on ancestor.
hgext/rebase.py
tests/test-rebase-detach.t
tests/test-rebase-parameters.t
tests/test-rebase-scenario-global.t
--- a/hgext/rebase.py	Sun Sep 18 19:59:33 2011 -0400
+++ b/hgext/rebase.py	Mon Sep 19 16:57:13 2011 +0200
@@ -536,11 +536,14 @@
 
     if src:
         commonbase = repo[src].ancestor(repo[dest])
-        samebranch = repo[src].branch() == repo[dest].branch()
         if commonbase == repo[src]:
             raise util.Abort(_('source is ancestor of destination'))
-        if samebranch and commonbase == repo[dest]:
-            raise util.Abort(_('source is descendant of destination'))
+        if commonbase == repo[dest]:
+            samebranch = repo[src].branch() == repo[dest].branch()
+            if samebranch and repo[src] in repo[dest].children():
+                raise util.Abort(_('source is a child of destination'))
+            # rebase on ancestor, force detach
+            detach = True
         source = repo[src].rev()
         if detach:
             # We need to keep track of source's ancestors up to the common base
--- a/tests/test-rebase-detach.t	Sun Sep 18 19:59:33 2011 -0400
+++ b/tests/test-rebase-detach.t	Mon Sep 19 16:57:13 2011 +0200
@@ -281,3 +281,25 @@
   |/
   o  0: 'A'
   
+
+  $ hg rebase -d 5 -s 7
+  saved backup bundle to $TESTTMP/a5/.hg/strip-backup/13547172c9c0-backup.hg
+  $ hg tglog
+  @  8: 'D'
+  |
+  o  7: 'C'
+  |
+  | o  6: 'B'
+  |/
+  o  5: 'extra branch'
+  
+  o  4: 'H'
+  |
+  | o  3: 'G'
+  |/|
+  o |  2: 'F'
+  | |
+  | o  1: 'E'
+  |/
+  o  0: 'A'
+  
--- a/tests/test-rebase-parameters.t	Sun Sep 18 19:59:33 2011 -0400
+++ b/tests/test-rebase-parameters.t	Mon Sep 19 16:57:13 2011 +0200
@@ -51,7 +51,7 @@
   $ cd a1
 
   $ hg rebase -s 8 -d 7
-  abort: source is descendant of destination
+  abort: source is a child of destination
   [255]
 
   $ hg rebase --continue --abort
--- a/tests/test-rebase-scenario-global.t	Sun Sep 18 19:59:33 2011 -0400
+++ b/tests/test-rebase-scenario-global.t	Mon Sep 19 16:57:13 2011 +0200
@@ -212,7 +212,7 @@
   $ cd a7
 
   $ hg rebase -s 6 -d 5
-  abort: source is descendant of destination
+  abort: source is a child of destination
   [255]
 
 F onto G - rebase onto a descendant:
@@ -248,3 +248,25 @@
   nothing to rebase
   [1]
 
+C onto A - rebase onto an ancestor:
+
+  $ hg rebase -d 0 -s 2
+  saved backup bundle to $TESTTMP/a7/.hg/strip-backup/5fddd98957c8-backup.hg
+  $ hg tglog
+  @  7: 'D'
+  |
+  o  6: 'C'
+  |
+  | o  5: 'H'
+  | |
+  | | o  4: 'G'
+  | |/|
+  | o |  3: 'F'
+  |/ /
+  | o  2: 'E'
+  |/
+  | o  1: 'B'
+  |/
+  o  0: 'A'
+  
+