Importing unrelated repo into another repo in Mercurial

659 Views Asked by At

I have two Mercurial repositories. Both repos have their own unrelated history. Let's call them:

  • "Main" (contains the project itself)
  • "Lab" (contains some related content)

I would now like to "import" the Lab repo into the Main repo with the following constraints:

  • Both repos shall keep their history.
  • Lab shall be stored as a subfolder in Main.
  • The changes from Lab shall be be located in a branch which gets merged into Main.

Following https://www.mercurial-scm.org/wiki/MergingUnrelatedRepositories basically works but doesn't create a branch.

1

There are 1 best solutions below

2
On BEST ANSWER

Given a repository Main and Lab, you can merge the Lab repository into the Main repository and rename its default branch to some other name by doing the following with the convert extension:

  1. Create a file "branchmap.txt" containing default Lab. Using this branchmap, the Lab changesets in the "default" branch will be named "Lab". If you have other branches in your Lab repository, you may want additional entries.
  2. Run hg convert Lab Main --branchmap branchmap.txt. This assumes the Lab and Main repository directories, and the branchmap.txt file, are in the current directory. Adjust paths accordingly. The Lab changesets will be added to the Main repository.
  3. In the Main repository, the following commands will move the Lab files into a Lab subdirectory then merge the Lab branch with default.
    a. hg update Lab
    b. mkdir Lab
    c. hg move * Lab d. hg ci -m "Moved Lab files to Lab subdirectory"
    e. hg update default
    f. hg merge Lab
    g. hg ci -m Merge

Now you can continue to modify the Lab branch in the future and merge to default as needed.