# HG changeset patch # User Pierre-Yves David # Date 1578392645 -3600 # Node ID d56a2d6f34f065e67f767fe9b27b3dc278ff75b2 # Parent 52f8b07ad2f9194f6c3e2a8666d1f0557341628a hgrc: introduce HGRCSKIPREPO to skip reading the repository's hgrc We had a way to change the behavior regarding reading the global and user config, but we had nothing regarding the repository hgrc itself. This option is useful in situation where scripts need to be able to work around strange configuration set by the user in his repository. (and were HGPLAIN is not enough). Differential Revision: https://phab.mercurial-scm.org/D7807 diff -r 52f8b07ad2f9 -r d56a2d6f34f0 mercurial/helptext/environment.txt --- a/mercurial/helptext/environment.txt Sat Jan 18 10:37:14 2020 -0800 +++ b/mercurial/helptext/environment.txt Tue Jan 07 11:24:05 2020 +0100 @@ -49,6 +49,9 @@ - if it's a directory, all files ending with .rc are added - otherwise, the file itself will be added +HGRCSKIPREPO + When set, the .hg/hgrc from repositories are not read. + HGPLAIN When set, this disables any configuration settings that might change Mercurial's default output. This includes encoding, diff -r 52f8b07ad2f9 -r d56a2d6f34f0 mercurial/helptext/scripting.txt --- a/mercurial/helptext/scripting.txt Sat Jan 18 10:37:14 2020 -0800 +++ b/mercurial/helptext/scripting.txt Tue Jan 07 11:24:05 2020 +0100 @@ -74,6 +74,14 @@ like the username and extensions that may be required to interface with a repository. +HGRCSKIPREPO + When set, the .hg/hgrc from repositories are not read. + + Note that not reading the repository's configuration can have + unintended consequences, as the repository config files can define + things like extensions that are required for access to the + repository. + Command-line Flags ================== diff -r 52f8b07ad2f9 -r d56a2d6f34f0 mercurial/localrepo.py --- a/mercurial/localrepo.py Sat Jan 18 10:37:14 2020 -0800 +++ b/mercurial/localrepo.py Tue Jan 07 11:24:05 2020 +0100 @@ -676,6 +676,8 @@ configs are loaded. For example, an extension may wish to pull in configs from alternate files or sources. """ + if b'HGRCSKIPREPO' in encoding.environ: + return False try: ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base) return True diff -r 52f8b07ad2f9 -r d56a2d6f34f0 tests/test-hgrc.t --- a/tests/test-hgrc.t Sat Jan 18 10:37:14 2020 -0800 +++ b/tests/test-hgrc.t Tue Jan 07 11:24:05 2020 +0100 @@ -258,3 +258,16 @@ plain: True read config from: $TESTTMP/hgrc $TESTTMP/hgrc:17: paths.foo=$TESTTMP/bar + +Test we can skip the user configuration + + $ cat >> .hg/hgrc < [paths] + > elephant = babar + > EOF + $ hg path + elephant = $TESTTMP/babar + foo = $TESTTMP/bar + $ HGRCSKIPREPO=1 hg path + foo = $TESTTMP/bar +