在mercurial中,有没有办法禁用所有配置(系统,用户,回购)?

Geo*_*eng 6 mercurial

在任何非平凡的hg安装中,hgrc往往包含重要的东西.

有没有办法完全忽略/绕过从系统,用户到回购级别的所有配置?

用例是在某些自动化脚本中使用一些hg核心功能.目前,如果有任何错误配置(我和我的〜/ .hgrc混乱),脚本将中止它根本不使用的东西.

它是完美的,我可以hg <whatever> --config:none.

Ry4*_*ase 8

您可以通过将HGRCPATH环境变量设置为没有配置的东西来实现.

ry4an@hail [~/hg/crew] % hg showconfig | grep Ry4an
ui.username=Ry4an Brase <ry4an@msi.umn.edu>
ry4an@hail [~/hg/crew] % HGRCPATH=/dev/null hg showconfig | grep Ry4an
ry4an@hail [~/hg/crew] % 
Run Code Online (Sandbox Code Playgroud)

此外,如果您从脚本调用也考虑HGPLAIN.

在这里都发现:https://www.mercurial-scm.org/repo/hg/file/e3b87fb34d00/mercurial/help/environment.txt

哪个说:

    41 HGRCPATH
    42     A list of files or directories to search for configuration
    43     files. Item separator is ":" on Unix, ";" on Windows. If HGRCPATH
    44     is not set, platform default search path is used. If empty, only
    45     the .hg/hgrc from the current repository is read.
    46 
    47     For each element in HGRCPATH:
    48 
    49     - if it's a directory, all files ending with .rc are added
    50     - otherwise, the file itself will be added
    51 
    52 HGPLAIN
    53     When set, this disables any configuration settings that might
    54     change Mercurial's default output. This includes encoding,
    55     defaults, verbose mode, debug mode, quiet mode, tracebacks, and
    56     localization. This can be useful when scripting against Mercurial
    57     in the face of existing user configuration.
    58 
    59     Equivalent options set via command line flags or environment
    60     variables are not overridden.
Run Code Online (Sandbox Code Playgroud)


Rod*_*Rod 2

似乎没有任何选项可以执行您想要的操作。但由于文档指出

(Unix、Windows)/.hg/hgrc

仅适用于特定存储库的每个存储库配置选项。该文件不受版本控制,并且在“克隆”操作期间不会传输。该文件中的选项将覆盖所有其他配置文件中的选项。在 Unix 上,如果该文件不属于受信任的用户或受信任的组,则该文件的大部分内容将被忽略。有关更多详细信息,请参阅下面可信部分的文档。

以下脚本将读取标准输入并将 hg -showconfig 的输出转换为可在 处写入的覆盖配置<repo>/.hg/hgrc。实际上它会覆盖 hg 找到的所有当前配置。该脚本可能需要进行调整,但到目前为止似乎有效。

# File override.py

import sys

config = dict()
for l in sys.stdin.readlines():
    section, sep, value = l.partition('.')
    if not section in config:
        config[section] = []
    config[section].append(value.split("=")[0])

for k in iter(config):
    print "[{0}]".format(k)
    for v in config[k]:
        print v + "="
Run Code Online (Sandbox Code Playgroud)

然后可以这样使用它:

> rm -f .hg/hgrc
> hg -showconfig | python override.py > .hg/hgrc
Run Code Online (Sandbox Code Playgroud)