[PATCH] bookmarks: rename the active bookmark with no arguments
David Demelier
demelier.david at gmail.com
Wed Jul 19 10:49:04 UTC 2017
# HG changeset patch
# User David Demelier <demelier.david at gmail.com>
# Date 1500449739 -7200
# Wed Jul 19 09:35:39 2017 +0200
# Node ID eeeafb331795055c7cae78cae5724c51637555dc
# Parent 9a944e908ecf9ac3aabf30a24406513370eeebe7
bookmarks: rename the active bookmark with no arguments
For convenience, the active bookmark is renamed if less than 2 arguments are
given.
diff -r 9a944e908ecf -r eeeafb331795 mercurial/commands.py
--- a/mercurial/commands.py Tue Jul 18 23:04:08 2017 +0530
+++ b/mercurial/commands.py Wed Jul 19 09:35:39 2017 +0200
@@ -895,7 +895,7 @@
[('f', 'force', False, _('force')),
('r', 'rev', '', _('revision for bookmark action'), _('REV')),
('d', 'delete', False, _('delete a given bookmark')),
- ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
+ ('m', 'rename', '', _('rename the active or given bookmark'), _('NAME')),
('i', 'inactive', False, _('mark a bookmark inactive')),
] + formatteropts,
_('hg bookmarks [OPTIONS]... [NAME]...'))
@@ -920,6 +920,8 @@
A bookmark named '@' has the special property that :hg:`clone` will
check it out by default if it exists.
+ If only one argument is given to -m, the active bookmark is renamed.
+
.. container:: verbose
Examples:
@@ -940,6 +942,10 @@
hg book -m turkey dinner
+ - rename the active bookmark to dinner::
+
+ hg book -m dinner
+
- move the '@' bookmark from another branch::
hg book -f @
@@ -964,11 +970,18 @@
if delete:
bookmarks.delete(repo, tr, names)
elif rename:
- if not names:
- raise error.Abort(_("new bookmark name required"))
- elif len(names) > 1:
+ if len(names) == 0:
+ if not repo._activebookmark:
+ raise error.Abort(_("no active bookmark to rename"))
+ old = repo._activebookmark
+ new = rename
+ elif len(names) == 1:
+ old = rename
+ new = names[0]
+ else:
raise error.Abort(_("only one new bookmark name allowed"))
- bookmarks.rename(repo, tr, rename, names[0], force, inactive)
+
+ bookmarks.rename(repo, tr, old, new, force, inactive)
elif names:
bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
elif inactive:
diff -r 9a944e908ecf -r eeeafb331795 tests/test-bookmarks.t
--- a/tests/test-bookmarks.t Tue Jul 18 23:04:08 2017 +0530
+++ b/tests/test-bookmarks.t Wed Jul 19 09:35:39 2017 +0200
@@ -187,6 +187,27 @@
abort: bookmark 'Y' already exists (use -f to force)
[255]
+rename the active bookmark
+
+ $ hg bookmark A
+ $ hg bookmark -m B
+ $ hg bookmarks
+ * B 2:db815d6d32e6
+ X 2:db815d6d32e6
+ X2 1:925d80f479bb
+ Y -1:000000000000
+ Z 0:f7b1eb17ad24
+ $ hg book -d B
+ $ hg up -q Y
+
+rename no active bookmark
+
+ $ hg up -q tip
+ $ hg book -m test
+ abort: no active bookmark to rename
+ [255]
+ $ hg up -q Y
+
force rename to existent bookmark
$ hg bookmark -f -m X Y
@@ -203,7 +224,7 @@
$ hg bookmark -r ':tip' TIP
$ hg up -q TIP
$ hg bookmarks
- REVSET 0:f7b1eb17ad24
+ REVSET -1:000000000000
* TIP 2:db815d6d32e6
X2 1:925d80f479bb
Y 2:db815d6d32e6
@@ -212,11 +233,8 @@
$ hg bookmark -d REVSET
$ hg bookmark -d TIP
-rename without new name or multiple names
+rename with multiple names
- $ hg bookmark -m Y
- abort: new bookmark name required
- [255]
$ hg bookmark -m Y Y2 Y3
abort: only one new bookmark name allowed
[255]
More information about the Mercurial-devel
mailing list