# HG changeset patch # User Razvan Cojocaru # Date 2014-03-16 15:31:31 # Node ID b13b99d39a465df4843048484e9bd0bab0433a0c # Parent d9a8017dce10ad7c2b74d3e907f52dfefc23e3c2 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. diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py --- a/mercurial/dispatch.py +++ b/mercurial/dispatch.py @@ -58,6 +58,8 @@ def dispatch(req): 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 @@ def _runcatch(req): 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 diff --git a/tests/test-config.t b/tests/test-config.t --- a/tests/test-config.t +++ b/tests/test-config.t @@ -19,6 +19,25 @@ Invalid syntax: no key 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 diff --git a/tests/test-hgrc.t b/tests/test-hgrc.t --- a/tests/test-hgrc.t +++ b/tests/test-hgrc.t @@ -43,6 +43,7 @@ issue1829: wrong indentation $ 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'" \