Skip to content

Instantly share code, notes, and snippets.

@rage-shadowman
Last active December 22, 2015 12:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rage-shadowman/6471961 to your computer and use it in GitHub Desktop.
Save rage-shadowman/6471961 to your computer and use it in GitHub Desktop.
Script to clone a git-svn backup repo. To create the backup repo, see: https://gist.github.com/rage-shadowman/6472005
#!/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 <git-repo> <dest-directory> <svn-project> [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment