Idea to mirror an svn to git

2.2k views Asked by At

Today, at my work we host our source code at a public svn repository that we don't admin access. Now, we want to use git (github) to host our source. For some internal reasons, the svn repository we use must mirror the git one.

Apparently, Subgit is the best tool to do this work, because the svn <-> git is very smooth and stress-free (what it really seems to be according to my tests). So, the layout I've been thing is this one:

svn-repo <- subgit-repo <- github <-> local git-repo from each developer.

The svn-repo will be read-only, i.e., it'll be only possible to commit using git.

Reading the Subgit blog I saw this post. In this post, the svnsync is used to synchronize the subgit-repo with the svn-repo, but the synchronization is one-way only, from svn-repo to subgit-repo :(

So, I've discovered svnadmin dump and load and I can use them to keep svn-repo synchronized with the subgit-repo. For example:

svnadmin dump --incremental subgit-repo | svnadmin load svn-repo

My question is: Is it a good idea to use svnadmin dump and load to keep my repositories synchronized?

Thanks!

1

There are 1 answers

5
vadishev On BEST ANSWER

Let's split the problem as follows:

  • Remote synchronization of Subversion repositories;
  • Synchronization of Git repositories, when one of them is hosted on GitHub.

Remote synchronization of Subversion repositories.

  1. Using svnsync.

    So, I've discovered svnadmin dump and load and I can use them to keep svn-repo synchronized with the subgit-repo.

    svnadmin dump --incremental subgit-repo | svnadmin load svn-repo

    Unfortunately you cannot run svnadmin load svn-repo unless you have admin access to svn-repo. But you can try to use svnsync instead:

    $ svnsync init svn-repo subgit-svn-repo
    $ svnsync sync svn-repo
    

    This way you sync changes from subgit-svn-repo to svn-repo remotely. Please notice that in your question you've pointed out the way to sync from svn-repo to subgit-svn-repo, but in my example I've shown this works in opposite direction as well.

    There's one issue with that approach though: there should be a pre-revprop-change hook in svn-repo. That means you still have to access svn-repo locally to enable the hook. Fortunately, that's a common case when administrators enable such hooks. Hope that holds for you, too.

    You may find the detailed HOW-TO in this blog post.

  2. Using SubGit 2.0.

    Right now we have a working prototype of SubGit 2.0 that enables read-write mirror of Subversion and Git repositories located on different hosts. One has to have admin access to Git repository only, so no need to modify Subversion repository anyhow.

    Currently it works like this:

    $ git init --bare git-repo
    $ subgit configure --svn-url svn-repo git-repo
    $ subgit install git-repo
    

    At this moment SubGit installs pre-receive and post-receive hooks into git-repo that automatically synchronize incoming changes with remote svn-repo.

    We're very close to publishing the very first EAP build with this functionality. And we encourage you to test the build as soon as it is ready. Until that moment there's only svnsync option, as far as I know.

Git synchronization with GitHub

From your question it's still no clear how are you going to synchronize changes of subgit-git-repo with github-repo.

I'd like to notice that one has to push changes into subgit-git-repo in order to synchronize them with subgit-svn-repo.

Basically your team may work with github repository only, and someone will manually push all the changes to SubGit-controlled Git repository:

$ git remote add github github-repo
$ git remote add subgit subgit-git-repo
$ git pull github
$ git push subgit

Or one can setup a cron job to periodically push changes to SubGit.