[PATCH 2 of 2] update: delete bookmarks.current when explicitly updating to a rev (issue3276)

Idan Kamara idankk86 at gmail.com
Mon Feb 27 17:18:56 CST 2012


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1330384458 -7200
# Node ID fc493929e66069fcaebad64036f81104d36c90df
# Parent  95a29d35f47932cef18bcc40cbc7c32bdcf034ba
update: delete bookmarks.current when explicitly updating to a rev (issue3276)

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -126,6 +126,13 @@
         wlock.release()
     repo._bookmarkcurrent = mark
 
+def unsetcurrent(repo):
+    try:
+        util.unlink(repo.join('bookmarks.current'))
+    except OSError, inst:
+        if inst.errno != errno.ENOENT:
+            raise
+
 def updatecurrentbookmark(repo, oldnode, curbranch):
     try:
         return update(repo, oldnode, repo.branchtags()[curbranch])
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5754,6 +5754,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
 
diff --git a/tests/test-bookmarks-current.t b/tests/test-bookmarks-current.t
--- a/tests/test-bookmarks-current.t
+++ b/tests/test-bookmarks-current.t
@@ -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
+
+  $ hg up -q X
+  $ hg up -q .
+  $ test -f .hg/bookmarks.current
+  [1]
diff --git a/tests/test-bookmarks-strip.t b/tests/test-bookmarks-strip.t
--- a/tests/test-bookmarks-strip.t
+++ b/tests/test-bookmarks-strip.t
@@ -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
 


More information about the Mercurial-devel mailing list