Monthly Archives: December 2011

Convert and mirror a Bazaar repository on Google Code and GitHub

An open source project should be as open as possible, for that reason I decided to make the source code of bashoneliners.com available in more than one VCS, for example in Subversion and Git in addition to Bazaar which remains the “master” branch.

Bazaar to Subversion

Thanks to the bzr-svn plugin which comes bundled with the latest versions of Bazaar this is really easy and straightforward.

Initial setup: import full history from Bazaar to Google Code

bzr co /path/to/bzr/repo /path/to/svn/pusher
cd /path/to/svn/pusher
bzr push https://PROJECT.googlecode.com/svn/trunk

Mirroring periodically

cd /path/to/svn/pusher
bzr up && bzr push

Occasionally, especially if you have a lot of changes to push at once, the connection can get interrupted, or even bzr could crash. No worries, just repeat the “bzr push”.

As usual with mirrors, if you ever commit to the Google Code repository with anything else other than the above script, the mirroring will stop working because your branches have diverged. If you ever do that by mistake it’s not the end of the world, you can reset the repository on Google Code and rebuild it again.

Bazaar to Git

There is a nice plugin for this too, but since I could not get it working easily on my Mac, I chose an alternative path that’s less pretty but very easy to get going, by using the Subversion mirror on Google Code as a stepping stone from Bazaar to Git.

Initial setup: import full history from Google Code to GitHub

git svn clone https://PROJECT.googlecode.com/svn/trunk /path/to/git/pusher
cd /path/to/git/pusher
git remote add origin git@github.com:repo-url
git push origin master

Mirroring periodically

cd /path/to/git/pusher
git svn rebase && git push origin master

As usual with mirrors, if you ever commit to the GitHub repository with anything else other than the above script, the mirroring will stop working because your branches have diverged. If you ever do that by mistake it’s not the end of the world, since with Git you can rewrite history 😉

How to handle git svn rebase with conflicts

I’m still new to git and it was not very clear at first how to handle the case when you encounter conflicts during a git svn rebase.  Some notes to help next time around:

  • At any time, you can do git rebase --abort to undo the rebase and be back to your untouched git branch.
  • There is NO:
    • git svn rebase --abort
    • git svn rebase --continue
    • git svn rebase --skip
  • There are only:
    • git rebase --abort
    • git rebase --continue
    • git rebase --info
  • Depending on the conflict you may have to do various things to resolve, such as:
    • Edit files and sort out the lines marked as conflicted.
    • Do git add path/to/file
    • Do git rm path/to/file
  • After resolving a conflict, do: git rebase --continue
    • At this step if git complains that nothing has changed, then you have to do: git rebase --skip
  • When resolving a conflict, if you know for a fact that the file in your master branch is the correct one, you can resolve the conflict with git checkout master path/to/file
  • During my rebase, somebody committed to subversion, which cause my next git rebase --continue to fail. I don’t know what is the best solution here, I did git rebase --abort and started over.