bookmarks: automatically advance bookmark on naked update (BC) (issue2894)
authorMatt Mackall <mpm@selenic.com>
Thu, 19 Jan 2012 14:07:48 -0600
changeset 15935 6c97eb445341
parent 15934 9d4b5c3cb853
child 15936 878bc4a62a73
bookmarks: automatically advance bookmark on naked update (BC) (issue2894)
mercurial/commands.py
tests/test-bookmarks-pushpull.t
--- a/mercurial/commands.py	Thu Jan 19 11:35:06 2012 -0600
+++ b/mercurial/commands.py	Thu Jan 19 14:07:48 2012 -0600
@@ -5633,7 +5633,7 @@
 
     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 and move the current bookmark.
 
     If the changeset is not a descendant of the working directory's
     parent, the update is aborted. With the -c/--check option, the
@@ -5678,6 +5678,11 @@
     if rev is None or rev == '':
         rev = node
 
+    # with no argument, we also move the current bookmark, if any
+    movemarkfrom = None
+    if node is None or node == '':
+        movemarkfrom = repo['.'].node()
+
     # if we defined a bookmark, we have to remember the original bookmark name
     brev = rev
     rev = scmutil.revsingle(repo, rev, rev).rev()
@@ -5701,7 +5706,9 @@
     else:
         ret = hg.update(repo, rev)
 
-    if brev in repo._bookmarks:
+    if not ret and movemarkfrom:
+        bookmarks.update(repo, [movemarkfrom], repo['.'].node())
+    elif brev in repo._bookmarks:
         bookmarks.setcurrent(repo, brev)
 
     return ret
--- a/tests/test-bookmarks-pushpull.t	Thu Jan 19 11:35:06 2012 -0600
+++ b/tests/test-bookmarks-pushpull.t	Thu Jan 19 14:07:48 2012 -0600
@@ -109,7 +109,7 @@
    * X                         1:9b140be10808
      Y                         0:4e3505fd9583
      foo                       -1:000000000000
-     foobar                    -1:000000000000
+     foobar                    1:9b140be10808
 
   $ hg pull --config paths.foo=../a foo
   pulling from $TESTTMP/a
@@ -125,7 +125,7 @@
      X@foo                     2:0d2164f0ce0d
      Y                         0:4e3505fd9583
      foo                       -1:000000000000
-     foobar                    -1:000000000000
+     foobar                    1:9b140be10808
   $ hg push -f ../a
   pushing to ../a
   searching for changes
@@ -158,7 +158,7 @@
   Y	4e3505fd95835d721066b76e75dbb8cc554d7f77
   X	9b140be1080824d768c5a4691a564088eede71f9
   foo	0000000000000000000000000000000000000000
-  foobar	0000000000000000000000000000000000000000
+  foobar	9b140be1080824d768c5a4691a564088eede71f9
   $ hg out -B http://localhost:$HGPORT/
   comparing with http://localhost:$HGPORT/
   searching for changed bookmarks
@@ -174,7 +174,7 @@
   searching for changed bookmarks
      Z                         0d2164f0ce0d
      foo                       000000000000
-     foobar                    000000000000
+     foobar                    9b140be10808
   $ hg pull -B Z http://localhost:$HGPORT/
   pulling from http://localhost:$HGPORT/
   no changes found
@@ -193,6 +193,6 @@
      Y                         0:4e3505fd9583
      Z                         2:0d2164f0ce0d
      foo                       -1:000000000000
-     foobar                    -1:000000000000
+     foobar                    1:9b140be10808
 
   $ kill `cat ../hg.pid`