Reputation: 1719
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
Upvotes: 11
Views: 5589
Reputation: 2077
Here's how I did it:
$ cd /projects/main_project
$ hg clone /projects/plugins/awesome plugins/awesome_plugin
$ echo plugins/awesome_plugin = plugins/awesome_plugin > .hgsub
$ hg add .hgsub
$ hg commit -m "added awesome_plugin plugin as a subp-repo"
Upvotes: 0
Reputation: 16905
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.
Upvotes: 2
Reputation: 13972
The subrepo documentation confused me so much so I wrote a shell script to abstract that part of it away.
Call it like
$ cd $TOP_OF_HG_PROJECT
$ addsubrepo.sh $URL_TO_HG_PROJECT relative_path/you/want_to/put_the_subrepo
Upvotes: 7