Git mirror of remote SVN repository

Some of you may know that we are already working on the next version of our tool, SubGit 2.0. This new version enables bi-directional synchronization of Git and SVN repositories located on different hosts.

You’ve heard it right, it is remote bi-directional Git mirror of an arbitrary SVN repository.

Many users demand that functionality. The reason is obvious: some developers have no local access to SVN repositories, so they cannot use SubGit. Today I will show you a little trick with the current version, SubGit 1.0; it enables writable Git mirror of remote SVN repository with minimal admin access.

So, you have a Subversion repository somewhere at http://company.com/svn/repos/, let’s build Git mirror out of that:

1. Create empty Subversion repository locally:

$ svnadmin create repos

2. Fetch remote repository into the local one with rdump-load cycle (see topic on replication with svnrdump in Subversion Book):

$ svnrdump dump http://company.com/repos/repos | svnadmin load repos

3. Install SubGit into the local repository to add Git part (see SubGit Book for more details):

$ subgit configure repos

Adjust the configuration accordingly to your needs: specify branches and tags layout, add authors information, etc. Finally, create a translated Git repository by installing SubGit:

$ subgit install repos

In the remaining part we will use svnsync to enable synchronization of created Git repository with remote SVN repository.

4. Make sure pre-revprop-change hook is enabled in remote repository. This is needed to make svnsync work. Unfortunately, this needs admin access to repository but often times this hook is already enabled for repository.

$ nano /path/to/remote/repos/hooks/pre-revprop-change

#!/bin/sh
exit 0

Do not forget to make hook script executable:

$ chmod +x /path/to/remote/repos/hooks/pre-revprop-change

5. Synchronize the local repository with the original one using svnsync (see topic on replication with svnsync in Subversion Book):

$ svnsync initialize http://company.com/svn/repos file://path/to/repos
$ svnsync synchronize http://company.com/svn/repos

6. Schedule svnsync runs to enable replication of the new revisions translated from Git by SubGit:

$ crontab -e

# m h dom mon dow command
3 * * * * svnsync synchronize http://company.com/svn/repos

If you’ve followed the steps above you have created Git mirror of remote Subversion repository. Be aware of certain drawbacks this approach implies:

  • Due to limitations of svnsync remote SVN repository must be read-only. That means no one should ever commit directly to this repository; committers should use Git mirror to publish all the changes.
  • Admin should enable pre-revprop-change hook to make svnsync work. Hopefully, the hook is already enabled for your repository as some admins do that beforehand.
  • The described approach does not work in case of a project hosted in SVN repository along with other projects: any modification committed into some other project inside the same Subversion repository inevitably breaks synchronization.

Fortunately, SubGit 2.0 doesn’t have any of these problems. Stay tuned!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>