我使用子库在多个项目之间共享代码。我保留着";主";位于中心位置的这些共享存储库的版本。这样,我就可以很容易地在一个项目中推动我对它们所做的更改,并在另一个项目中将它们拉入。这是可行的,但理想情况下,我只想推送项目存储库,所有子存储库都应该推送到它们的来源。但Mercurial总是将所有子存储库推送到主存储库的原点。
这是我的设置:
Project1 (default path = Project-Central-Location/Project1)
- lib-A (default path = Library-Central-Location/lib-A)
- lib-B (default path = Library-Central-Location/lib-B)
Project2 (default path = Project-Central-Location/Project2)
- lib-A (default path = Library-Central-Location/lib-A)
Library-Central-Location
- lib-A <= push of Project1 should push lib-A to this location
- lib-B
Project-Central-Location
- Project1
- lib-A <= push of Project1 pushes lib-A to this location instead
- lib-B
- Project 2
- lib-A
我最终使用了钩子。首先,位于中心位置的项目内部的库需要指向相应的中心库存储库:
Project-Central-Location
- Project1
- lib-A <= (default path = Library-Central-Location/lib-A)
- lib-B <= (default path = Library-Central-Location/lib-B)
- Project 2
- lib-A <= (default path = Library-Central-Location/lib-A)
然后你需要将其添加到他们的.hg/hgrc
文件中:
[hooks]
changegroup.hg-push = hg push
这样,每当我推动项目时,我都会触发对中央图书馆的推动。