diff --git a/hgext3rd/configwarn.py b/hgext3rd/configwarn.py new file mode 100644 --- /dev/null +++ b/hgext3rd/configwarn.py @@ -0,0 +1,53 @@ +# configwarn.py - warn unsupported user configs +# +# Copyright 2017 Facebook, Inc. +# +# This software may be used and distributed according to the terms of the +# GNU General Public License version 2 or any later version. + +"""warn unsupported user configs + +Config:: + + [configwarn] + # Config names that are supposed to be set by system config and not + # overrided by user config. + systemconfigs = diff.git, extensions.hggit +""" + +from __future__ import absolute_import + +from mercurial.i18n import _ +from mercurial import ( + rcutil, + registrar, +) + +configtable = {} +configitem = registrar.configitem(configtable) + +configitem('configwarn', 'systemconfigs', default=[]) + +def reposetup(ui, repo): + # use reposetup, not uisetup to work better with chg and it checks reporc. + if not repo.local(): + return + + nonsystempaths = set(rcutil.userrcpath() + [repo.vfs.join('hgrc')]) + systemconfigs = ui.configlist('configwarn', 'systemconfigs') + + for configname in systemconfigs: + if '.' not in configname: + continue + + section, name = configname.split('.', 1) + source = ui.configsource(section, name) + + if ':' not in source: + continue + + path, lineno = source.split(':', 1) + if path in nonsystempaths and lineno.isdigit(): + ui.warn(_('warning: overriding config %s is unsupported (hint: ' + 'remove line %s from %s to resolve this issue)\n') + % (configname, lineno, path)) diff --git a/tests/test-configwarn.t b/tests/test-configwarn.t new file mode 100644 --- /dev/null +++ b/tests/test-configwarn.t @@ -0,0 +1,54 @@ + $ cat >> $HGRCPATH < [extensions] + > configwarn=$TESTDIR/../hgext3rd/configwarn.py + > [configwarn] + > systemconfigs=diff.git, phases.publish + > [alias] + > noop=log -r null -T '{files}' + > EOF + +Need to override rcutil.userrcpath to test properly without side-effects + + $ cat >> $TESTTMP/rcpath.py < from __future__ import absolute_import + > from mercurial import encoding, rcutil + > def userrcpath(): + > return [encoding.environ[b'USERHGRC']] + > rcutil.userrcpath = userrcpath + > EOF + + $ cat >> $HGRCPATH < [extensions] + > rcpath=$TESTTMP/rcpath.py + > EOF + + $ USERHGRC="$TESTTMP/userhgrc" + $ HGRCPATH="$HGRCPATH:$USERHGRC" + $ export USERHGRC + +Config set by system config files or command line flags are fine + + $ hg init + $ hg noop + $ hg noop --config diff.git=1 + +Config set by user config will generate warnings + + $ cat >> $USERHGRC < [diff] + > git=0 + > EOF + + $ hg noop + warning: overriding config diff.git is unsupported (hint: remove line 2 from $TESTTMP/userhgrc to resolve this issue) + +Config set by repo will generate warnings + + $ cat >> .hg/hgrc << EOF + > [phases] + > publish=1 + > EOF + + $ hg noop + warning: overriding config diff.git is unsupported (hint: remove line 2 from $TESTTMP/userhgrc to resolve this issue) + warning: overriding config phases.publish is unsupported (hint: remove line 2 from $TESTTMP/.hg/hgrc to resolve this issue)