Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I move my Mercurial repository root up one directory?

I have a directory structure like:

project_root
  data/
  src/
    .hg/
    utils/
    math/
    graphics/
    ...
  README.txt
  LICENCE.txt

As you can see from the location of .hg/, only src/ is under Hg control. I'd like to move the repository root up from src/ to its parent directory project_root, so I can track data/, README.txt, and LICENCE.txt as well.

A hacky way to do this would be to move everything down a directory rather than moving .hg up:

  • Move the contents of src down to a new directory src/src/
  • Move the contents of project_root (other than src/) down to src/
  • Rename src to new_project_root
  • Move new_project_root out of project_root, delete project_root

Is there a better way? I can't be the first person with this problem, and the above solution seems overly involved.

like image 481
SuperElectric Avatar asked Jul 17 '11 16:07

SuperElectric


2 Answers

You should try hg convert. You will be "converting" your existing Mercurial repo into a new one. You specify rules for the conversion, which in your case will be that all files from the original repo go to a src directory in the new repo. Then you can manually copy and hg add the other files to the new repo.

This has the advantage that it won't be reflected as separate changes in your history. The possible disadvantage is that it will cause your changeset IDs to be regenerated, and existing clones will no longer be able to pull from the new repo.

like image 98
John Zwinck Avatar answered Nov 18 '22 19:11

John Zwinck


Your plan is fine. It may seem involved, but it should take less than 20 minutes (worst case) and only happens once.

In the first step when you move the files that are tracked, you should use hg rename (alias hg move) to move them, as Mercurial will remember what each file was before and after the move. This will help with merging changes on file prior to the move with the new files after the move. Works best when renaming/copying is not accompanied by changes to the contents in the same changeset.

I recommend cloning the actual repo (or copying the entire project directory) before proceeding.

like image 32
Joel B Fant Avatar answered Nov 18 '22 19:11

Joel B Fant