Changing directory structure in Mercurial

I have a single-user mercury repository with one folder. The directory structure is simple:

P104 lecture_notes files under version control live here 

After some time, I realize that I want to have two directories in the repository, for example

 P104 lecture_notes files under version control live here (.hg is here) homework more files under version control 

Now, if I just try to add files to the repository, it fails:

 br@ymir :~/P104/lecture_notes$ ll .. total 16 drwxr-xr-x 4 br br 4096 2012-02-02 18:05 ./ drwxr-xr-x 4 br br 4096 2012-02-01 20:46 ../ drwxr-xr-x 2 br br 4096 2012-02-02 17:44 homework/ drwxr-xr-x 4 br br 4096 2012-02-02 18:06 lecture_notes/ br@ymir :~/P104/lecture_notes$ hg add ../homework/hw1_P104.tex abort: ../homework/hw1_P104.tex not under root 

My first idea was to clone the repo one level in the directory structure, add files to the clone, and delete the original repo. But even cloning fails:

 br@ymir :~/P104/2011/lecture_notes$ hg clone . .. abort: destination '..' is not empty 

So the question is, is there a way for Mercurial-ish to do this differently than creating a clean repository somewhere else and copying the files manually?

+6
source share
2 answers

If the root directory of your Mercurial repo is under ~/P104/lecture_notes , I would prefer:

  • rename lecture_notes to P104
  • create subdirectory lecture_notes
  • move all existing files to this new subdirectory
  • add homework and its files in the renamed P104 directory
  • hg add all

The idea is to save the .hg repository where it is ( ~/P104/lecture_notes renamed to ~/P104/P104 ) and reorganize the files in this renamed directory.
No need to clone.

+4
source

I like the VonC solution where you do not move the .hg folder. This is a direct solution. Here is an alternative where you move it, and therefore you need to rename fewer folders:

  • Move the .hg folder to ~/P104

     $ mv ~/P104/lecture_notes/.hg ~/P104 

    From the point of view of Mercurial, you have moved all the top-level files to the lecture_notes directory. In the homework folder, new files will also appear without a trace.

  • Let Mercurial define renames:

     $ hg addremove 

    This will correctly detect that files that were top-level files are now in the lecture_notes directory. Untracked (and not ignored) files in homework simply added.

  • Save changes:

     $ hg commit 

The general "trick" is that the files in the working copy are visible relative to the .hg directory. Therefore, moving the .hg directory up in the file system hierarchy, we effectively move the working copy files to the hierarchy inside the working copy.

+7
source

Source: https://habr.com/ru/post/907512/


All Articles