Gitifyhg is a git client for pushing to and pulling from Mercurial repositories. I described the first implementation, which used hg-git internally, last month. However, I found that it didn’t work as well in practice as my initial tests had indicated, and I morosely reverted to using hg directly.
While researching ways to improve the app, I stumbled across git-remote-hg by Felipe Contreras. It claimed to be a cure-all to the git-hg bridging problem that “just worked”. So I downloaded and tried it, but it didn’t live up to the author’s hype. While it could handle basic cloning, pushing to and pulling from the default branch, it failed for me when working with named upstream branches, something I have to do regularly in my day job. I submitted several issues and pull requests, most of which were ignored. The more deeply involved I became with the code, the more I felt a complete rewrite was in order.
I had some free time during the holiday season, and started my version of a git remote as an exercise, with no intent to create anything useful. To my surprise, something useful emerged. In fact, I believe gitifyhg is the most robust and functional git to hg client currently available. More importantly, it is eminently hackable code: well tested and fairly well documented. I hope this will make it easy to contribute to, and that my inbox will soon be full of pull requests.
This is the real deal. The best part is that you don’t have to learn any new commands. It’s just basic git with mercurial as a remote. The only command that has changed from normal git usage is
pip install gitifyhg git clone gitifyhg::http://selenic.com/hg cd hg
gitifyhg:: before the mercurial url, you can git clone most mercurial repositories. If you can’t, it’s a bug. Other complex repositories I have successfully cloned include py.test and pypy.
You can easily use gitifyhg in the fashion of git-svn. All named branches are available as remote branches.
default maps to
master. Other branches map to
If you want to commit to the master branch, I suggest a workflow like this:
git clone gitifyhg::<any mercurial url> cd repo_name git checkout -b working # make a local branch so master stays prestine # hack and commit, hack and commit git checkout master git pull # Any new commits that other people have added to upstream mercurial are now on master git rebase master working # rebase the working branch onto the end of master git checkout master git push
Working on a named mercurial branch, for example
feature1, is easy:
git checkout --track origin/branches/feature1 git checkout -b working # make a local branch so feature1 stays prestine for easy pulling and rebasing # hack and commit, hack and commit git checkout branches/feature1 git pull # New commits from upstream on the feature1 branch git rebase branches/feature1 working # rebase the working branch onto the end of feature1 git checkout master git push #push your changes back to the upstream feature1 branch
It is even possible to create new named branches (assuming
my_new_branch doesn’t exist yet in Mercurial):
git checkout -b "branches/my_new_branch" # hack add commit git push --set_upstream origin branches/my_new_branch
These basic workflows have been working flawlessly for me all week. In contrast to my previous attempts to use git to hg bridges, I have found it easier to use gitifyhg than to work in the mercurial commands that I have become expert with, but not used to, in the past year.
Gitify hg is not yet perfect. There are a few issues that still need to be ironed out. There are failing tests for most of these in the gitifyhg test suite if you would like to contribute with some low-hanging fruit:
- Anonymous branches are dropped when cloned. Only the tip of a named branch is kept.
- Tags can be cloned and pulled, but not pushed.
- Bookmarks can be cloned and pushed, but not pulled reliably. I suspect this is related to the anonymous branch issue.
So give it a shot. Gitifyhg is just one easy_install gitifyhg away.