Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a subrepo to an existing repository in mercurial

Tags:

mercurial

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

like image 662
Hauge Avatar asked Mar 09 '10 12:03

Hauge


2 Answers

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
like image 139
RyanWilcox Avatar answered Sep 18 '22 23:09

RyanWilcox


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.

like image 35
Mikezx6r Avatar answered Sep 21 '22 23:09

Mikezx6r