Mercurial repo inside a repo
Asked Answered
P

3

5

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?

Pepin answered 12/6, 2010 at 13:12 Comment(2)
The obvious question is, why would you want to do that?Communion
I don't want to do that :) I just wondered what happened, and how mercurial would behave in that case. As I imagined, such usage would be a bit tricky, and I would anyway use subrepos.Pepin
L
15

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 that is in a repo, your commands will always act on the innermost 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 two repos updating the same files.

Levkas answered 13/6, 2010 at 2:15 Comment(1)
Much detailed answer than mine. +1Ecphonesis
E
4

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.

Ecphonesis answered 12/6, 2010 at 17:16 Comment(3)
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.Pepin
@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.Ecphonesis
@Chris but I would advise adding an hgignore rule in the globalRepo in order to ignore the subRepo content altogether. This has absolutely no effect. Since any subdirectory with an .hg folder in it is ignored by the outer repo. And one cannot change that behaviour. And thats why I gave up on mercurial, git keeps tracking unless I ignore the inner one - or declare it a subrepo (which is reasonable and you seem to imply it as given for hg as well)Coumarone
H
0

Here are some docs on nested repositories.

Hygro answered 12/6, 2010 at 13:17 Comment(2)
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 :)Pepin
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.Hygro

© 2022 - 2024 — McMap. All rights reserved.