Patchwork [3,of,3,V2] rebase: prevent creating divergence

login
register
mail settings
Submitter Laurent Charignon
Date Jan. 6, 2016, 9:01 p.m.
Message ID <96aec452fb6814bca054.1452114119@lcharignon-mbp.local>
Download mbox | patch
Permalink /patch/12582/
State Superseded
Commit f0e9f38d250fb40ab835cb8c8c2acca8aed545bc
Delegated to: Martin von Zweigbergk
Headers show

Comments

Laurent Charignon - Jan. 6, 2016, 9:01 p.m.
# HG changeset patch
# User Laurent Charignon <lcharignon@fb.com>
# Date 1452113756 28800
#      Wed Jan 06 12:55:56 2016 -0800
# Node ID 96aec452fb6814bca0540c26ba2e21a552004ac6
# Parent  09b8308e5e443d73e81bb488bf13789b7ef11149
rebase: prevent creating divergence

Before this patch rebase would create divergence when you were rebasing obsolete
changesets on a destination not containing one of its successors.
This patch introduces experimental.rebaseallowdivergence to explicitly allow
divergence creation with rebase.

Patch

diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -350,6 +350,17 @@  def rebase(ui, repo, **opts):
                                                                 dest)
                 rebaseobsskipped = set(obsoletenotrebased)
 
+                # Obsolete node with successors not in dest leads to divergence
+                divergenceok = ui.configbool('experimental',
+                                             'rebaseallowdivergence')
+                divergencebasecandidates = rebaseobsrevs - rebaseobsskipped
+
+                if divergencebasecandidates and not divergenceok:
+                    msg = _("this rebase will cause divergence")
+                    h = _("to force the rebase please set "
+                          "experimental.rebaseallowdivergence=True")
+                    raise error.Abort(msg, hint=h)
+
                 # - plain prune (no successor) changesets are rebased
                 # - split changesets are not rebased if at least one of the
                 # changeset resulting from the split is an ancestor of dest
diff --git a/tests/test-rebase-obsolete.t b/tests/test-rebase-obsolete.t
--- a/tests/test-rebase-obsolete.t
+++ b/tests/test-rebase-obsolete.t
@@ -712,3 +712,96 @@  should display a friendly error message
   abort: all requested changesets have equivalents or were marked as obsolete
   (to force the rebase, set the config experimental.rebaseskipobsolete to False)
   [255]
+
+If a rebase is going to create divergence, it should abort
+
+  $ hg log -G
+  @  11:f44da1f4954c nonrelevant
+  |
+  | o  10:121d9e3bc4c6 P
+  |/
+  o  9:4be60e099a77 C
+  |
+  o  6:9c48361117de D
+  |
+  o  2:261e70097290 B2
+  |
+  o  0:4a2df7238c3b A
+  
+
+  $ hg up 9
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo "john" > doe
+  $ hg add doe
+  $ hg commit -m "john doe"
+  created new head
+  $ hg up 10
+  1 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo "foo" > bar
+  $ hg add bar
+  $ hg commit --amend -m "10'"
+  $ hg up 10 --hidden
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo "bar" > foo
+  $ hg add foo
+  $ hg commit -m "bar foo"
+  $ hg log -G
+  @  15:73568ab6879d bar foo
+  |
+  | o  14:77d874d096a2 10'
+  | |
+  | | o  12:3eb461388009 john doe
+  | |/
+  x |  10:121d9e3bc4c6 P
+  |/
+  o  9:4be60e099a77 C
+  |
+  o  6:9c48361117de D
+  |
+  o  2:261e70097290 B2
+  |
+  o  0:4a2df7238c3b A
+  
+  $ hg summary
+  parent: 15:73568ab6879d tip
+   bar foo
+  branch: default
+  commit: (clean)
+  update: 2 new changesets, 3 branch heads (merge)
+  phases: 8 draft
+  unstable: 1 changeset
+  $ hg rebase -s 10 -d 12
+  abort: this rebase will cause divergence
+  (to force the rebase please set experimental.rebaseallowdivergence=True)
+  [255]
+  $ hg log -G
+  @  15:73568ab6879d bar foo
+  |
+  | o  14:77d874d096a2 10'
+  | |
+  | | o  12:3eb461388009 john doe
+  | |/
+  x |  10:121d9e3bc4c6 P
+  |/
+  o  9:4be60e099a77 C
+  |
+  o  6:9c48361117de D
+  |
+  o  2:261e70097290 B2
+  |
+  o  0:4a2df7238c3b A
+  
+With experimental.rebaseallowdivergence=True, rebase can create divergence
+
+  $ hg rebase -s 10 -d 12 --config experimental.rebaseallowdivergence=True
+  rebasing 10:121d9e3bc4c6 "P"
+  rebasing 15:73568ab6879d "bar foo" (tip)
+  $ hg summary
+  parent: 17:61bd55f69bc4 tip
+   bar foo
+  branch: default
+  commit: (clean)
+  update: 1 new changesets, 2 branch heads (merge)
+  phases: 8 draft
+  divergent: 2 changeset
+