如何将 Mercurial 子存​​储库推送到它们自己的源

How to push Mercurial subrepositories to their own origin

我正在使用子存储库在多个项目之间共享代码。 我将这些共享存储库的“主”版本保存在一个中央位置。 这样我就可以轻松地将我对它们所做的更改推送到一个项目中,并将它们拉到另一个项目中。 这行得通,但理想情况下,我只想推送项目存储库,所有子存储库都应推送到 它们的 来源。但是 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

我最终使用了钩子。首先,central location的projects里面的libraries需要指向对应的central library repository:

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

这样我每次推送项目时都会触发对中央库的推送。