我可以通过编程方式设置 Mercurial 配置选项吗?

发布于 2024-10-11 03:46:48 字数 257 浏览 0 评论 0原文

我正在寻找一种方法来设置 .hgrc 配置项,而无需实际编辑文本文件。我正在尝试标准化多个开发人员之间的 hgrc 设置,我想要一个类似的命令

hg --config ui.username=foo

,但它也会将该配置更改保存到 hgrc 文件中。

看起来这应该是 vanilla hg 命令应该直接支持的东西,但我在任何地方都找不到它。

I'm looking for a way to set .hgrc configuration items without actually editing the text file. I'm trying to standardize the setup of the hgrc across multiple developers and I would like a command like

hg --config ui.username=foo

but which also saves that config change into the hgrc file.

It seems like this should be something that should be supported directly in the vanilla hg command, but I can't find it anywhere.

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

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

发布评论

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

评论(3

鸵鸟症 2024-10-18 03:46:48

如果您希望保存配置更改,那么某人(无论是您还是 Mercurial)都必须编辑配置文件:-)

如果您可以调用 Mercurial

hg --config ui.username=foo

,那么您也应该能够执行

echo '[ui]' >> ~/.hgrc
echo 'username = foo' >> ~/.hgrc

保存配置更改的操作,无论 ~/.hgrc 文件看起来如何(可以有多个 [ui] 部分)。

Mercurial 3.0 及更高版本具有 hg config --edit 命令 打开一个包含用户配置文件的编辑器。仍然不完全符合您的要求,但至少这使得交互式编辑文件变得更容易。

Someone -- either you or Mercurial -- will have to edit the configuration file if you want the config change to be saved :-)

And if you can call Mercurial with

hg --config ui.username=foo

then you should also be able to do

echo '[ui]' >> ~/.hgrc
echo 'username = foo' >> ~/.hgrc

which will save the config change, not matter how the ~/.hgrc file happens to look like (it is okay to have multiple [ui] sections).

Mercurial 3.0 and later has the hg config --edit command that opens an editor with the user config file. Still not quite what you're asking for, but at least this makes it easier to edit the file interactively.

葬心 2024-10-18 03:46:48

这种形式:

hg --config ui.username=foo

不保存任何内容。它仅设置一次运行的值。

如果有帮助的话,您也可以使用 /etc/mercurial/hgrc 进行系统范围的设置。

This form:

hg --config ui.username=foo

Doesn't save anything. It sets the value for just the one run.

Also you can use /etc/mercurial/hgrc for system wide settings if that helps anything.

不气馁 2024-10-18 03:46:48

有一个扩展可以帮助解决此问题,https://bitbucket.org/alu/hgconfig/wiki/ Home

安装该 hgext 后,您可以执行以下操作。

% hg showconfig paths
paths.default=ssh://[email protected]/alu/hgconfig
% hg config paths.upstream $(hg showconfig paths.default)
% hg config paths.default $(hg showconfig paths.default | sed 's|/alu/|/nassrat/|')
% hg showconfig paths
paths.default=ssh://[email protected]/nassrat/hgconfig
paths.upstream=ssh://[email protected]/alu/hgconfig

唯一的问题是这会覆盖内置的配置命令,您可以调整代码来更改命令名称,或者接受它。幸运的是,如果您的用例只是设置和获取特定配置,那可能并不重要。

There is an extension that helps with this, https://bitbucket.org/alu/hgconfig/wiki/Home

After installing that hgext, you can do things like this.

% hg showconfig paths
paths.default=ssh://[email protected]/alu/hgconfig
% hg config paths.upstream $(hg showconfig paths.default)
% hg config paths.default $(hg showconfig paths.default | sed 's|/alu/|/nassrat/|')
% hg showconfig paths
paths.default=ssh://[email protected]/nassrat/hgconfig
paths.upstream=ssh://[email protected]/alu/hgconfig

The only gotcha is this overrides the builtin config command, you can either tweak the code to change the command name, or live with it. Fortunately, it probably would not matter if your use case is simply to set and get specific configs.

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