Search code examples
visual-studio-2010mercurialmergeprojects-and-solutionschangeset

Merging disparate projects with repositories into a single solution with hg?


I started two disparate projects in Visual Studio 2010, each with their own hg repository.

Later I decided that the two projects belonged under one solution, and thus one hg repository.

The new solution the following file structure:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |      ∟--.hg  
   |    ∟ Project_B
   |      ∟--.hg
   +---OverarchingSolution.sln

Is there a way that I can merge Project_A's and Project_B's changesets into the solution folder's repository?

Thus resulting in:

SolutionFolder
   |---.hg
   +---Lib
   |    ∟ dlls
   +---Source
   |    ∟ Project_A
   |    ∟ Project_B
   +---OverarchingSolution.sln

With all of the changesets from Project_A's and Project_B's landing in the SolutionFolder's repository?


Solution

  • If you think there's a chance you'll ever want to use those two repositories separately again (i.e: use one in a different solution but not the other) then you can just make them subrepositories of a new top level repository.

    To do that you'd just cd into SolutionFolder and create a file named .hgsub containing these lines:

    Source/Project_A = Source/Project_A
    Source/Project_B = Source/Project_B
    

    then you run these commands (still in SolutionFolder):

    hg init
    hg add .hgsub
    hg commit -m 'new repo with two sub repos'
    

    After that you can do most all the normal Mercurial commands up in Solution Folder (status, commit, etc) with an additional --subrepos argument and they'll cascade down into the sub-repos.