Skip to content

Instantly share code, notes, and snippets.

@tternes
Last active August 29, 2015 14:00
Show Gist options
  • Save tternes/e3e9ddd18a1210ec5228 to your computer and use it in GitHub Desktop.
Save tternes/e3e9ddd18a1210ec5228 to your computer and use it in GitHub Desktop.
git-svn clone without the full repro
#!/bin/bash
########################################
# Quick and dirty script for cloning an svn branch with git without pulling the entire repo history
#
# Usage: git-svn-clone.sh <URL> <LOCAL_OUTPUT_PATH>
# e.g. git-svn-clone.sh http://myserver.com/svn/branches/feature-1.0 feature-1.0
#
########################################
URL=$1
LOCAL_OUTPUT_PATH=$2
########################################
# Fetch the revision from the svn log, stopping at the first commit in a branch
# This is obviously gross - clean up with some
########################################
# Output will be something like:
#------------------------------------------------------------------------
#r62344 | somedeveloper | 2014-04-07 15:36:45 -0500 (Mon, 07 Apr 2014)
#------------------------------------------------------------------------
#r62281 | somedeveloper | 2014-04-03 19:25:04 -0500 (Thu, 03 Apr 2014)
#------------------------------------------------------------------------
#r62280 | somedeveloper | 2014-04-03 19:23:44 -0500 (Thu, 03 Apr 2014)
#------------------------------------------------------------------------
# ^-- we want the revision from the second-to-last line
########################################
echo Determining first commit on branch at ${URL}
REVISION=`svn log --stop-on-copy -q ${URL} | tail -n 2 | head -n 1 | cut -d" " -f1`
########################################
# Create an empty git repo at the local checkout path
git svn init --prefix=origin $URL $LOCAL_OUTPUT_PATH
cd $LOCAL_OUTPUT_PATH
########################################
# fetch the svn repro from the first branch commit to latest
echo Fetching revision ${REVISION} through HEAD
git svn fetch -$REVISION:HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment