Can I nest subrepos in Mercurial?
Asked Answered
W

2

8

I am having trouble setting up a project in Mercurial with subrepos.

Goal:

I want to set up the structure like so:

-- Build_Repo (this repo will be used to track dependencies)
  -- Subrepo_A (this is the main source)
    -- Modules (Part of Subrepo_A)
      -- Subrepo_B 

So there are three repos: Build, A, and B. B is nested inside A, A is nested inside the root build repository. The build repo will be used to track dependencies, subrepo A will be used to track the main source files, and subrepo B (and others) will be used to track module/plugin development.

Problem/Question

I have no problem setting up the initial build repo and the nested Subrepo_A by simply adding the Subrepo_A path and source to the .hgsub file and committing it to the build repo. However, when after I add the subrepo_B path/source to the build repo's .hgsub, and then try to commit I get the error message:

abort: path 'Subrepo_A/Modules/Sebrepo_B' is inside nested repo 'Subrepo_A'

Mercurial doesn't appear to like a nested repo inside an already nested repo. Is this true, or am I missing something? Any better ideas on how to manage builds/dependencies?

Wiredraw answered 12/9, 2011 at 22:8 Comment(1)
What language/toolset are you using? Generally sub-repos as dependency management are sub-optimal. I like building a module, publishing it's artifacts (nexus, artifactory, etc) and having dependent modules consume it.Nag
P
1

The problem here is one of Mercurial's inescapable constraints: a repository corresponds to a folder tree on your computer. The repository is responsible for everything under that folder tree.

When your top-level repository includes a sub-repository, it hands over to the sub-repo complete control of that part of its folder structure. So the top level can't specify another sub-repository somewhere in the first sub-repos folders.

Solution 1

Subrepo_B is actually a dependency of Subrepo_A. In that case, make your repositories reflect the true dependency by editing Subrepo_A's .hgsub file to add Subrepo_B under Modules/Sebrepo_B. This works because Subrepo_A retains control over its folders.

Solution 2

Subrepo_A doesn't depend on Subrepo_B, you were putting it there for convenience. In this case, you should make both Subrepo_A and Subrepo_B be subrepos (in different locations) of the Build_Repo.

Papilloma answered 4/7, 2012 at 7:48 Comment(0)
L
0

In your situation, you'll have to add subrepoB to subrepoA.

I would suggest trying to move dependencies so that your tree only has 2 levels, but that may not be possible. It's always not a very smooth experience otherwise.

Leland answered 13/9, 2011 at 3:43 Comment(2)
Any other recommendations on how to manage dependencies in this situation?Wiredraw
The answer to this, as others have noted, is to make subrepoB a subrepo of subrepoA, and subrepoA a subrepo of build_repo. It seems like you don't want to do this for some reason. If it is because subrepoA is a clone of a project you don't control, and therefore can't add a subrepo to, a way around that is to make a private fork/clone of subrepoA, and use that as the repo for "subrepoA". That way you can add customizations to it (add subrepo to it), and still keep in sync with the pulic/external updates to subrepoA.Gramicidin

© 2022 - 2024 — McMap. All rights reserved.