3

I am using subrepositories to share code between multiple projects. I keep the "master" version of these shared repositories in a central location. That way I can easily push changes I made to them in one project and pull them in another. That works, but ideally I want to just push the project repository and all subrepositories should be pushed to their origin. But Mercurial always pushes all subrepositories into the origin of the main repository.

This is my setup:

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
Karsten
  • 1,814
  • 2
  • 17
  • 32
  • A sub-repository *is* a repository in its own right, so you can `cd` into it and use it the way you would use any repository. That includes configuring paths in the repository if you'd like, and/or running `hg push` with a specific destination. You mention tortoisehg in tags, though, and this is all command-line stuff; I have no idea how to convince tortoisehg to be more capable. – torek Jun 06 '21 at 05:17
  • I know I can push them individually, but this is cumbersome and error prone (I might forget). I will look into hooks and see if they can help with this. – Karsten Jun 07 '21 at 09:34

1 Answers1

2

I ended up using hooks. First, the libraries inside the projects in the central location need to point to the corresponding 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)

Then you need to add this to their .hg/hgrc files:

[hooks]
changegroup.hg-push = hg push

That way I will trigger a push to the central libraries anytime I push the projects.

Karsten
  • 1,814
  • 2
  • 17
  • 32