Mercurial > hg-stable
changeset 19523:f37b5a17e6a0 stable 2.7
bookmarks: pull --update updates to active bookmark if it moved (issue4007)
This makes `hg pull --update` behave the same wrt the active bookmark as
`hg pull && hg update` does as of 2096e025a728. A helper function,
bookmarks.calculateupdate, is added to prevent code duplication between
postincoming and update.
author | Kevin Bullock <kbullock@ringworld.org> |
---|---|
date | Thu, 01 Aug 2013 21:43:14 -0500 |
parents | 3d19b8136641 |
children | f3381f365bd1 |
files | mercurial/bookmarks.py mercurial/commands.py tests/test-bookmarks.t |
diffstat | 3 files changed, 35 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/bookmarks.py Thu Aug 01 20:06:00 2013 -0500 +++ b/mercurial/bookmarks.py Thu Aug 01 21:43:14 2013 -0500 @@ -170,6 +170,19 @@ 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
--- a/mercurial/commands.py Thu Aug 01 20:06:00 2013 -0500 +++ b/mercurial/commands.py Thu Aug 01 21:43:14 2013 -0500 @@ -4520,7 +4520,7 @@ 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 @@ 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
--- a/tests/test-bookmarks.t Thu Aug 01 20:06:00 2013 -0500 +++ b/tests/test-bookmarks.t Thu Aug 01 21:43:14 2013 -0500 @@ -507,19 +507,37 @@ * 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