开发者

How to checkout configuration file and rename it using mercurial?

How do I tell mercurial to copy a file from /home/configs/config.ini into my local clone everytime I run hg clone /home/hg/repo1 without tracking it ?

For example

> ls -l /home/hg/repo1
  开发者_如何学运维file_one.py
  file_two.py

> hg clone /home/hg/repo1 /home/me/repo1
> cd /home/me/repo1
> ls -l /home/me/repo1
  file_one.py
  file_two.py
  config.ini

Thanks, Martin


The preferred way of doing this is by tracking a file called, say, config.ini.example, and then copying it to config.ini, and include config.ini in your .hgignore file. You could also make your application generate a config.ini when it is first run if it does not yet exist.

There are no (documented) hooks for the cloning action because when you clone, you create a new repository. Because this repo is brand new, it has no .hgrc file in order to define hooks. That is, the hooks you run are the ones from the new repository, not the old one.


You can do it with a hook, but you're going to find it more trouble than just creating a clear README.txt. :)

The hook would look like:

[hooks]
post-clone = cp -i config.ini.sample config.ini

As Paul Fischer pointed out, it's better to use a .sample that's in the repo than something like /home/configs/config.ini that's out of the repo.

The problem, as VonC points out, is that hooks aren't copied down on clone -- and for good reason: if cloning brought down hooks too then I'd put post-clone = rm -rf ~ in there are really ruin your day.

So if you're set on using a hook the way around it is to put the hook somewhere outside the repo. In a corporate setting you can do that in the /etc/mercurial/hgrc file on all systems, which if you have a decent IT setup they can do centrally. Since it sounds like you're sure there will be a /home/configs user dir it sounds like you might be talking about all the clones being on a single machine, which case this is a fine option for you. However, in an more decentralized environment you're back to having each person manually install the hook you want in their own ~/.hgrc, and at that point you might as well just have them do the copy themselves.

One idea worth considering is checking if whatever is interpreting your config.ini file has an include-like directive? Then you could have the cloned-down config.ini looks like:

... some stuff
%include /home/configs/config.ini
... more stuff

In which case no copy is necessary at all. Mercurial, for example, does have an include directive which works just like that: http://www.selenic.com/mercurial/hgrc.5.html#syntax


One way would be to define a hook like changegroup, in which you perform the copy right after the clone.
Only problem: that hook won't run with hard-linked paths, as reported in issue 1602.


It sounds like you just need to hardlink the file, so that each time you run hg update in /home/me/repo1 the file in /home/configs is updated as well:

rm /home/configs/config.ini
ln /home/me/repo1/config.ini /home/configs/config.ini

Note that you don't have to remove a clone and reclone to update your working copy. Just use hg pull and hg update.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