changeset 28118:0e3835c7e1cf

rebase: perform update through the 'update' command The update logic have grow more and more complicated over time (eg bookmark movement, new destination logic, warning on other head, etc). The rebase extension was reimplementing its own basic version of update to be used by 'hg pull --rebase'. We remove the custom code and use a combination of higher level functions. A test is added to check that the update is properly warning about other branch heads.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sun, 14 Feb 2016 00:45:17 +0000
parents 41a0fb2b4bbc
children 91a827e760df
files hgext/rebase.py tests/test-rebase-pull.t
diffstat 2 files changed, 49 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/rebase.py	Sat Feb 13 16:59:32 2016 +0000
+++ b/hgext/rebase.py	Sun Feb 14 00:45:17 2016 +0000
@@ -16,7 +16,7 @@
 
 from mercurial import hg, util, repair, merge, cmdutil, commands, bookmarks
 from mercurial import extensions, patch, scmutil, phases, obsolete, error
-from mercurial import copies, repoview, revset
+from mercurial import copies, destutil, repoview, revset
 from mercurial.commands import templateopts
 from mercurial.node import nullrev, nullid, hex, short
 from mercurial.lock import release
@@ -1145,7 +1145,6 @@
                 ui.debug('--update and --rebase are not compatible, ignoring '
                          'the update flag\n')
 
-            movemarkfrom = repo['.'].node()
             revsprepull = len(repo)
             origpostincoming = commands.postincoming
             def _dummy(*args, **kwargs):
@@ -1166,15 +1165,11 @@
                 if 'source' in opts:
                     del opts['source']
                 if rebase(ui, repo, **opts) == _nothingtorebase():
-                    branch = repo[None].branch()
-                    dest = repo[branch].rev()
-                    if dest != repo['.'].rev():
-                        # there was nothing to rebase we force an update
-                        hg.update(repo, dest)
-                        if bookmarks.update(repo, [movemarkfrom],
-                                            repo['.'].node()):
-                            ui.status(_("updating bookmark %s\n")
-                                      % repo._activebookmark)
+                    rev, _a, _b = destutil.destupdate(repo)
+                    if rev != repo['.'].rev(): # we could update
+                        # not passing argument to get the bare update behavior
+                        # with warning and trumpets
+                        commands.update(ui, repo)
         finally:
             release(lock, wlock)
     else:
--- a/tests/test-rebase-pull.t	Sat Feb 13 16:59:32 2016 +0000
+++ b/tests/test-rebase-pull.t	Sun Feb 14 00:45:17 2016 +0000
@@ -266,3 +266,46 @@
   |
   o  0: 'C1'
   
+
+pull --rebase update (no rebase) use proper update:
+
+- warn about other head.
+
+  $ cd ../a
+  $ echo R6 > R6
+  $ hg ci -Am R6
+  adding R6
+  $ cd ../c
+  $ hg up 'desc(R5)'
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg pull --rebase
+  pulling from $TESTTMP/a (glob)
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  nothing to rebase - working directory parent is already an ancestor of destination 65bc164c1d9b
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  1 other heads for branch "default"
+  $ hg tglog
+  @  9: 'R6'
+  |
+  | o  8: 'L2'
+  | |
+  | o  7: 'L1'
+  |/
+  o  6: 'R5'
+  |
+  o  5: 'R4'
+  |
+  o  4: 'R3'
+  |
+  o  3: 'R2'
+  |
+  o  2: 'R1'
+  |
+  o  1: 'C2'
+  |
+  o  0: 'C1'
+