3

我希望项目的父目录包含一个 hgrc 文件,该文件夹中的 repo 继承自该文件,例如

~/work/
~/work/hgrc
~/work/project1/
~/work/project2/
~/personal/hgrc
~/personal/project1
~/personal/project2
~/personal/project3

工作中的任何项目都应该继承自work/hgrc,个人中的任何项目都应该继承自personal/hgrc。我正在考虑在克隆上添加一个脚本,以~/.hgrc搜索父目录中的任何 hgrc 文件以及%include它们是否存在,但这有一个丑陋之处,即如果我在克隆它之后在它下面添加一个 hgrc,它将不会被包含在内。只有 5% 的时间考虑,但仍然...

4

2 回答 2

3

怎么放:

%include ../hgrc

在每个 repo 的 .hg/hgrc 中?您甚至可以自动执行此操作,但将其放在您的系统范围内/etc/mercurial/hgrc

[hooks]
post-clone = echo '%include ../hgrc' >> .hg/hgrc

我没有测试过那个钩子。:)

于 2011-02-11T18:47:52.540 回答
0

Following @Ry4an's suggestion, here is an example that works for me. I add this to my ~/.hgrc file so it works everywhere.

[hooks]
# This hook adds "%include ../.hgrc" to .hg/hgrc if the .hgrc file exists in
# the top level.  This allows one to store a set of paths for example.
# See 
update = if [ -e .hgrc ] && touch .hg/hgrc                                  \
                         && ! grep -q '%include \.\./\.hgrc' .hg/hgrc; then \
           echo '%include ../.hgrc' >> .hg/hgrc;                            \
         fi

This hook adds the line %include ../.hgrc to the .hg/hgrc file iff the file .hgrc exists in the top level of the repo. Note that by using the update hook, we bypass the issue of the with post-clone clone hook of having to try to figure out the directory name of the target clone from environmental variables.

于 2014-06-12T23:19:54.820 回答