This is a nasty little python script that was hacked together to copy and convert your bitbucket mercurial repositories to git. It is very crude with little error checking (I only needed to run it once).
Backup your repos first. This app is not destructive, it does not delete mercurial repos, it renames them. That said you should have a local backup of your repos anyway.
Steps
- Downloads the mercurial repository.
- Creates a local git repo
- Converts the mercurial repository into the newly created local git repo.
- Renames each mercurial repository to zzz{repo name} HG
- Creates a new remote (bitbucket) repo with the original repo name
- Pushes the new git repo up to bitbucket
python convert.py
- This was tested on OSX. At the very least you will need an *nix system to execute the popen calls
- The mercurial python module (pip install mercurial)
- git
- hg
All other dependencies are are packaged with this script they include:
- A modified version of python-bitbucket https://bitbucket.org/jmoiron/python-bitbucket that allows write/create opperations.
- A copy of ht-fast-export http://repo.or.cz/w/fast-export.git
- Once the script has been run you should have your old hg repo renamed as
zzz{repo name} HG
. I put the zzz prefix so it would move to the bottom of your dashboard (and so I could id repos that have already been converted). - A new git repo with the name of the original
If you deploy from bitbucket (like I do) you will need to update your local code to point either the new git repo or the new url for the hg repo.
Not everything will be converted to your new git repo. You will loose issues, wiki pages followers etc.
- Delete the newly created bitbucket git repo from the web interface (if it was created).
- Rename the mercurial back to the original name by removing the zzz prefix and HG suffix.
It would be cool to do some command line arguments to only covert a subset of repos etc. I wanted to convert all my repos so I didn't take the time to do this.
It would also be cool to include a backup script to backup clone all your bitbucket repos locally. I have one that I use; perhaps I will clean it up and release it.