Patchwork [stable,V3] config: exit non zero on non-existent config option (issue4247)

login
register
mail settings
Submitter Aaron Kushner
Date Aug. 30, 2014, 4:58 p.m.
Message ID <8f29078a0d6314047d8e.1409417908@dev1904.prn2.facebook.com>
Download mbox | patch
Permalink /patch/5643/
State Accepted
Headers show

Comments

Aaron Kushner - Aug. 30, 2014, 4:58 p.m.
# HG changeset patch
# User Aaron Kushner <akushner@fb.com>
# Date 1408492622 25200
#      Tue Aug 19 16:57:02 2014 -0700
# Node ID 8f29078a0d6314047d8efa2937f9f660de15a04d
# Parent  bdc0e04df243d3995c7266bf7d138fddd0449ba6
config: exit non zero on non-existent config option (issue4247)

When running 'hg config no_such_option', hg exited with a
zero exit code. This change now exits with a 1 if the
config option does not exist.
Matt Mackall - Sept. 1, 2014, 9:05 p.m.
On Sat, 2014-08-30 at 09:58 -0700, Aaron Kushner wrote:
> # HG changeset patch
> # User Aaron Kushner <akushner@fb.com>
> # Date 1408492622 25200
> #      Tue Aug 19 16:57:02 2014 -0700
> # Node ID 8f29078a0d6314047d8efa2937f9f660de15a04d
> # Parent  bdc0e04df243d3995c7266bf7d138fddd0449ba6
> config: exit non zero on non-existent config option (issue4247)

Queued for stable, thanks. Congrats on your first Mercurial patch.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1498,7 +1498,7 @@ 
 
     See :hg:`help config` for more information about config files.
 
-    Returns 0 on success.
+    Returns 0 on success, 1 if NAME does not exist.
 
     """
 
@@ -1551,6 +1551,7 @@ 
         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'))
+    matched = False
     for section, name, value in ui.walkconfig(untrusted=untrusted):
         value = str(value).replace('\n', '\\n')
         sectname = section + '.' + name
@@ -1560,14 +1561,20 @@ 
                     ui.debug('%s: ' %
                              ui.configsource(section, name, untrusted))
                     ui.write('%s=%s\n' % (sectname, value))
+                    matched = True
                 elif v == sectname:
                     ui.debug('%s: ' %
                              ui.configsource(section, name, untrusted))
                     ui.write(value, '\n')
+                    matched = True
         else:
             ui.debug('%s: ' %
                      ui.configsource(section, name, untrusted))
             ui.write('%s=%s\n' % (sectname, value))
+            matched = True
+    if matched:
+        return 0
+    return 1
 
 @command('copy|cp',
     [('A', 'after', None, _('record a copy that has already occurred')),
diff --git a/tests/test-config.t b/tests/test-config.t
--- a/tests/test-config.t
+++ b/tests/test-config.t
@@ -83,3 +83,8 @@ 
 
   $ hg showconfig unsettest
   unsettest.set-after-unset=should be set (.hg/hgrc)
+
+Test exit code when no config matches
+
+  $ hg config Section.idontexist
+  [1]
diff --git a/tests/test-lfconvert.t b/tests/test-lfconvert.t
--- a/tests/test-lfconvert.t
+++ b/tests/test-lfconvert.t
@@ -326,6 +326,7 @@ 
   verified existence of 6 revisions of 4 largefiles
   [1]
   $ hg -R largefiles-repo-hg showconfig paths
+  [1]
 
 
 Avoid a traceback if a largefile isn't available (issue3519)