Cloning Mercurial projects from Codeplex for Git users

Recently wanted to get hold of Catel source and examples from Codeplex But as a Git user and not so familiar with Mercurial, looked for a simple way to clone across the code. For now I do not want to push back any changes (though that is possible, if you want to), I didn’t want to change from using  GitExtensions/Git Bash under Windows to say Tortoise Git or Tortoise Hg, having experienced a number of issues with these before.

(BTW Catel is a brilliant MVVM framework that leaves the competition for dead: see http://catel.catenalogic.com/index.html?gs_introduction.htm and http://catel.codeplex.com for more details.  If you are considering Caliburn.Micro, Cinch, MVVM light or killing yourself with Prism, take a look at Catel, see http://www.codeproject.com/Articles/178581/Catel-Part-0-of-n-Why-choose-Catel or http://catel.catenalogic.com/index.html?mvvm_framework_comparison_shee.htm )

Note: This below is assuming you have GitExtensions installed, and running a Windows 7×64 or 8 x64, a lot of the SO tips were not working for me. I’d tried a number of times to get hg-git going, only to find it failed in one place or another. In the end it was lack of compatibility of 64bit Python or 64bit Mercurial install. So although I have Windows 7/8 x64 OS, the main fix needed was to use 32bit versions of everything.

So, to be able to clone a Mercurial repository from say Codeplex, and then clone into Git.

Install Python, then Mercurial (once only)

1. Install Python 2.7 32bit (not 64bit, even if a 64bit OS)

2. Set an environment variable called PYTHONPATH to C:\Python27\Lib\site-packages

3. Prepend or append this the Python path this on to the windows path, C:\Python27;C:\Python27\scripts;

3a Install Easy_Install

go to https://pypi.python.org/pypi/setuptools#windows
get setuptools-0.6c11.win32-py2.7.exe
install it

4. Install Mercurial 32 bit (not 64bit, even if a 64bit OS)

Install HG-GIT (once only)

1. Install Dulwich (used by hg-git), open a new command window (to make use of the environment variables set above), type:

easy_install dulwich

note: if you get an error: unable to find vcvarsall.bat, then add this environment variable (if Visual Studio 2012 installed)

SET VS90COMNTOOLS=%VS110COMNTOOLS%

reopen dos cmd window and try again.

(thanks to : http://stackoverflow.com/questions/2817869/error-unable-to-find-vcvarsall-bat for the answer to this)

2. Install HG-GIT; in a command window type:

 easy_install hg-git

3. Configure Mercurial, (note for Windows user it is mercurial.ini and not ~/.hgrc) so edit the file

c:\users\username\mercurial.ini

in a text editor, add the following lines:

[ui] username = FirstName LastName <your.email@yourdomain.com.whatever>
editor = notepad++.exe
[extensions]
hgext.bookmarks =
dulwich = C:\Python27\Lib\site-packages\dulwich-0.8.7-py2.7-win32.egg\dulwich
hg-git = c:\python27\lib\site-packages\hg_git-0.4.0-py2.7.egg\hggit

note: you may need to update the version numbers/paths

To clone from a remote Mercurial repository to local Mercurial repository (each time)

open up a command prompt window with admin access

change directories to the root directory, inside which you want the Mercurial repo to go, say:

     cd \development\mercurial

now clone the repository, type:

    hg clone https://hg.codeplex.com/catel

Clone from a local Mercurial repository to local Git repository

Navigate inside the directory mercurial just created, named after the repository.  In this example it would be

c:\development\mercurial\catel\.hg

(1) edit the file hgrc using a text editor

add the following 2 lines to the end of the file, save and close.

[git]
intree = true

(2) in a command window,  inside the Mercurial repo (in this example, it would be in the directory c:\development\mercurial\catel ) type:

hg bookmark -r default master
hg gexport 

This second command creates a .git repo beside the .hg repo, it is a private repo ready to clone from using Git.

(3) Clone from the private repo to your working / public git repo into a local directory under which you would like the Git repo to be put, following the above example it would be:

cd \development\projects
git clone c:\development\mercurial\catel

now you will have a working local Git repository in this directory:

cd \development\projects\catel

Advertisements