Skip to content

Instantly share code, notes, and snippets.

@loftux
Created January 24, 2013 15:23
Show Gist options
  • Save loftux/4622983 to your computer and use it in GitHub Desktop.
Save loftux/4622983 to your computer and use it in GitHub Desktop.
Script to convert a specific subversion path to git, ignoring other subversion paths and content. Not tested to handle merges, does not record commits with proper dates (historic dates in commit message). If you want all that there are better tools available.
#!/bin/bash
# Convert a subversion repository path to git
# Author: Peter Löfgren, Loftux AB
# The subversion path to export
URL="https://share-extras.googlecode.com/svn/trunk/Media Preview"
# First revision this path exists
STARTREV=2
svn co -r ${STARTREV} "${URL}" export
cd "$( dirname "$0" )/export"
if [ ! -f ".gitignore" ]; then
echo .svn >> .gitignore
fi
if [ ! -d ".git" ]; then
git init
git add .
git commit -m "Initial commit, export from ${URL}"
fi
localrev=$(( `svn info | grep Revision | awk '{print $2}'`+1 ))
remoterev=$((`svn info $( svn info | grep 'Root:' | awk -F': ' '{print $2}' ) | grep Revision | awk '{print $2}'`+1))
echo Updating from $localrev to $remoterev
while [ $localrev -lt $remoterev ]; do
echo `date "+%Y-%m-%d %H:%M"` Updating $localrev
svn update -q -r $localrev
loggmessage=`svn log -r $localrev`
git add .
git ls-files --deleted | xargs git rm
git commit -m "${loggmessage:73}"
let localrev=localrev+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment