Mercurial Subrepos – How do you create them and how do they work?

You could probably try this stuff out and learn it more quickly than writing up your question took, but I’ll bite.

Can any or all of these steps be
executed with TortoiseHG, as of
version 0.9.2? If yes, how?

TortiseHG doesn’t yet put GUI wrappers around sub-repo creation, but TortiseHG has always done a great job of working with the command line. Use the command line to create and them and you’re good to go.

What does
the above code do (a line-by-line
explanation would be much
appreciated).

hg init main  # creates the main repo
cd main # enter the main repo
hg init nested # create the nested. internal repo
echo test > nested/foo # put the word test into the file foo in the nested repo
hg -R nested add nested/foo # do an add in the nested repo of file foo
echo nested = nested > .hgsub # put the string "nested = nested" into a file (in main) named .hgsub
hg add .hgsub # add the file .hgsub into the main repo

Here are some specific
questions that came to mind as I was
trying to decipher it: What does > do?

That has nothing to do with mercurial it’s standard shell (unix and dos) for “put the result into a file named X”

In line 5, I don’t
understand what nested/foo is. Where
did foo come from? What is foo? A
repository? A folder?

It’s a file in the subrepo. Foo is a traditional arbitrary name, and the arbitrary contents are the string “test”

Line 6 – this
one completely baffles me.

It’s putting the contents in .hgsub necessary to say that nested is a nested repo named nested and located at nested.

In line 7,
I assume .hgsub is being added to
main? Or is it being added to nested?

main

Let’s say I get my subrepos set up,
and my Bar repository is now up to
revision 10. If I attempt to update to
revision 7, will this cause my library
folders (My
Documents/Development/Libraries/ProjectA
and …/Libraries/ProjectB) to update
to whatever is stored in revision 7 as
well? Given that Foo also refers to
Libraries/ProjectA, this could get
interesting!

Revision numbers won’t carry across, but you have control by editing the .hgsubstate file.

Leave a Comment