Migrating our subversion repository to github
May 9, 2012 Leave a comment
We recently moved our svn repository to git hosted at github. Now I’d like to share my experience doing that migration and explain the steps we took to do so. I pretty much followed the process described by John Goulah in his blogpost. So here are the concrete steps I took:
1. Download the entire subversion repository to the local machine for performance reasons.
2. Create an authors mapping file which looks something like this:
#svnuser = gituser <email> thomasb = thomascube <thomas@...>
3. To start, initialize the git repository with reference to the old svn repos:
$ git svn init file://<path-to-local-svn-repos> roundcube-git
4. cd into the roundcube-git folder and edit the .git/config file to configure what to migrate. I just added the following blocks:
[svn]
authorsfile = authors.txt
[svn-remote "svn"]
url = file://<path-to-local-svn-repos>
fetch = trunk/roundcubemail:refs/remotes/svn/trunk
branches = branches/{release-0.6,release-0.7,release-0.8}:refs/remotes/svn/*
tags = tags/roundcubemail/*:refs/remotes/svn/tags/*
Don’t forget to place the authors.txt file into the destination folder!
5. Now we can start importing the subversion data by executing
$ git svn fetch
Depending on the size of your repository this will take a while to run. Grab yourself a coffee or two.
6. There are a few more tasks to run in order to finish this off. Download the scripts from the git-svn-abandon repository and put them somewhere in your $PATH. Then run
$ git-svn-abandon-fix-refs
7. Now we also want to create a table mapping svn revisions to git commits. This can be used later on to update references to revisions in Trac comments for example. The scripts used to do that can be downloaded from the TRAC-SVN-to-GIT-migration project.
$ git-svn-create-lookup-table.sh > rev-lookuptable.txt
8. After creating the mapping table, we can now remove the comments referring to the old svn revisions from every git commit messages. This is done with
$ git-svn-abandon-cleanup
Done. The git repository is now complete. For Roundcube, we’re using a public github repository so what’s left is to push all the data to that:
$ git remote add origin git@github.com:roundcube/roundcubemail.git $ git push --all $ git push --tags
The next challenge is to update our Trac platform to place nice with the github repository.
9. Showing a git repository as source in Trac is pretty easy. Clone the repository somewhere on the machine where trac runs and install the GitPlugin for Trac. Just follow the instructions on the referred wiki page. In addition to that, the github-trac plugins helps to keep the Trac clone updated when new changes are pushed to the remote github repository.
10. Finally, we wanted all references to SVN revisions in tickets and comments to point to the according commits in our new github repository. And we therefore created the mapping table in step 7. But it turned out that the revision mapping table created by git-svn-create-lookup-table.sh wasn’t correct. None of the listed git commits finally existed in the git repository. Maybe the git-svn-abandon-cleanup changed them. So I was forced to build a new one in order to update all references. I achieved that by comparing the logs from both the SVN and GIT repository with this quickly hacked PHP script.
svn log file://<path-to-local-svn-repos> > svn.log git log > git.log php git-svn-create-rev-map.php svn.log git.log > rev-lookuptable.txt
Now we could start the (slightly modified) convertTracTickets.php script from the TRAC-SVN-to-GIT-migration tools and change all references in our Trac tickets. But don’t forget to backup your database before that step.