changeset 18471:2096e025a728 stable

update: update to current bookmark if it moved out from under us (issue3682) If the current bookmark (the one listed in .hg/bookmarks.current) doesn't point to a parent of the working directory, e.g. if it was moved by a pull, use that as the update target instead of the tipmost descendent. A small predicate is (finally) added to the bookmarks module to check whether the current bookmark is also active.
author Kevin Bullock <kbullock@ringworld.org>
date Mon, 21 Jan 2013 13:47:10 -0600
parents 28b3d669295e
children 37100f30590f
files mercurial/bookmarks.py mercurial/commands.py tests/test-bookmarks.t
diffstat 3 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bookmarks.py	Mon Jan 21 12:58:59 2013 -0600
+++ b/mercurial/bookmarks.py	Mon Jan 21 13:47:10 2013 -0600
@@ -134,6 +134,19 @@
     finally:
         wlock.release()
 
+def iscurrent(repo, mark=None, parents=None):
+    '''Tell whether the current bookmark is also active
+
+    I.e., the bookmark listed in .hg/bookmarks.current also points to a
+    parent of the working directory.
+    '''
+    if not mark:
+        mark = repo._bookmarkcurrent
+    if not parents:
+        parents = [p.node() for p in repo[None].parents()]
+    marks = repo._bookmarks
+    return (mark in marks and marks[mark] in parents)
+
 def updatecurrentbookmark(repo, oldnode, curbranch):
     try:
         return update(repo, oldnode, repo.branchtip(curbranch))
--- a/mercurial/commands.py	Mon Jan 21 12:58:59 2013 -0600
+++ b/mercurial/commands.py	Mon Jan 21 13:47:10 2013 -0600
@@ -5961,7 +5961,12 @@
     # with no argument, we also move the current bookmark, if any
     movemarkfrom = None
     if rev is None:
-        movemarkfrom = repo['.'].node()
+        curmark = repo._bookmarkcurrent
+        if bookmarks.iscurrent(repo):
+            movemarkfrom = repo['.'].node()
+        elif curmark:
+            ui.status(_("updating to active bookmark %s\n") % curmark)
+            rev = curmark
 
     # if we defined a bookmark, we have to remember the original bookmark name
     brev = rev
--- a/tests/test-bookmarks.t	Mon Jan 21 12:58:59 2013 -0600
+++ b/tests/test-bookmarks.t	Mon Jan 21 13:47:10 2013 -0600
@@ -458,7 +458,11 @@
   adding file changes
   added 2 changesets with 2 changes to 2 files (+1 heads)
   (run 'hg heads' to see heads, 'hg merge' to merge)
+
+update to current bookmark if it's not the parent
+
   $ hg update
+  updating to active bookmark Z
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg bookmarks
      X2                        1:925d80f479bb