tags:

views:

122

answers:

3

What is the best/easiest way (or is it even possible) to add an existing repository to another existing repository as a subrepo?

Situation is I have an existing (main) project where I want to include a library project so that i can edit the library project from the main project, and commit the changes to the library project when comitting the main project.

Also: Do I need to clone/push/pull to the original library project, or is this done automatically when committing in the main project?

Regards
Jesper Hauge

A: 

You might want to use the deps extension.

Roberto Aloi
Isn't the deps extension only for external repos that are not mercurial repos? Does deps allow me to commit changes to the "included" repo?
Hauge
According to the docs, it supports 'any' type of repository, including Mercurial
Mikezx6r
If you have a Mercurial sub-repository, just enter it and push from there. It will be able to distinguish the "container" (inner or outer).
Roberto Aloi
I believe the original poster is looking for something more formal, and automatic. I clone a repository that has a dependency. The clone will also bring in dependent projects automatically.When a commit is done, the poster only wants to do commit/push/pull at the top level, and have the rest happen automatically.I believe that's what subrepo is aiming to do, and seems quite far towards that goal.
Mikezx6r
You said id Mikezx6r - when using externals in SVN commits happen automatically, and as far as I remember externals will also be pulled to new checkouts automatically, which makes externals ideal for this kind of setup. Mercurial seems much more fragile and difficult to work with in this respect.
Hauge
+2  A: 

The subrepo documentation confused me so much so I wrote a shell script to abstract that part of it away.

addsubrepo.sh

Call it like

$ cd $TOP_OF_HG_PROJECT
$ addsubrepo.sh $URL_TO_HG_PROJECT relative_path/you/want_to/put_the_subrepo
RyanWilcox
Alas I'm on a windows box so no shell scripts for me, but your scripts could probably be ported to a powershell script, just seems a bit over the top, for such a basic function :-o
Hauge
There's always Cygwin, it's big, but it works fine.
reinierpost
It does feel over the top, but it feels like every time I try to do a subrepo in hg I screw it up. Now I don't :)At the very least this show you how it's done
RyanWilcox
+2  A: 

Reading the docs, the subrepo plugin supports this functionality.

I haven't used it yet, but will likely start using it in the near future.

It is improved every release of Mercurial, and I believe people are successfully using it. It seems to get a reasonable amount of attention, and was on the agenda for the last coding blitz.

According to the help, pull, push, commit etc should act on the subrepo as well. It sounds like a commit will check if there are any changes in the subrepo. If there are, they will be committed, and the new changeset in the subrepo will be recorded in the .hgsubstate file. This file, as well as the changes in the main repo will then be committed.

When you clone, Mercurial should see the .hgsubstate as well as the .hgsub file, and correctly pull the subrepo, and update to the correct revision.

Mikezx6r