# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1504014120 -19800 # Node ID 31cbace4c0f12c2353aa459a5db8e875a456c191 # Parent aa5268900ba11dea43a577504093f2722a81d598 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. diff -r aa5268900ba1 -r 31cbace4c0f1 hgext3rd/topic/__init__.py --- 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")) diff -r aa5268900ba1 -r 31cbace4c0f1 tests/test-topic.t --- 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