#!/bin/sh ################################################################################ # # This shell script will convert a project inside a Subversion # repository that is managed by the SVA/SC utility into a Git # repository. # # You will need to have the git-svn tool installed before you run this # script. I also highly recommend that you use a local Subversion # repository, instead of a remote one. # ################################################################################ args=`getopt A:t:b: $*`; e=$?; set -- $args options="--no-metadata" tags_subdir="rel" branches_subdir="exp" if [ $e != 0 ]; then echo "Usage: [options] svn-url project-name" echo " -A authors-file Resolve commit authors, see git-svn(1)" echo " -t tags-subdir The tags subdir to import (default: $tags_subdir)" echo " -b branches-subdir The branches subdir to import (default: $branches_subdir)" exit 1 fi while [ $# -ne 0 ]; do case "$1" in -A) options="-A $2 $options"; shift; shift;; -t) tags_subdir=$2; shift; shift;; -b) branches_subdir=$2; shift; shift;; --) shift; break;; esac done if [ $# -ne 2 ]; then echo "missing project name, or more than one project name given" exit 1 fi # capture the URL and project name svnurl=$1 project=$2 # if the output directory exists, we have a problem if [ -r $project.git ]; then echo "error: output directory exists: $project.git" exit 1 fi # make the URL a file:// if it's a local dir if [ -d $svnurl ]; then svnurl=file://`pwd`/$svnurl fi # initial clone, but too shallow echo "converting from svn to git" git svn clone \ --quiet \ --trunk=trunk \ --tags=tags/$tags_subdir \ --branches=branches/$branches_subdir \ $options $svnurl/$project $project.git || exit 1 # work inside the repo cd $project.git || exit 1 # transform remote branches to local branches for branch in `git branch -r|egrep -v '^ *tags'`; do echo "resolving remote branch: $branch" git checkout $branch git checkout -b $branch done # transform tags to real tags for tag in `git branch -r|egrep '^ *tags'|egrep -v @`; do tag_name=`echo $tag|sed 's|tags/||'` git checkout $tag git tag -a -m "Tagging v$tag_name" v$tag_name done # rename the truck branch to master, since that's what it really is git branch -M trunk master git checkout master git repack -a -d || exit 1 git prune-packed || exit 1 # create a bare clone, dropping the lame remote branches cd .. || exit 1 git clone --bare $project.git $project.git.bare || exit 1 rm -rf $project.git || exit 1 mv $project.git.bare $project.git || exit 1 # done echo "Bare repository in $project.git"