2

I want to move from Google Code and Mercurial to Git and GitHub while keeping all branches and version history.

So far it seems like the Hg-Git mercurial plugin (http://hg-git.github.com/) is my only option. I tried to follow the install instructions but am in a little over my head. Here's where I am:

[extensions]
hgext.bookmarks =
hggit = 

Now when I run:

C:\Python27\Scripts>easy_install.exe hg-git

I get the following:

Searching for hg-git
Best match: hg-git 0.3.3
Processing hg_git-0.3.3-py2.7.egg
hg-git 0.3.3 is already the active version in easy-install.pth

Using c:\python27\lib\site-packages\hg_git-0.3.3-py2.7.egg
Processing dependencies for hg-git
Searching for dulwich>=0.8.0
Reading http://pypi.python.org/simple/dulwich/
Reading http://samba.org/~jelmer/dulwich
Reading http://launchpad.net/dulwich
Best match: dulwich 0.8.5
Downloading http://samba.org/~jelmer/dulwich/dulwich-0.8.5.tar.gz
Processing dulwich-0.8.5.tar.gz
Running dulwich-0.8.5\setup.py -q bdist_egg --dist-dir c:\users\lee\appdata\local\temp\easy_install-3qgeev\dulwich-0.8.5\egg-dist-tmp-ciyt_4

And then a bunch of errors that look like this:

Traceback (most recent call last):
  File "C:\Python27\Scripts\easy_install-script.py", line 8, in <module>
    load_entry_point('setuptools==0.6c11', 'console_scripts', 'easy_install')()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1712, in main
    with_ei_usage(lambda:
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1700, in with_ei_usage
    return f()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 1716, in <lambda>
    distclass=DistributionWithoutHelpCommands, **kw
  File "C:\Python27\lib\distutils\core.py", line 152, in setup
    dist.run_commands()
  File "C:\Python27\lib\distutils\dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "C:\Python27\lib\distutils\dist.py", line 972, in run_command
    cmd_obj.run()
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 211, in run
    self.easy_install(spec, not self.no_deps)
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 446, in easy_install
    return self.install_item(spec, dist.location, tmpdir, deps)
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 481, in install_item
    self.process_distribution(spec, dists[0], deps, "Using")
  File "C:\Python27\lib\site-packages\setuptools\command\easy_install.py", line 519, in process_distribution
    [requirement], self.local_index, self.easy_install
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 563, in resolve
    dist = best[req.key] = env.best_match(req, self, installer)
  File "C:\Python27\lib\site-packages\pkg_resources.py", line 799, in best_match
    return self.obtain(req, installer) # try and download/install

Not sure what to try next. I also tried following tips from Cloning github repo with hggit but I'm missing something obvious. Any help would be greatly appreciated.

Community
  • 1
  • 1
Lee Richardson
  • 8,331
  • 6
  • 42
  • 65
  • 1
    Have you had a look at: [Converting a Mercurial (hg) repository to Git on Windows (7)](http://stackoverflow.com/questions/3267232/converting-a-mercurial-hg-repository-to-git-on-windows-7)? – Pedro Romano Sep 23 '12 at 20:23
  • 1
    I remember I used Tailor (http://progetti.metapensiero.it/tailor) for some repository conversions. – liori Sep 23 '12 at 20:29

2 Answers2

2

Just draft and some notes&thoughts:

  • In order to use TortoiseHG (on Windows, XP SP3 if it matter) Python is not mandatory - I work with THG without Python/setuptools/pip
  • TortoiseHG (32bit or 64bit) from Bitbucket are self-sufficient Mercurial in Windows-world
  • I added hg-git extension to my TortoiseHG by hand

\TortoiseHg\plugins>dir /B

hg-git

...

  • added hg-git extension to global mercurial.ini (Documents and Settings\Badger\mercurial.ini)

[extensions]

...

hggit = c:\Program Files_Tools\TortoiseHg\plugins\hg-git\hggit

...

  • bookmarks extension, as default extension, bundled with THG, was enabled in GUI some versions ago and can be found in mercurial.ini now as bookmarks = without corresponding checkbox in Settings-Extensions

  • With functional hg-git in TortoiseHG (clone, pull, push without errors for some Git-repo) you can try to convert external Mercurial repo to external Git repo

    • clone CG Mercurial repo to local (Mercurial) repo
    • create new empty Git repo on Github (verify authentification and other possible issues)
    • add second remote repo (GUI - "Synchonize" tab, by hand - new string in [paths] section in repo's .hg\hgrc), for me only git+ssh://git@github.com/username/reponame.git URL (with key-based authentification over PageAnt) is transparent solution
    • push local repo to github
    • Have Fun

Screenshot is just example of my active Git repo on GitHub and attempt to illustrate my words by a live source

Fiver Repo

Lazy Badger
  • 94,711
  • 9
  • 78
  • 110
  • Thanks @Badger for the details. First, by 'hgsubversion' in mercurial.ini, I assume you mean 'hggit'. Now I'm a little further along. When I type "% hg help hggit" in THG I get "hggit extension - no help text available". So I'm assuming the extension is good. But when I try to clone from github I get "No module named gitrepo". Any ideas? – Lee Richardson Sep 24 '12 at 03:20
  • 1
    @LeeRichardson - 1. yes, hgsubversion was my typo - I removed wrong line from copy&paste chunk 2. hggit **very basic** help can be reached by (surprise!!!) `hg help git` 3. Before github game (and not clone, I always use *only pull|push* pair), check hg-git work on some another repo – Lazy Badger Sep 24 '12 at 07:49
  • @Badger Been working on this for days with no luck. I can now clone and pull just fine (an out of date THG was causing problems). The push isn't working though. When I try to push to github ('hg push git+ssh://git@github.com/lprichar/SirenOfShame.git') I get "abort: The handle is invalid". I get the same when pushing to a local git repo. Do I need to include add dulwich to THG somehow? Do I need to configure TortoiseHg to use TortoisePlink.exe for ssh? Thank you so much for your help. – Lee Richardson Sep 27 '12 at 04:19
  • 1
    @LeeRichardson - 1. THG **have** dulwich in core 2. `[ui] ssh = "C:\Program Files\TortoiseHg\TortoisePlink.exe"` in mercurial.ini 3. Did you add and verify your public key to GitHub profile? 4. Try to push with `--debug --traceback` options 5. I don't know, why I haven't problems with my repo - all *just work as expected* – Lazy Badger Sep 27 '12 at 16:39
  • 1
    @LeeRichardson - I used http://jamesmckay.net/2010/06/tortoisehg-as-a-github-client-on-windows/ as quick-start guide – Lazy Badger Sep 27 '12 at 16:45
  • Thanks for all your help @Badger. I never got past "The handle is invalid" error in THG, but with all your tips I eventually got it working from an msysgit command prompt. Wow, what a pain this was. Thanks again for your help! – Lee Richardson Sep 28 '12 at 17:04
1

I also struggled with hg-git. I come up with a weird solution.

I imported hg repo with https://import.github.com/new It is not weird and must be what you look for.


The weird and bonus section is below:

  • I created a hg mirror repo on http://bitbucket.org
  • I created a local hg repository within git repository.
  • I added .hg/ to my .gitignore
  • Add .hg/ and .git/ to your .gitignore file .git/ .hg/
  • Enter the .hg directory in local repo and symlink your .gitignore file as .hgignore with

    $ ln -s ../.gitignore .hgignore

  • Now any changes made to your .gitignore are considered also by hg

    $ git add .gitignore -am 'gitignore'

    $ hg add .gitignore -am 'Do not forget to symlink .gitignore as .hgignore in .hg/ folder'

    $ hg push default

    $ git push origin master

Conclusion: While it looks inefficient, it takes advantages of github while not losing hg repo and database and gives opportunity to use both git and hg

guneysus
  • 6,203
  • 2
  • 45
  • 47
  • Obviously the hg and git repo are not going to exactly be in sync, lest you be really deliberate and sync atomic clocks across terminals. Still, I wish developers made some attempt at allowing multiple DVCS methodologies, maybe each method could be a (blog timeline) different perspective of the repository root, spoken in multiple languages. The HG version commit log could mention the Git version is keeping a different timeline and vice versa, keeping each power in check. – prosody-Gabe Vereable Context Jul 08 '20 at 00:49