[PATCH 5 of 6] update: add switch to move active bookmark forward

Kevin Bullock kbullock+mercurial at ringworld.org
Wed Dec 7 11:40:57 CST 2011


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1321481586 21600
# Node ID 6bab2e0693916ee9160f41dc9fe52b9d7304de54
# Parent  1917c90be9b026cc5aeff849a07045f38e221be7
update: add switch to move active bookmark forward

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5586,9 +5586,11 @@
     ('c', 'check', None,
      _('update across branches if no uncommitted changes')),
     ('d', 'date', '', _('tipmost revision matching date'), _('DATE')),
-    ('r', 'rev', '', _('revision'), _('REV'))],
+    ('r', 'rev', '', _('revision'), _('REV')),
+    ('B', 'bookmark', None, _('move the active bookmark forward'))],
     _('[-c] [-C] [-d DATE] [[-r] REV]'))
-def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
+def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False,
+           bookmark=False):
     """update working directory (or switch revisions)
 
     Update the repository's working directory to the specified
@@ -5604,6 +5606,9 @@
     Update sets the working directory's parent revison to the specified
     changeset (see :hg:`help parents`).
 
+    With -B/--bookmark, the active bookmark will be moved forward along
+    with the update.
+
     The following rules apply when the working directory contains
     uncommitted changes:
 
@@ -5656,6 +5661,14 @@
             raise util.Abort(_("you can't specify a revision and a date"))
         rev = cmdutil.finddate(ui, repo, date)
 
+    old = repo['.']
+    if bookmark:
+        if repo._bookmarks[repo._bookmarkcurrent] != old.node():
+            raise util.Abort(_("no active bookmark"))
+        if not bookmarks.updatecurrentbookmark(repo, old.node(),
+                                               repo['.'].branch()):
+            raise util.Abort(_("cannot move active bookmark to a non-descendant"))
+
     if clean or check:
         ret = hg.clean(repo, rev)
     else:
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -204,7 +204,7 @@
   serve: accesslog, daemon, daemon-pipefds, errorlog, port, address, prefix, name, web-conf, webdir-conf, pid-file, stdio, cmdserver, templates, style, ipv6, certificate
   status: all, modified, added, removed, deleted, clean, unknown, ignored, no-status, copies, print0, rev, change, include, exclude, subrepos
   summary: remote
-  update: clean, check, date, rev
+  update: clean, check, date, rev, bookmark
   addremove: similarity, include, exclude, dry-run
   archive: no-decode, prefix, rev, type, subrepos, include, exclude
   backout: merge, parent, rev, tool, include, exclude, message, logfile, date, user
diff --git a/tests/test-update-bookmark.t b/tests/test-update-bookmark.t
new file mode 100644
--- /dev/null
+++ b/tests/test-update-bookmark.t
@@ -0,0 +1,37 @@
+  $ hg init
+  $ echo a>a
+  $ hg ci -Aqm0
+  $ hg bookmark --inactive b0
+  $ echo b>a
+  $ hg ci -m1
+
+active bookmark moved forward to descendant
+
+  $ hg update -q b0
+  $ hg update -qB
+  $ hg bookmarks
+   * b0                        1:7abd236267be
+
+refuses to move active bookmark backwards
+
+  $ hg update -B 0
+  abort: cannot move active bookmark to a non-descendant
+  [255]
+
+refuses to move bookmark across branches
+
+  $ hg update -q 0
+  $ echo c>a
+  $ hg ci -qm2
+  $ hg update -q b0
+  $ hg update -cB
+  abort: cannot move active bookmark to a non-descendant
+  [255]
+
+works with --check if --check isn't actually necessary
+
+  $ hg update -q 0
+  $ hg bookmark -f b0
+  $ hg update -qcB
+  $ hg bookmarks
+   * b0                        2:f25fcbd609fb


More information about the Mercurial-devel mailing list