[PATCH 1 of 2] bookmarks: on a bare update use config to choose target or choose @

Stephen Lee sphen.lee at gmail.com
Tue Mar 11 06:20:10 CDT 2014


# HG changeset patch
# User Stephen Lee <sphen.lee at gmail.com>
# Date 1394536636 -39600
#      Tue Mar 11 22:17:16 2014 +1100
# Node ID ff0ffb9855d8e88fbcce967867f2a373eaac581f
# Parent  7d7c963bc88e63e6dff3971ba389b983a0cc29fa
bookmarks: on a bare update use config to choose target or choose @

When running "hg up" with an active and current bookmark, first check
if a key "bookmarks.<name>.track" is set - if so it names the bookmark
we want to update to. Otherwise if there is an @ bookmark, use it.

In both cases the active bookmark is moved to the target and remains
active. This is the same as how bare "hg up" has worked in the past,
except there was no way to choose a target other than the branch tip.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -170,6 +170,24 @@
                 deleted = True
     return deleted
 
+def trackingbookmark(repo):
+    '''Return the bookmark that the current bookmark is tracking.
+    This is the bookmark we update to when doing a bare 'hg up', or
+    the head to merge with in 'hg merge'.
+    To make 'foo' track 'bar', set bookmarks.foo.track = bar
+    By default bookmarks will track @ if it exists'''
+    bm = repo.ui.config('bookmarks', repo._bookmarkcurrent + '.track')
+    if bm is None:
+        if '@' in repo._bookmarks:
+            return '@'
+        else:
+            return None #no tracking and no @, use old behaviour
+    elif bm in repo:
+        return bm
+
+    raise util.Abort(_('bookmark %s being tracked by %s does not exist') %
+        (bm, repo._bookmarkcurrent))
+
 def calculateupdate(ui, repo, checkout):
     '''Return a tuple (targetrev, movemarkfrom) indicating the rev to
     check out and where to move the active bookmark from, if needed.'''
@@ -178,6 +196,7 @@
         curmark = repo._bookmarkcurrent
         if iscurrent(repo):
             movemarkfrom = repo['.'].node()
+            checkout = trackingbookmark(repo)
         elif curmark:
             ui.status(_("updating to active bookmark %s\n") % curmark)
             checkout = curmark
diff --git a/tests/test-bookmarks-merge.t b/tests/test-bookmarks-merge.t
--- a/tests/test-bookmarks-merge.t
+++ b/tests/test-bookmarks-merge.t
@@ -146,3 +146,34 @@
   abort: heads are bookmarked - please merge with an explicit rev
   (run 'hg heads' to see all heads)
   [255]
+
+# test bookmark tracking behaviour for update
+
+  $ hg up -q c
+  $ hg --config bookmarks.c.track=e up
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updating bookmark c
+  $ hg bookmarks
+     b                         1:d2ae7f538514
+   * c                         7:ca784329f0ba
+     e                         7:ca784329f0ba
+     g                         8:04dd21731d95
+  $ hg id
+  ca784329f0ba c/e
+
+# test bookmarks implicity tracking @
+
+  $ hg up -q 3
+  $ hg book -f c
+  $ hg book -r5 @
+  $ hg up
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  updating bookmark c
+  $ hg bookmarks
+     @                         5:26bee9c5bcf3
+     b                         1:d2ae7f538514
+   * c                         5:26bee9c5bcf3
+     e                         7:ca784329f0ba
+     g                         8:04dd21731d95
+  $ hg id
+  26bee9c5bcf3 @/c


More information about the Mercurial-devel mailing list