在 Mercurial 中,有没有办法禁用所有配置(系统、用户、存储库)?

发布于 2024-10-08 20:21:02 字数 225 浏览 0 评论 0原文

在任何重要的 hg 安装中,hgrc 往往包含重要的内容。

有没有办法完全忽略/绕过从系统、用户到存储库级别的所有配置?

用例是在一些自动化脚本中使用一些 hg 核心功能。目前,如果有任何配置错误(并且我经常弄乱我的 ~/.hgrc),脚本将因根本不使用的内容而中止。

如果我可以 hg就完美了--config:无

On any non-trivial hg installation, the hgrc's tend to contain significant stuff.

Is there a way to completely ignore/bypass ALL configurations, from system, user, to repo-level?

The use case is to use some hg core functionalities in some automation scripts. Currently, if anything is misconfigured (and I mess with my ~/.hgrc a lot), the scripts will abort for something it doesn't use at all.

It'd be perfect is I can just hg <whatever> --config:none.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凶凌 2024-10-15 20:21:02

您可以通过将 HGRCPATH 环境变量设置为不带任何配置的内容来实现此目的。

ry4an@hail [~/hg/crew] % hg showconfig | grep Ry4an
ui.username=Ry4an Brase <[email protected]>
ry4an@hail [~/hg/crew] % HGRCPATH=/dev/null hg showconfig | grep Ry4an
ry4an@hail [~/hg/crew] % 

另外,如果您从脚本调用,也请考虑 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.

You can do it by setting your HGRCPATH environment variable to something with no configuration in it.

ry4an@hail [~/hg/crew] % hg showconfig | grep Ry4an
ui.username=Ry4an Brase <[email protected]>
ry4an@hail [~/hg/crew] % HGRCPATH=/dev/null hg showconfig | grep Ry4an
ry4an@hail [~/hg/crew] % 

Also if you're invoking from a script consider HGPLAIN too.

Both found here: https://www.mercurial-scm.org/repo/hg/file/e3b87fb34d00/mercurial/help/environment.txt

Which says:

    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.
忆沫 2024-10-15 20:21:02

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

(Unix、Windows)/.hg/hgrc

每个存储库的配置选项
只适用于特定的
存储库。该文件不是
版本控制的,并且不会得到
在“克隆”期间转移
手术。 此文件中的选项
覆盖所有其他选项
配置文件。
在 Unix 上,大多数
该文件的内容将被忽略,如果
不属于受信任的用户或
一个值得信赖的团体。查看文档
欲了解更多信息,请参阅下面的可信部分
详细信息。

以下脚本将读取标准输入并将 hg -showconfig 的输出转换为可写入 /.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 + "="

然后可以这样使用它:

> rm -f .hg/hgrc
> hg -showconfig | python override.py > .hg/hgrc

There doesn't seem to have any option to perform want you want. But since the documentation states that

(Unix, Windows) /.hg/hgrc

Per-repository configuration options
that only apply in a particular
repository. This file is not
version-controlled, and will not get
transferred during a "clone"
operation. Options in this file
override options in all other
configuration files.
On Unix, most
of this file will be ignored if it
doesn't belong to a trusted user or to
a trusted group. See the documentation
for the trusted section below for more
details.

The following script will read the stdin and convert the output of hg -showconfig to an override config that could be written at <repo>/.hg/hgrc. Effectively it overrides all the current config found by hg. The script might have to be tweaked but it seems to work so far.

# 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 + "="

It can then be used as such:

> rm -f .hg/hgrc
> hg -showconfig | python override.py > .hg/hgrc
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文