views:

122

answers:

3

Is it possible to create a mercurial repository inside an existing mercurial repository?

The idea is to handle subdirectories of a repository as different repositories, how do you do that?

I'm not talking about subrepos (at least, if I understood the purpose of subrepos...), but if this is how subrepos do exist for, I got it wrong and I'll try to get it right :)

Thanks ~Aki

EDIT: To be more clear, I'd like to know what happens, the practices and the implications of having a repository inside another one, without specifying modules/subrepos. In other words: what happens if I just do:

hg init globalRepo
hg init globalRepo/subRepo

and use these two repositories as-are?

A: 

Google is your friend: http://mercurial.selenic.com/wiki/NestedRepositories

TerryP
Already read, I said I wasn't talking about subrepos. But hey, my fault: I had to be more clear; I'll add some details in the question. Thanks anyway :)
AkiRoss
Generally sub repositories is how you do sub repositories. Other wise you would likely want to tell the top level repo to ignore the contents of globalRepo/subRepo in order to seperate the history, which likely defeats the purpose of it, unless you're just to lazy to make independent repos.
TerryP
+2  A: 

As you can see in this SO question, you can make that kind of nested hg init, even though it is usually reserved for defining subRepo (which is not what you are after).

Normally it should work as two independant repos, but I would advise adding an hgignore rule in the globalRepo in order to ignore the subRepo content altogether.

VonC
Thanks for the answer and sorry for this late comment.So, if I got it correctly, subrepos are almost like nested repos, with the difference that they have a .hgsub tracked in the parent repo, right? Which I guess is an indication for the parent repo which act somewhat like the .hgignore ou suggested me.
AkiRoss
@AkiRoss: "with the difference that they have a `.hgsub` tracked in the parent repo": yes, the parent repo actually reference only the `.hgsub`, which is the exact reference (commit) of the subrepo. But in the case of a nested repo, there is no "parent" repo. The first repo ignores completely the fact it has a nested repo inside itself.
VonC
+5  A: 

It works well. Long before the subrepo support was added in Mercurial 1.3 lots of folks kept their entire home directories in a mercurial repo for tracking their .bashrc files and the like. Then within their home dir they'd have many clones of other repos.

Whenever you invoke mercurial (without the -R option) it looks in the current directory for a .hg directory and then just keeps going up directories until it finds one. So if you're in a repo in a repo your commands will always act on the inner most repo you're in.

The caveat is that you want to make sure not to have files added to the outer repo that end up inside the inner repo. Then you'll have to repos updating the same files.

Ry4an
Much detailed answer than mine. +1
VonC