src/topic/destination.py
changeset 1892 b1fadc089b82
parent 1891 077c40f206d1
child 1900 27ea12c05e99
--- a/src/topic/destination.py	Sun Mar 13 13:07:54 2016 +0000
+++ b/src/topic/destination.py	Sun Mar 13 12:29:43 2016 +0000
@@ -2,6 +2,7 @@
 from mercurial import util
 from mercurial import destutil
 from mercurial import extensions
+from mercurial import bookmarks
 from mercurial.i18n import _
 
 def _destmergebranch(orig, repo, action='merge', sourceset=None, onheadcheck=True):
@@ -42,6 +43,18 @@
     else:
         return orig(repo)
 
+def _destupdatetopic(repo, clean, check):
+    """decide on an update destination from current topic"""
+    movemark = node = None
+    topic = repo.currenttopic
+    revs = repo.revs('.::topic("%s")' % topic)
+    if not revs:
+        return None, None, None
+    node = revs.last()
+    if bookmarks.isactivewdirparent(repo):
+        movemark = repo['.'].node()
+    return node, movemark, None
+
 def setupdest():
     if util.safehasattr(destutil, '_destmergebranch'):
         extensions.wrapfunction(destutil, '_destmergebranch', _destmergebranch)
@@ -50,6 +63,10 @@
             # logic not shared with merge yet < hg-3.8
             and not util.safehasattr(rebase, '_definesets')):
         extensions.wrapfunction(rebase, '_destrebase', _destmergebranch)
+    if util.safehasattr(destutil, 'destupdatesteps'):
+        bridx = destutil.destupdatesteps.index('branch')
+        destutil.destupdatesteps.insert(bridx, 'topic')
+        destutil.destupdatestepmap['topic'] = _destupdatetopic
 
 def ngtip(repo, branch, all=False):
     """tip new generation"""