Can I set Mercurial config options programmatically?

梦想与她 提交于 2019-11-30 17:58:41

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.

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.

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://hg@bitbucket.org/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://hg@bitbucket.org/nassrat/hgconfig
paths.upstream=ssh://hg@bitbucket.org/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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!