There are many reasons why git-svn integration is interesting, and most of them are sociological. Here are some situations where git-svn integration can be useful:
- You work at a place that has standardized on SVN, but want to use git as your personal “svn client”
- Your company’s svn servers have horrid performance, and you want to continue to be productive when they’re not
- You want a fast and powerful web view of your svn repo (and what’s centrally provided isn’t cutting it).
- You are considering transitioning to a DVCS but you (or maybe those you work with?) are not willing to jump in without trying it on.
Git’s svn integration supports all of these uses quite naturally. This series of articles shall drop code which touches on these usages, but the real goal here is to explore a harmonious bi-directional svn<–>git arrangement, one where novel commits may occur on both sides of the boundary without b0rking repos or pissing off susan.
a kick-ass svn client
@mojodna has written up his work flow, and I find that to be a great exploration into some of the issues around using git as a svn client.
the read-only mirror
Here’s the purely hypothetical scenario: you’ve got this big ol' svn repo maintained by some fabulous folks. For whatever reason, those fabulous folks have provided you with a less-than-fabulous web view into your repository. You want to create an automatically updated git mirror of your SVN repository. You heavily dig on the simple, clean, and fast feel of cgit. This is uni-directional, but we’re just getting our feet wet.
Onward…
- pick the box that’s pulling the source and servin the pages
- setup limited passphraseless access for a headless user on them machines (an excercise for the reader, thas' u)
- git svn clone -s (as the appropriate user)
Now we’ve got two issues, first is that periodic bit, and second is
that git svn clone
will not create any local refs to
mirror remote branches. git branch -r
will list em, but
how might we go about turning svn branches named ‘tags/7.8.10’ into
real git tags, and likewise, remote svn branches into local
branches?
the periodic part
this part’s simple, use your friend cron
and plunk some git svn fetch && git svn rebase
into periodic execution.
the “ref” mirroring part
Here’s a little script I wrote, I called it git-svn-mirror-refs:
#!/usr/bin/env bash for r in `git branch -r | grep -v trunk`; do istag=x$(echo $r | egrep -v '^tags') if [ "$istag" == "x" ] ; then tn=$(echo $r | sed -e 's/^tags\///') git tag -f $tn refs/remotes/tags/$tn else git branch --track -f $r refs/remotes/$r fi done
mirroring redux
What did we gain? A fast and simple website where folks can browse the source of your project, pull tarballs of any arbitrary ref or commit, and view changes online. This is probably not huge for you… You’re probably not sold yet. Well, come back for part II. And in the mean time, don’t forget to provide your users with ergonomic urls:
Options +FollowSymLinks RewriteEngine On RewriteRule ^[0-9a-f]+$ /index.cgi/platform/commit/?id=$0 RewriteRule ^svn/([0-9a-f]+)$ /index.cgi/platform.svn/commit/?id=$1
next time…
… we’ll take a look at taking changes made in git and getting them into svn, and the opposite…
—ll