[PATCH now with a test] showconfig: don't accept multiple sections and one config item

Brodie Rao brodie at bitheap.org
Sat Oct 9 16:57:07 CDT 2010


# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1286661333 18000
# Node ID 8efec506f6929cac2a182e7b48d5fa80579f5a2a
# Parent  ef500b2f100b8cbc20dfc90b78e17092e730de48
showconfig: don't accept multiple sections and one config item

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1066,7 +1066,9 @@ def showconfig(ui, repo, *values, **opts
         ui.debug(_('read config from: %s\n') % f)
     untrusted = bool(opts.get('untrusted'))
     if values:
-        if len([v for v in values if '.' in v]) > 1:
+        sections = [v for v in values if '.' not in v]
+        items = [v for v in values if '.' in v]
+        if len(items) > 1 or items and sections:
             raise util.Abort(_('only one config item permitted'))
     for section, name, value in ui.walkconfig(untrusted=untrusted):
         sectname = section + '.' + name
diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t
--- a/tests/test-hgrc.t
+++ b/tests/test-hgrc.t
@@ -75,6 +75,22 @@ username expansion
   $ HGUSER=$olduser
   $ export HGUSER
 
+showconfig with multiple arguments
+
+  $ echo "[alias]" > $HGRCPATH
+  $ echo "log = log -g" >> $HGRCPATH
+  $ echo "[defaults]" >> $HGRCPATH
+  $ echo "identify = -n" >> $HGRCPATH
+  $ hg showconfig alias defaults
+  alias.log=log -g
+  defaults.identify=-n
+  $ hg showconfig alias defaults.identify
+  abort: only one config item permitted
+  [255]
+  $ hg showconfig alias.log defaults.identify
+  abort: only one config item permitted
+  [255]
+
 HGPLAIN
 
   $ cd ..


More information about the Mercurial-devel mailing list