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.

Revisions

  1. loftux created this gist Jan 24, 2013.
    36 changes: 36 additions & 0 deletions SvnPathToGit.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/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