update: delete bookmarks.current when explicitly updating to a rev (issue3276) stable
authorIdan Kamara <idankk86@gmail.com>
Tue, 28 Feb 2012 23:47:46 +0200
branchstable
changeset 16191 7c75924a6926
parent 16190 9479c28a22bf
child 16192 a4413624d014
child 16193 b468cea3f29d
child 16213 369a5e5441bb
update: delete bookmarks.current when explicitly updating to a rev (issue3276)
mercurial/bookmarks.py
mercurial/commands.py
tests/test-bookmarks-current.t
tests/test-bookmarks-strip.t
--- a/mercurial/bookmarks.py	Tue Feb 28 10:06:35 2012 +0100
+++ b/mercurial/bookmarks.py	Tue Feb 28 23:47:46 2012 +0200
@@ -126,6 +126,17 @@
         wlock.release()
     repo._bookmarkcurrent = mark
 
+def unsetcurrent(repo):
+    wlock = repo.wlock()
+    try:
+        util.unlink(repo.join('bookmarks.current'))
+        repo._bookmarkcurrent = None
+    except OSError, inst:
+        if inst.errno != errno.ENOENT:
+            raise
+    finally:
+        wlock.release()
+
 def updatecurrentbookmark(repo, oldnode, curbranch):
     try:
         return update(repo, oldnode, repo.branchtags()[curbranch])
--- a/mercurial/commands.py	Tue Feb 28 10:06:35 2012 +0100
+++ b/mercurial/commands.py	Tue Feb 28 23:47:46 2012 +0200
@@ -5732,6 +5732,8 @@
             ui.status(_("updating bookmark %s\n") % repo._bookmarkcurrent)
     elif brev in repo._bookmarks:
         bookmarks.setcurrent(repo, brev)
+    elif brev:
+        bookmarks.unsetcurrent(repo)
 
     return ret
 
--- a/tests/test-bookmarks-current.t	Tue Feb 28 10:06:35 2012 +0100
+++ b/tests/test-bookmarks-current.t	Tue Feb 28 23:47:46 2012 +0200
@@ -125,3 +125,29 @@
   $ hg bookmarks
      X                         0:719295282060
      Z                         0:719295282060
+
+test deleting .hg/bookmarks.current when explicitly updating
+to a revision
+
+  $ echo a >> b
+  $ hg ci -m.
+  $ hg up -q X
+  $ test -f .hg/bookmarks.current
+
+try to update to it again to make sure we don't
+set and then unset it
+
+  $ hg up -q X
+  $ test -f .hg/bookmarks.current
+
+  $ hg up -q 1
+  $ test -f .hg/bookmarks.current
+  [1]
+
+when a bookmark is active, hg up -r . is
+analogus to hg book -i <active bookmark>
+
+  $ hg up -q X
+  $ hg up -q .
+  $ test -f .hg/bookmarks.current
+  [1]
--- a/tests/test-bookmarks-strip.t	Tue Feb 28 10:06:35 2012 +0100
+++ b/tests/test-bookmarks-strip.t	Tue Feb 28 23:47:46 2012 +0200
@@ -34,7 +34,7 @@
 
   $ hg book test2
 
-update to -2
+update to -2 (inactives the active bookmark)
 
   $ hg update -r -2
   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -61,7 +61,7 @@
 
   $ hg book
      test                      1:8cf31af87a2b
-   * test2                     1:8cf31af87a2b
+     test2                     1:8cf31af87a2b
 
 immediate rollback and reentrancy issue