Reorganize directory structure with Mercurial - mercurial

I have a project with directory structure
Foo/
.hg
Bar1/
...
Bar2/
...
Zope/
...
I want to change this to
Foo/
.hg
Source/
Bar1/
...
Bar2/
...
Zope/
...
What is the easiest way? (There are too many files to move them one-by-one. And there are several files with identical content, so if I just move the files and ask Mercurial to figure things out afterwards, then things get a little messy.)

Mercurial has a special command to move stuff: hg mv
When you move your folders like this, it knows in the history that Foo/Source/Bar/SomeFile was previously Foo/Bar/SomeFile.
So when you look at the history of Foo/Source/Bar/SomeFile now, you also see the changes that were made when the file was still Foo/Bar/SomeFile.
Here's an example how to move the Bar1 folder into the Source folder and commit:
hg mv Bar1 Source
hg commit -m "moved to Source folder"

Drag the 2 Bar folders into the new Source folder and commit.

Related

Hg: How to move files (to subfolder) without losing history?

How to move files (to subfolder) without losing their history?
In my Mercurial repository (I mean the folder with the .hg in it) I have MyProject/ folder with all project files. Now I need to create src/ folder inside and move all files to it (from MyProject/ to MyProject/src/). How can I do it without losing all history?
Since you have a "tortoisehg" tag, I figured I'd explain the way I do this using the GUI.
Usually, I just rename/move files in my IDE, or from windows explorer, then when I go to commit, THG will show a bunch of (?) unknown files and (R) removed files. Just right click on any of the files and choose "Detect Renames...", then click the "Find Renames" button.
You might have to adjust the "Min Similarity" slider until you get all the files you want and only the files you want, but it's usually very straightforward.
hg mv
does do the right thing, but hg log does not list entries past the move unless you
give it the -f option. See this question for more info
Why 'hg mv' (mercurial) doesn't move a file's history by default?
After you do this, you likely want to add the -f option to hg log
to the hgrc file for the repo.
.hg/hgrc
[defaults]
log = -f
In Windows with Tortoise HG installed, there is a windows shell extension that handles this very nicely.
In Windows Explorer, simply right-click and drag the file(s) you wish to move into the destination folder. You are then presented with a pop-up that give you these choices:
HG Move versioned item(s) here
HG Copy versioned item(s) here
Use hg mv to move your files and then use hg log -f (follow) to see history including renames.

hg convert with filemap giving empty repository

I have got a new repository converted from SVN. I want to minimize this repository further by removing unintended files.
For that I am again converting the mercurial repository to a new one by using hg convert and the filemap parameter.
So my filemap looks like this:
include a
rename a .
The command I am using is:
hg convert --filemap fm.txt . ../new_repo
This ends after full conversion as I can see in the console output.
But if I now check the content of the directory new repo, I can see only .hg files in there.
I ran hg update -C within the directory whic gives me one more file .hgtags
Can anyone please suggest what has gone wrong?
This answer was spot on: you don't actually create an empty directory, but a directory with a hidden .hg directory. If you run
hg update
in your target directory, you will have your target directory with all its contents as expected.
In common, you done all correct (if directory a exist in source repo)
In my test for repository with directory lang, which I want to move into the root of new repo, I used filemap
include lang
rename lang .
identical to your filemap and got bare repository after converting (no files in Working Dir, only repository on .hg). Testing repository
hg log
changeset: 19:41e96453fa67
tag: tip
...
changeset: 0:ba52ea5c5c1f
showed me all related hisory
hg up
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
(without -C) brings all files into the Working Directory
SR>dir /B
.hg
UTF-8

Clone Mercurial repository into public_html

I want to clone my Mercurial repository into my /public_html folder on my web server. My Mercurial project looks like this...
- /ProjectName
- /public
- /application
- /config
- /library
What I want is to just get the contents of "ProjectName" into my /public_html folder. Unfortunately, cloning the repository includes "ProjectName" and all of the subfolders are in there.
Any idea how to accomplish this without a symbolic link?
Just to put it out there, you probably don't want a full clone in your public_html unless you really want every version that ever was out there on the web. There's nothing inherently wrong with that, but since you'll have a .hg in public_html people will even be able to clone your repository from it.
Instead consider using the hg archive command which exports all the files as they exist at a specific revision and places them wherever you want.
For example:
cd your_clone
hg archive --rev release /public_html
That takes the code pointed to by the release label (which could be a tag, bookmark, or branch head) and puts the files, but not a full-history clone, in /public_html.
I actually found an easy way to do this.
hg clone https://me#bitbucket.org/me/ProjectName "/home/website/public_html"
public_html has to be empty to clone the repository into it, so I moved everything out, cloned the repo, then moved the pre-existing files and folder back.
Here is a simple step that you can follow:
cd /public_html
hg init .
hg pull ../pathto/ProjectName/
This will pull all the files and folders under ProjectName in public_html without creating /public_html/ProjectName.
But it will still copy all the resources that are in the mercurial repository (Files and Folders) into your directory.

