我可以通过编程方式设置 Mercurial 配置选项吗?
我正在寻找一种方法来设置 .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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您希望保存配置更改,那么某人(无论是您还是 Mercurial)都必须编辑配置文件:-)
如果您可以调用 Mercurial
,那么您也应该能够执行
保存配置更改的操作,无论
~/.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
then you should also be able to do
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.这种形式:
不保存任何内容。它仅设置一次运行的值。
如果有帮助的话,您也可以使用 /etc/mercurial/hgrc 进行系统范围的设置。
This form:
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.有一个扩展可以帮助解决此问题,https://bitbucket.org/alu/hgconfig/wiki/ Home
安装该 hgext 后,您可以执行以下操作。
唯一的问题是这会覆盖内置的配置命令,您可以调整代码来更改命令名称,或者接受它。幸运的是,如果您的用例只是设置和获取特定配置,那可能并不重要。
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.
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.