diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py --- a/mercurial/bookmarks.py +++ b/mercurial/bookmarks.py @@ -170,6 +170,19 @@ def deletedivergent(repo, deletefrom, bm deleted = True return deleted +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.''' + movemarkfrom = None + if checkout is None: + curmark = repo._bookmarkcurrent + if iscurrent(repo): + movemarkfrom = repo['.'].node() + elif curmark: + ui.status(_("updating to active bookmark %s\n") % curmark) + checkout = curmark + return (checkout, movemarkfrom) + def update(repo, parents, node): deletefrom = parents marks = repo._bookmarks diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -4520,7 +4520,7 @@ def postincoming(ui, repo, modheads, opt if modheads == 0: return if optupdate: - movemarkfrom = repo['.'].node() + checkout, movemarkfrom = bookmarks.calculateupdate(ui, repo, checkout) try: ret = hg.update(repo, checkout) except util.Abort, inst: @@ -5829,14 +5829,7 @@ def update(ui, repo, node=None, rev=None cmdutil.clearunfinished(repo) # with no argument, we also move the current bookmark, if any - movemarkfrom = None - if rev is None: - curmark = repo._bookmarkcurrent - if bookmarks.iscurrent(repo): - movemarkfrom = repo['.'].node() - elif curmark: - ui.status(_("updating to active bookmark %s\n") % curmark) - rev = curmark + rev, movemarkfrom = bookmarks.calculateupdate(ui, repo, rev) # if we defined a bookmark, we have to remember the original bookmark name brev = rev diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t --- a/tests/test-bookmarks.t +++ b/tests/test-bookmarks.t @@ -507,19 +507,37 @@ update to current bookmark if it's not t * Z 3:125c9a1d6df6 x y 2:db815d6d32e6 +pull --update works the same as pull && update + + $ hg bookmark -r3 Y + moving bookmark 'Y' forward from db815d6d32e6 + $ hg -R cloned-bookmarks-update update Y + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg -R cloned-bookmarks-update pull --update . + pulling from . + searching for changes + adding changesets + adding manifests + adding file changes + added 2 changesets with 2 changes to 2 files (+1 heads) + updating bookmark Y + updating bookmark Z + updating to active bookmark Y + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + test wrongly formated bookmark $ echo '' >> .hg/bookmarks $ hg bookmarks X2 1:925d80f479bb - Y 2:db815d6d32e6 + Y 3:125c9a1d6df6 * Z 3:125c9a1d6df6 x y 2:db815d6d32e6 $ echo "Ican'thasformatedlines" >> .hg/bookmarks $ hg bookmarks malformed line in .hg/bookmarks: "Ican'thasformatedlines" X2 1:925d80f479bb - Y 2:db815d6d32e6 + Y 3:125c9a1d6df6 * Z 3:125c9a1d6df6 x y 2:db815d6d32e6