Mercurial Nested Repo Issue

I have accidentally created a repo in a sub directory of another repo
Since doing this the sub repo now contains a number of commits
I realised my mistake when I attempted an hg st on the original (parent?) repo and it complained of a file being inside a nested repo
What I would like to do is somehow move the sub repo history up into the parent then just delete the sub repo so I have just one repo
The dir structure is like this:
my original repo:
core/
my directories containing src code i'm trying to version control:
core/src/
core/test/
my accidental repo is in:
core/src/
e.g. its this one I want to push?/merge? up a level into the core/ repo, then just kill the core/src/ repo (by deleting the .hg dir)
I have read a few stack overflow discussions on this but they seem to be trying to solve more complicated sub repo scenarios. I'm hoping a straightforward (dare i say it simple) solution may exist?
I have not had much luck with the HG wiki on this either
Preserving history
Depending on the version you're using, you can use the Transplant or Graft extension to achieve your goal.
I've never done that and don't have time to test it before hand, but something like the following steps should work :
Move your actual core/src/ dir somewhere else, for example ~/temp.subrepo/
Remove the subrepo from the .hgsub file
Use the Convert extension to rename the files in the subrepo (see below for a quick example)
Transplant the changes : hg transplant -s ~/temp.subrepo.converted/ 0:tip
To convert the subrepo, you can use something like this :
$ echo include . > /tmp/myfilemap
$ echo rename . src/ >> /tmp/myfilemap
$ hg convert --filemap /tmp/myfilemap ~/temp.subrepo/ ~/temp.subrepo.converted/
Like I said, I'm not sure this will work out of the box, but it's at least a lead. If you have any problem, don't hesitate to ask.
History doesn't matter
Or maybe the simplest solution is just to remove the .hg directory in the subrepo, remove any mention of the subrepo in the .hgsub file of the main repo, and just add and commit the files :
hg add core/src
hg commit
You will lose all the history of the subrepo, but at least the solution is really simple.

Putting home directory under source control (hg)

For a while I had just my code under source control, but I decided it would be cool to put things like my stuff in my .vim folder among other things in a repo. (I'm obviously not going to store everything in my repo, just various config files, my src directory, and maybe a few other things as well)
I was able to set up a repo fine, then push it to my server where I can access it from my other computers, but I can't clone it to my other computers. When I try to clone it it fails because the home directory isn't empty. Is there a way to do what I want here?
Since the versioned files between my computers are the same, what I did was:
~$ hg clone ssh://myserver/hg/dotfiles mydotfiles
~$ mv mydotfiles/.hg .
~$ rm -rf mydotfiles
and that's it, now your home folder is under version control, but of course if your dot files are not identical between computers you will have to do something about it.
Since I only want to version some files and not everything under my home folder, I have this simple rule in ~/.hgignore
# This .hgignore is for the dotfiles repository only,
# the rest of my HG repositories use the file
# .hgignore_global as referenced by [ui]'s ignore setting.
syntax:glob
*
This way I don't get an ocean of files when I do hg status and only see those files that I have under version control that have been modified.
But since I want to see unversioned files when working within another hg repository, I have this in my ~/.hgrc file
[ui]
ignore=/home/gajon/.hgignore_global
And ~/.hgignore_global contains some filters for common transient files:
syntax: glob
*.pyc
*~
.*.swp
.svn*
*.svn*
*.fasl
syntax: regexp
^\.pc/
Suppose you have proj1 and proj2. proj1 is a mercurial repo you want to clone to proj2, but proj2 already has files in it.
Try this:
hg clone proj1 proj3
mv proj3/.hg proj2
rmdir proj3
cd proj2
hg update -C -r tip
In the other directories that already exist, you could hg init, hg add what you want, hg commit that, hg pull from the central repo, and deal with the resulting merge.