Martin Drozdik
Martin Drozdik

Reputation: 13323

How to combine repositories while retaining the directory structure?

I have many projects that "fit together". They share source files.

enter image description here

Each project (including tens of tests) has its own Mercurial repository.

I would like to join all these repositories into a master repository and retain the same directory structure.

mkdir MasterProject
cd MasterProject
mkdir "Common_sources"
hg init
hg pull ../Common_sources Common_sources 

The last statement obviously doesn't work that way, but it is exactly the behaviour that I would like. That is, copy all the files and their histories and place them into the Common_sources directory.

How can I achieve this in Mercurial?

Upvotes: 0

Views: 58

Answers (1)

Steve Kaye
Steve Kaye

Reputation: 6262

You'll need to use the convert extension to do this.

What you need to do is to convert the source repositories using a filemap to move all the files in the repository into a sub-folder. To do this for the Common_sources folder you would use this command:

hg convert --filemap filemap.txt Common_sources Common_sources.tmp

The filemap.txt file would contain this line of text:

rename . Common_sources

After the convert, you have a repository called Common_sources.tmp with the same history as Common_sources except for the fact that all the files are in a sub-directory.

You would perform a similar task on all the repositories that you want to combine and then combine them into one project as follows:

mkdir MasterProject
hg init
hg pull ../Common_sources.tmp
hg pull ../Integration_tests -f
hg merge
hg commit -m "Merging integration tests"

Repeating the pull, merge and commit for each project that you want to add into the repository project.

When that's all done you can finish off with an hg update to see all the new folders in the master repository.

Upvotes: 2

Related Questions