Patchwork bookmarks: allow renaming active bookmark using '.'

login
register
mail settings
Submitter David Demelier
Date Aug. 21, 2017, 7:06 a.m.
Message ID <f6ee280ea6afef475c3d.1503299210@markand.fr>
Download mbox | patch
Permalink /patch/23167/
State Superseded
Headers show

Comments

David Demelier - Aug. 21, 2017, 7:06 a.m.
# HG changeset patch
# User David Demelier <markand@malikania.fr>
# Date 1503298366 -7200
#      Mon Aug 21 08:52:46 2017 +0200
# Node ID f6ee280ea6afef475c3d158c4c4964a05be6ef15
# Parent  1e71a27dee970ec9ef02c004f662b5a99182f69b
bookmarks: allow renaming active bookmark using '.'
Yuya Nishihara - Aug. 23, 2017, 1:59 p.m.
On Mon, 21 Aug 2017 09:06:50 +0200, David Demelier wrote:
> # HG changeset patch
> # User David Demelier <markand@malikania.fr>
> # Date 1503298366 -7200
> #      Mon Aug 21 08:52:46 2017 +0200
> # Node ID f6ee280ea6afef475c3d158c4c4964a05be6ef15
> # Parent  1e71a27dee970ec9ef02c004f662b5a99182f69b
> bookmarks: allow renaming active bookmark using '.'

I like the idea.

> --- a/mercurial/bookmarks.py	Sun Aug 13 00:17:13 2017 -0700
> +++ b/mercurial/bookmarks.py	Mon Aug 21 08:52:46 2017 +0200
> @@ -763,7 +763,11 @@
>      """
>      marks = repo._bookmarks
>      mark = checkformat(repo, new)
> -    if old not in marks:
> +    if old == ".":
> +        if not repo._activebookmark:
> +            raise error.Abort(_("no active bookmark to rename"))
> +        old = repo._activebookmark
> +    elif old not in marks:

Perhaps bookmarks.expandname() could be used, and I slightly prefer resolving
"." in commands.py since that seems more like a UI stuff.

Patch

diff -r 1e71a27dee97 -r f6ee280ea6af mercurial/bookmarks.py
--- a/mercurial/bookmarks.py	Sun Aug 13 00:17:13 2017 -0700
+++ b/mercurial/bookmarks.py	Mon Aug 21 08:52:46 2017 +0200
@@ -763,7 +763,11 @@ 
     """
     marks = repo._bookmarks
     mark = checkformat(repo, new)
-    if old not in marks:
+    if old == ".":
+        if not repo._activebookmark:
+            raise error.Abort(_("no active bookmark to rename"))
+        old = repo._activebookmark
+    elif old not in marks:
         raise error.Abort(_("bookmark '%s' does not exist") % old)
     changes = []
     for bm in marks.checkconflict(mark, force):
diff -r 1e71a27dee97 -r f6ee280ea6af tests/test-bookmarks.t
--- a/tests/test-bookmarks.t	Sun Aug 13 00:17:13 2017 -0700
+++ b/tests/test-bookmarks.t	Mon Aug 21 08:52:46 2017 +0200
@@ -191,6 +191,28 @@ 
 
   $ hg bookmark -f -m X Y
 
+rename bookmark using .
+
+  $ hg book rename-me
+  $ hg book -m . renamed
+  $ hg bookmark
+     X2                        1:925d80f479bb
+     Y                         2:db815d6d32e6
+     Z                         0:f7b1eb17ad24
+   * renamed                   2:db815d6d32e6
+  $ hg up -q Y
+  $ hg book -d renamed
+
+rename bookmark using . with no active bookmark
+
+  $ hg book rename-me
+  $ hg book -i rename-me
+  $ hg book -m . renamed
+  abort: no active bookmark to rename
+  [255]
+  $ hg up -q Y
+  $ hg book -d rename-me
+
 list bookmarks
 
   $ hg bookmark