[PATCH 2 of 3] update to bookmark master or branch/master

arne_bab at web.de arne_bab at web.de
Thu Nov 3 07:11:23 CDT 2011


# HG changeset patch
# User Arne Babenhauserheide <bab at draketo.de>
# Date 1320315791 -3600
# Node ID 7c6ed23884fcb4f09d8133216cdc56ec150124aa
# Parent  5b239c772bf0def200acfa24b5529dcf447af307
update to bookmark master or branch/master

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5039,7 +5039,9 @@ def update(ui, repo, node=None, rev=None
 
     Update the repository's working directory to the specified
     changeset. If no changeset is specified, update to the tip of the
-    current named branch.
+    current named branch. If a bookmark named branch/master (just
+    master for the default branch) exists on the branch, update to
+    that bookmark instead.
 
     If the changeset is not a descendant of the working directory's
     parent, the update is aborted. With the -c/--check option, the
@@ -5081,6 +5083,19 @@ def update(ui, repo, node=None, rev=None
     if rev is None or rev == '':
         rev = node
 
+    # if no revision was specified and there is a master bookmark,
+    # update to that bookmark instead of tip.
+    if rev is None:
+        branch = repo["."].branch()
+        branchmaster = branch+"/master"
+        if branch == "default":
+            if ("master" in repo._bookmarks and
+                repo["master"].branch() == "default"):
+                rev = repo["master"].hex()
+        elif (branchmaster in repo._bookmarks and
+              repo[branchmaster].branch() == branch):
+            rev = repo[branchmaster].hex()
+
     # if we defined a bookmark, we have to remember the original bookmark name
     brev = rev
     rev = scmutil.revsingle(repo, rev, rev).rev()
@@ -5104,6 +5119,7 @@ def update(ui, repo, node=None, rev=None
     else:
         ret = hg.update(repo, rev)
 
+    # move the bookmark with the update
     if brev in repo._bookmarks:
         bookmarks.setcurrent(repo, brev)
 


More information about the Mercurial-devel mailing list