Wednesday, August 4, 2010

Script to get latest revision from svn as a git repository

Here is a script that I use to fetch the latest revision of a svn project. The trick lies in finding that revision number. It isn't the Revision of the repository but the Last Changed Rev. The rest is straightforward git svn.

#!/bin/sh

SVN_URL=$1
GIT_DIR=$2
REV=`svn info $SVN_URL | awk -F': ' '/Last Changed Rev/ { print $2 }'`

mkdir -p $GIT_DIR
cd $GIT_DIR
git svn init --stdlayout $SVN_URL
git svn fetch -r $REV:HEAD