bundle: update current bookmark to most recent revision on current branch
authorDavid Soria Parra <dsp@php.net>
Mon, 14 Mar 2011 23:03:56 +0100
changeset 13663 d16c99f16f00
parent 13662 80d6e1f63ed9
child 13664 53db4e2026ab
child 13687 6528c1abc019
bundle: update current bookmark to most recent revision on current branch We check if the current bookmark is set to the first parent of the dirstate. Is this the case we move the bookmark to most recent revision on the current branch (where hg update will update you to).
mercurial/bookmarks.py
mercurial/commands.py
tests/test-bookmarks.t
--- a/mercurial/bookmarks.py	Mon Mar 14 20:53:55 2011 +0100
+++ b/mercurial/bookmarks.py	Mon Mar 14 23:03:56 2011 +0100
@@ -116,6 +116,15 @@
         wlock.release()
     repo._bookmarkcurrent = mark
 
+def updatecurrentbookmark(repo, oldnode, curbranch):
+    try:
+        update(repo, oldnode, repo.branchtags()[curbranch])
+    except KeyError:
+        if curbranch == "default": # no default branch!
+            update(repo, oldnode, repo.lookup("tip"))
+        else:
+            raise util.Abort(_("branch %s not found") % curbranch)
+
 def update(repo, parents, node):
     marks = repo._bookmarks
     update = False
--- a/mercurial/commands.py	Mon Mar 14 20:53:55 2011 +0100
+++ b/mercurial/commands.py	Mon Mar 14 23:03:56 2011 +0100
@@ -4038,15 +4038,16 @@
     fnames = (fname1,) + fnames
 
     lock = repo.lock()
+    wc = repo['.']
     try:
         for fname in fnames:
             f = url.open(ui, fname)
             gen = changegroup.readbundle(f, fname)
             modheads = repo.addchangegroup(gen, 'unbundle', 'bundle:' + fname,
                                            lock=lock)
+        bookmarks.updatecurrentbookmark(repo, wc.node(), wc.branch())
     finally:
         lock.release()
-
     return postincoming(ui, repo, modheads, opts.get('update'), None)
 
 def update(ui, repo, node=None, rev=None, clean=False, date=None, check=False):
--- a/tests/test-bookmarks.t	Mon Mar 14 20:53:55 2011 +0100
+++ b/tests/test-bookmarks.t	Mon Mar 14 23:03:56 2011 +0100
@@ -288,3 +288,36 @@
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg -R cloned-bookmarks-rev bookmarks
      X2                        1:925d80f479bb
+
+create bundle with two heads
+
+  $ hg clone . tobundle
+  updating to branch default
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ echo x > tobundle/x
+  $ hg -R tobundle add tobundle/x
+  $ hg -R tobundle commit -m'x'
+  $ hg -R tobundle update -r -2
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ echo y > tobundle/y
+  $ hg -R tobundle branch test
+  marked working directory as branch test
+  $ hg -R tobundle add tobundle/y
+  $ hg -R tobundle commit -m'y'
+  $ hg -R tobundle bundle tobundle.hg
+  searching for changes
+  2 changesets found
+  $ hg unbundle tobundle.hg
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files (+1 heads)
+  (run 'hg heads' to see heads, 'hg merge' to merge)
+  $ hg update
+  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg bookmarks
+     X2                        1:925d80f479bb
+     Y                         2:db815d6d32e6
+   * Z                         3:125c9a1d6df6
+     x  y                      2:db815d6d32e6
+