Version-controlled extension configuration in Mercurial
Asked Answered
M

4

8

Normally, I would enable extensions by adding the following to .hg/hgrc:

[extensions]
hgext.win32text=
[encode]
** = cleverencode:
[decode]
** = cleverdecode:

However, I want this configuration to be versioned, i.e. part of the repository, so that it is enabled for anyone else (coworkers, build machines) cloning the repository. Note that whomsoever clones the repository should not be required to do anything to enable these extensions.

It appears it is not possible from the documentation, but does anyone know any neat tricks that can help me here?

Madagascar answered 13/5, 2009 at 7:18 Comment(0)
W
10

You want mercurial to do something automatically when you clone a repo (update the hooks or config). Documentation says it is not possible and gives some very good reasons:

Hooks do not propagate

In Mercurial, hooks are not revision controlled, and do not propagate when you clone,
or pull from, a repository. The reason for this is simple: a hook is a completely    
arbitrary piece of executable code. It runs under your user identity, with your 
privilege level, on your machine. No comments

It would be extremely reckless for any distributed revision control system to 
implement revision-controlled hooks, as this would offer an easily exploitable way to 
subvert the accounts of users of the revision control system. No comments

So clearly, mercurial itself won't solve your problem. You clearly state that you want nothing but mercurial to solve your problem, so the answer is: what you are asking is not possible.

The only way to solve your problem is that all your users will have to run/install at least once a given script that perform the actions you want, something like installing the right hooks.

If you want to be clever about this:

  • create a one-time script to run that will install a hook to copy the right config into the .hg or the user
  • make sure that the hook, once installed, can update the script to distribute config updates to the users
  • make the hook add some special marking to commit messages
  • refuse on the central repository commit that do not carry the special message

A bit complicated, but that's the closest I can imagine to your requirements:

  • user run a script once and they forget
  • you can make sure that if the did not run it, they can not commit to your central repo
Wager answered 13/5, 2009 at 8:9 Comment(1)
Yes, special build scripts or common build server configurations are the next best solution. I was just hoping that there was some not-easily-discoverable functionality in HG for this. --- "Documentation says it is not possible and gives some very good reasons." Where does it say this? Sounds like something I want to read.Madagascar
S
6

The current development version of Mercurial (to be released as Mercurial 1.3 on July 1st) supports a %include directive in its configuration files.

That means that you can ask people to put

%include ../common-hgrc

into .hg/hgrc. Having done that, you can then effectively control their Mercurial settings by committing changes to common-hgrc. When they pull the change, the new settings will take effect.

Do note, that this is dangerous: anybody who can get you to pull changes into your repository can now insert arbitrary hooks into common-hgrc and you will execute them on the next Mercurial command (even a "safe" command line hg status).

Summerly answered 22/5, 2009 at 9:40 Comment(1)
I like this workaround. It id trivial to include in the repos a little script that appends the %include line to .hg/hgrcManis
G
1

You might be able to solve that problem via the ProjRC extension.

“This extension makes Mercurial look for and parse .hg/projrc for additional configuration settings. The file is transferred on clone and on pull (but never on push)”

Goodnatured answered 2/7, 2012 at 9:46 Comment(0)
B
0

What about creating a link from .hg/hgrc to e.g. customhg/hgrc so that it gets versioned. Then you need to create some hook that copies it back to .hg/hgrc - e.g. after each update.

Binaural answered 13/5, 2009 at 7:23 Comment(3)
It needs to be fully automatic, I don't want to periodically log in to each and every build slave to create the .hg/hgrc link.Madagascar
I think mercurial supports links. So, if you check customhg/hgrc in, while it points to .hg/hgrc, that should work.Binaural
The link creation itself is not automatic. So, you are asking users to perform a specific action, which the author do not want.Wager

© 2022 - 2024 — McMap. All rights reserved.