changeset 22276:b13b99d39a46

config: highlight parse error caused by leading spaces (issue3214) Added "unexpected leading whitespace" message to parse error when .hgrc has a line that starts with whitespace. Helps new users unfamiliar with syntax of rc file.
author Razvan Cojocaru <razvan.cojocaru93@gmail.com>
date Sun, 16 Mar 2014 17:31:31 +0200
parents d9a8017dce10
children e116abad3afa
files mercurial/dispatch.py tests/test-config.t tests/test-hgrc.t
diffstat 3 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dispatch.py	Wed Aug 20 22:52:56 2014 -0700
+++ b/mercurial/dispatch.py	Sun Mar 16 17:31:31 2014 +0200
@@ -58,6 +58,8 @@
         if len(inst.args) > 1:
             ferr.write(_("hg: parse error at %s: %s\n") %
                              (inst.args[1], inst.args[0]))
+            if (inst.args[0][0] == ' '):
+                ferr.write(_("unexpected leading whitespace\n"))
         else:
             ferr.write(_("hg: parse error: %s\n") % inst.args[0])
         return -1
@@ -155,6 +157,8 @@
         if len(inst.args) > 1:
             ui.warn(_("hg: parse error at %s: %s\n") %
                              (inst.args[1], inst.args[0]))
+            if (inst.args[0][0] == ' '):
+                ui.warn(_("unexpected leading whitespace\n"))
         else:
             ui.warn(_("hg: parse error: %s\n") % inst.args[0])
         return -1
--- a/tests/test-config.t	Wed Aug 20 22:52:56 2014 -0700
+++ b/tests/test-config.t	Sun Mar 16 17:31:31 2014 +0200
@@ -19,6 +19,25 @@
   hg: parse error at $TESTTMP/.hg/hgrc:1: =nokeyvalue
   [255]
 
+Test hint about invalid syntax from leading white space
+
+  $ cat > .hg/hgrc << EOF
+  >  key=value
+  > EOF
+  $ hg showconfig
+  hg: parse error at $TESTTMP/.hg/hgrc:1:  key=value
+  unexpected leading whitespace
+  [255]
+
+  $ cat > .hg/hgrc << EOF
+  >  [section]
+  > key=value
+  > EOF
+  $ hg showconfig
+  hg: parse error at $TESTTMP/.hg/hgrc:1:  [section]
+  unexpected leading whitespace
+  [255]
+
 Reset hgrc
 
   $ echo > .hg/hgrc
--- a/tests/test-hgrc.t	Wed Aug 20 22:52:56 2014 -0700
+++ b/tests/test-hgrc.t	Sun Mar 16 17:31:31 2014 +0200
@@ -43,6 +43,7 @@
   $ echo '  x = y' >> $HGRC
   $ hg version
   hg: parse error at $TESTTMP/hgrc:2:   x = y
+  unexpected leading whitespace
   [255]
 
   $ python -c "print '[foo]\nbar = a\n b\n c \n  de\n fg \nbaz = bif cb \n'" \