#!/bin/sh # # git-clone-svn-based-repo.sh: # # clones a git-svn based repo including all SVN commits without pounding # the SVN server for hours (just a quick refresh taking seconds) # usage_exit () { echo "Usage: $0 [authors-file]" exit 1 } if [ $# -lt 3 ] then usage_exit fi if [ $# -gt 4 ] then usage_exit fi if ! git ls-remote "$1" > /dev/null 2>&1 then echo "No git repo found at: $1" usage_exit fi if [ -r "$2" ] then echo "File or directory already exists: $2" usage_exit fi if ! svn ls "$3" 2> /dev/null | grep -q trunk then echo "No SVN project found: $3" usage_exit fi if [ $# -eq 4 -a ! -f "$4" ] then usage_exit fi # create new bare git repo mkdir "$2" cd "$2" git init --bare .git # fetch everything from backup git remote add backup "$1" git fetch backup refs/remotes/*:refs/remotes/* git fetch backup refs/heads/*:refs/heads/* git fetch backup refs/tags/*:refs/tags/* # disable future fetching from backup # setup to push all remote refs to backup by default git config remote.backup.fetch do_not_fetch_from_backup git config remote.backup.push '+refs/remotes/*:refs/remotes/*' # initialize git repo to usable (non-bare) state git init # update SVN references git svn init -s "$3" # use an author translation file if given if [ $# -eq 4 ] then git config svn.authorsfile "$4" fi git svn fetch # update master to current SVN trunk git checkout master git svn rebase # update ignore properties from SVN git svn show-ignore >> .git/info/exclude