[PATCH] bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)

liscju piotr.listkiewicz at gmail.com
Fri Feb 19 21:48:52 UTC 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1455917289 -3600
#      Fri Feb 19 22:28:09 2016 +0100
# Node ID 7f68decb8bceff4c6da47cb02cf8ca56c538cee5
# Parent  a036e1ae1fbe88ab99cb861ebfc2e4da7a3912ca
bookmarks: add 'hg push -B .' for pushing the active bookmark (issue4917)

diff -r a036e1ae1fbe -r 7f68decb8bce mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Sun Feb 07 00:49:31 2016 -0600
+++ b/mercurial/bookmarks.py	Fri Feb 19 22:28:09 2016 +0100
@@ -182,6 +182,12 @@
             fp.write("%s %s\n" % (hex(node), encoding.fromlocal(name)))
         self._clean = True
 
+    def expandname(self, bname):
+        if bname == '.':
+            return self.active
+        else:
+            return bname
+
 def _readactive(repo, marks):
     """
     Get the active bookmark. We can have an active bookmark that updates
diff -r a036e1ae1fbe -r 7f68decb8bce mercurial/commands.py
--- a/mercurial/commands.py	Sun Feb 07 00:49:31 2016 -0600
+++ b/mercurial/commands.py	Fri Feb 19 22:28:09 2016 +0100
@@ -5698,7 +5698,8 @@
 
     If -B/--bookmark is used, the specified bookmarked revision, its
     ancestors, and the bookmark will be pushed to the remote
-    repository.
+    repository. Specifying ``.`` is equivalent to specifying the active
+    bookmark's name.
 
     Please see :hg:`help urls` for important details about ``ssh://``
     URLs. If DESTINATION is omitted, a default path will be used.
@@ -5710,6 +5711,7 @@
         ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push')
         for b in opts['bookmark']:
             # translate -B options to -r so changesets get pushed
+            b = repo._bookmarks.expandname(b)
             if b in repo._bookmarks:
                 opts.setdefault('rev', []).append(b)
             else:
diff -r a036e1ae1fbe -r 7f68decb8bce mercurial/exchange.py
--- a/mercurial/exchange.py	Sun Feb 07 00:49:31 2016 -0600
+++ b/mercurial/exchange.py	Fri Feb 19 22:28:09 2016 +0100
@@ -576,7 +576,8 @@
         ancestors = repo.changelog.ancestors(revnums, inclusive=True)
     remotebookmark = remote.listkeys('bookmarks')
 
-    explicit = set(pushop.bookmarks)
+    explicit = set([repo._bookmarks.expandname(bookmark)
+                    for bookmark in pushop.bookmarks])
 
     comp = bookmod.compare(repo, repo._bookmarks, remotebookmark, srchex=hex)
     addsrc, adddst, advsrc, advdst, diverge, differ, invalid, same = comp
diff -r a036e1ae1fbe -r 7f68decb8bce tests/test-bookmarks-pushpull.t
--- a/tests/test-bookmarks-pushpull.t	Sun Feb 07 00:49:31 2016 -0600
+++ b/tests/test-bookmarks-pushpull.t	Fri Feb 19 22:28:09 2016 +0100
@@ -103,6 +103,29 @@
   deleting remote bookmark W
   [1]
 
+export the active bookmark
+
+  $ hg bookmark V
+  $ hg push -B . ../a
+  pushing to ../a
+  searching for changes
+  no changes found
+  exporting bookmark V
+  [1]
+
+delete the bookmark
+
+  $ hg book -d V
+  $ hg push -B V ../a
+  pushing to ../a
+  searching for changes
+  no changes found
+  deleting remote bookmark V
+  [1]
+  $ hg up foobar
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  (activating bookmark foobar)
+
 push/pull name that doesn't exist
 
   $ hg push -B badname ../a


More information about the Mercurial-devel mailing list