Patchwork [sprint] : bookmarks: add 'hg push -B .' as a shorthand for pushing the active bookmark issue(4917)

login
register
mail settings
Submitter Uri Baghin
Date Oct. 25, 2015, 5:01 p.m.
Message ID <A4DDF9A2-D911-42F3-AF5B-6CEFC7A288B6@fb.com>
Download mbox | patch
Permalink /patch/11245/
State Changes Requested
Headers show

Comments

Uri Baghin - Oct. 25, 2015, 5:01 p.m.
# HG changeset patch
# User Uri Baghin <coneko@fb.com>
# Date 1445788353 0
#      Sun Oct 25 15:52:33 2015 +0000
# Node ID 6782d5b9ef0f85904067535d441a1c3381ff3a1f
# Parent  58a309e9cf80d74d96e8c56cb95be20a4b130092
bookmarks: add 'hg push -B .' as a shorthand for pushing the active bookmark issue(4917)
Matt Mackall - Nov. 1, 2015, 7:21 p.m.
On Sun, 2015-10-25 at 17:01 +0000, Uri Baghin wrote:
> # HG changeset patch
> # User Uri Baghin <coneko@fb.com>
> # Date 1445788353 0
> #      Sun Oct 25 15:52:33 2015 +0000
> # Node ID 6782d5b9ef0f85904067535d441a1c3381ff3a1f
> # Parent  58a309e9cf80d74d96e8c56cb95be20a4b130092
> bookmarks: add 'hg push -B .' as a shorthand for pushing the active
> bookmark issue(4917)

The issue robot is picky. It needs to be "(issueXXXX)" precisely.

Since we're already planning to use this '.' trick in more than one
place for bookmarks, I think this logic should go into a utility
function in bookmarks.py. Otherwise, looks good.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py

--- a/mercurial/commands.py

+++ b/mercurial/commands.py

@@ -5370,7 +5370,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.
@@ -5380,6 +5381,20 @@ 

 
     if opts.get('bookmark'):
         ui.setconfig('bookmarks', 'pushing', opts['bookmark'], 'push')
+        activebookmark = repo._activebookmark

+        if '.' in opts['bookmark'] and activebookmark is None:

+            raise error.Abort(_('no bookmark is active'),

+                              hint=_('do not specify \'.\' in bookmarks'))

+

+        def expandactivebookmark(b):

+            if b == '.':

+                return activebookmark

+            else:

+                return b

+

+        opts.update([(

+            'bookmark',

+            [expandactivebookmark(x) for x in opts['bookmark']])])

         for b in opts['bookmark']:
             # translate -B options to -r so changesets get pushed
             if b in repo._bookmarks:
diff --git a/tests/test-bookmarks-pushpull.t b/tests/test-bookmarks-pushpull.t

--- a/tests/test-bookmarks-pushpull.t

+++ b/tests/test-bookmarks-pushpull.t

@@ -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