Join multiple subrepos into one and preserve history in Mercurial
Asked Answered
L

3

11

Currently I have project consisting of multiple repositories, e.g.:

+---Project (main repo)
    +---Core (subrepo)
    +---Web (subrepo)
    \---Tests (subrepo)

Unfortunately the code between subrepos is quite coupled so it doesn't work nicely with branches.

Is there any way to consolidate the subrepos into one main repository preserving the history?

Latham answered 7/10, 2010 at 14:24 Comment(0)
S
8

I would start with using hg convert with a filemap that excludes the .hgsub and the subrepos. Next, use hg convert on the subrepos with rename entries in the filemap like: rename . Core

Once you have those new repos, you can use hg pull -f to import the changesets from the converted subrepos into the converted main repo one at a time. You'll also need to merge them into your new main repo (they form separate heads with the null revision as the most recent common ancestor).

Sleeve answered 7/10, 2010 at 15:11 Comment(5)
Almost what I wanted. Any ideas on how to preserve the same folder layout?Latham
@regent: I'd added a comment to yanjost's answer saying how to do this; I've now incorporated it nto my answer.Sleeve
Hey I wasn't so far away from the solution ;)Smriti
you can auto-generate this file via the following command chain: ls -1 Project | xargs -n 1 echo 'exclude' (could not edit previous comment because 5 minutes is too long for StackOverflow :-/ )Vault
see also https://mcmap.net/q/1018813/-are-there-advantages-of-using-hg-convert-to-merge-2-repos-instead-of-hg-pull-f (original question does the opposite but the rename example in the answer shows our case here) for more details on the pull and merge part.Vault
S
3

First guess : Perhaps by using the convert extension with a filemap ?

Another try :

  • Pull all your repos into the same repo, you will have different heads for the "default" branch
  • Then for each head
    • Update to this head
    • Move the files (hg move) into the right directory
  • Merge all the "default" heads together

Edit : added more details, and another try

Smriti answered 7/10, 2010 at 14:31 Comment(3)
It looks like 'convert' even doesn't attempt to convert subrepos when converting the main.Latham
Force-pulling worked! But any ideas on how to preserve the same directory layout? (Currently the contents of Core, Web and Tests are in the same Project folder.)Latham
@regent: use hg convert on the subrepos with rename entries in the filemap like: rename . Core; then hg pull -f from those new repos.Sleeve
T
0

Assuming you don't have to convert repos, why not simply push each repo in the central one?

  1. Make sure each repo root directory have a main directory named after the repo name.
  2. push each repo in the main repo.
Touraco answered 7/10, 2010 at 15:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.