我正在编写一些调用 Mercurial 的单元测试,我想确保这些测试不依赖于机器的任何本地状态。我知道我可以覆盖某些配置值,例如:
hg --config ui.username='Test Account <not-a-real-address@example.com>' ...
然而,这仍然会读取机器上的全局和用户 .hgrc
文件,这可能会以意想不到或不希望的方式影响 Mercurial 的行为。
是否有一种可靠的方法来调用 hg
而无需查看 任何 配置文件,除了 repo 中的 .hg/hgrc
文件?例如,对于 Bash,我可以使用 bash --noprofile --norc
完成此操作,但我没有看到 Mercurial 的类似标志。
注意:我知道“重量级”选项,例如在隔离的虚拟环境(如 Docker)中运行测试。如果有必要,我当然会做类似的事情,但我想知道是否有办法配置 Mercurial 本身。
最佳答案
发现更多一点 Issue 3147: command line option to disable ~/.hgrc ,这是 CLOSED WONTFIX,但是建议的解决方法似乎可以按预期工作:
$ HGRCPATH= hg ...
这会覆盖 hgrc 文件的默认搜索路径,尽管在 hgrc docs 中并未提及(截至撰写本文时)。 (编辑:在 another page 中提到)。
例子:
# lots of inherited config by default
$ hg showconfig | wc
118 361 7232
$ HGRCPATH= hg showconfig
ui.formatted=True
ui.interactive=False
$ hg init foo && cd foo
$ HGRCPATH= hg showconfig
bundle.mainreporoot=/tmp/foo
ui.formatted=True
ui.interactive=False
关于unit-testing - 在不加载全局和用户配置的情况下调用 Mercurial,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52584763/