git-svn and ReviewBoard

The cat in the tree is looking at me
This cat is ON MY BRANCH! Image by pinto_2003

The company I am currently at haven’t yet made the jump to git. It’s understandable; there are a number of large SVN repositories and only one (or two) of the developers know how to use git. So, it doesn’t make sense right now. I’m trying to get git-svn working accurately in my workflow before I try and explain the awesome-ness of git for my colleagues. I’ve run into two problems, one is svn:properties and how git doesn’t support them (except ignore) which is a pain, because it means that if I want to adhere to AWin coding standards and not have PHPUnderControl moan at me, I need to have svn:keywords and svn:EOL properties for each file. The hacky fix is to run a seperate SVN directory on my box, which I add files to, add the properties, then rebase them into git. It’s a pain.

The other problem is ReviewBoard. Well, it’s not such a massive problem now ReviewBoard has ‘post-review’ which allows you to send reviews to RB via the command line. But, sometimes, you just want a standard diff file which you can upload to RB, git diff doesn’t create files that ReviewBoard understands, which is where a little bit of bash scripting comes into play.

I found this: My (work) Git Workflow (You should read it all, it goes into managing branches and stuff, it’s a useful read if you’re just starting out with git-svn, thanks Seth!). Which almost worked. Except, for some reason, it was pumping out massive diff files that git diff wasn’t. So, I had a little bit of a fiddle and found that it uses the git config option svn-remote. Which, for my repo is set to the trunk. Which doesn’t make any sense if I want to run an diff on the branch I’m working on, so, I modified it:

# git-svn-diff originally by (
# modified by
# Generate an SVN-compatible diff against the tip of the tracking branch

# Get the tracking branch (if we're on a branch)
TRACKING_BRANCH=`git svn info | grep URL | sed -e 's/.*\/branches\///'`

# If the tracking branch has 'URL' at the beginning, then the sed wasn't successful and
# we'll fall back to the svn-remote config option
if [[ "$TRACKING_BRANCH" =~ URL.* ]]
        TRACKING_BRANCH=`git config --get svn-remote.svn.fetch | sed -e 's/.*:refs\/remotes\///'`

# Get the highest revision number
REV=`git svn find-rev $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH)`

# Then do the diff from the highest revition on the current branch
git diff --no-prefix $(git rev-list --date-order --max-count=1 $TRACKING_BRANCH) $* |
sed -e "s/^+++ .*/&     (working copy)/" -e "s/^--- .*/&        (revision $REV)/" \
-e "s/^diff --git [^[:space:]]*/Index:/" \
-e "s/^index.*/===================================================================/"

You can also see it here:

So far, it seems to be working for me. But it’s only until I get the department using git right, RIGHT?


2 thoughts on “git-svn and ReviewBoard

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s