topics: make sure we have some restrictions on topic names
This patch makes sure we don't allow topic names with just whitespaces, and
other checks which we do for a bookmark.
--- a/hgext3rd/topic/__init__.py Tue Aug 29 19:03:59 2017 +0530
+++ b/hgext3rd/topic/__init__.py Tue Aug 29 19:12:00 2017 +0530
@@ -73,6 +73,7 @@
patch,
phases,
registrar,
+ scmutil,
templatefilters,
util,
)
@@ -315,7 +316,7 @@
('', 'current', None, 'display the current topic only'),
] + commands.formatteropts,
_('hg topics [TOPIC]'))
-def topics(ui, repo, topic='', clear=False, rev=None, list=False, **opts):
+def topics(ui, repo, topic=None, clear=False, rev=None, list=False, **opts):
"""View current topic, set current topic, change topic for a set of revisions, or see all topics.
Clear topic on existing topiced revisions:
@@ -353,6 +354,13 @@
if clear and topic:
raise error.Abort(_("cannot use --clear when setting a topic"))
+ if topic:
+ topic = topic.strip()
+ if not topic:
+ raise error.Abort(_("topic name cannot consist entirely of whitespaces"))
+ # Have some restrictions on the topic name just like bookmark name
+ scmutil.checknewlabel(repo, topic, 'topic')
+
if list:
if clear or rev:
raise error.Abort(_("cannot use --clear or --rev with --list"))
--- a/tests/test-topic.t Tue Aug 29 19:03:59 2017 +0530
+++ b/tests/test-topic.t Tue Aug 29 19:12:00 2017 +0530
@@ -93,10 +93,20 @@
Trying some invalid topicnames
$ hg topic '.'
+ abort: the name '.' is reserved
+ [255]
$ hg topic null
+ abort: the name 'null' is reserved
+ [255]
$ hg topic tip
+ abort: the name 'tip' is reserved
+ [255]
$ hg topic 12345
+ abort: cannot use an integer as a name
+ [255]
$ hg topic ' '
+ abort: topic name cannot consist entirely of whitespaces
+ [255]
Test commit flag and help text