Skip to content

Instantly share code, notes, and snippets.

@schakko
Created June 5, 2012 10:13
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 schakko/2874178 to your computer and use it in GitHub Desktop.
Save schakko/2874178 to your computer and use it in GitHub Desktop.
Convert multiple SVN repositories with help of svn2git
#!/bin/bash
PATH_svn2git=~/svn2git/svn-all-fast-export
# path to account mapping. Must be in format "$svn-username $git-fullname <$git-email>"
PATH_account_map=~/svn2git/account-map
# layout template
PATH_template=~svn2git/standardlayout.rules
# repplace string #REPOSITORY# with current repository element
TEMPLATE_REPLACEMENT='\#REPOSITORY\#'
DIR=$1
if [ ! $1 ]; then
echo "Missing directory parameter"
exit
fi
if [ ! -d $DIR ]; then
echo "Parent directory $DIR does not exists"
exit
fi
for subdir in $DIR*; do
if [ -d $subdir ]; then
BASENAME=`basename $subdir`
TARGET_TEMPLATE=$DIR/$BASENAME.layout
echo "Trying to convert SVN repository $BASENAME"
echo " Copying template $PATH_template to $TARGET_TEMPLATE"
rm $TARGET_TEMPLATE
cat $PATH_template | sed -e "s/$TEMPLATE_REPLACEMENT/$BASENAME/" >> $TARGET_TEMPLATE
echo " Converting SVN repository $BASENAME"
$PATH_svn2git --identity-map $PATH_account_map --rules $TARGET_TEMPLATE $subdir
echo "done."
fi
done
#
# Declare the repositories we know about:
#
create repository #REPOSITORY#.git
end repository
#
# Declare the rules
# Note: rules must end in a slash
#
match /trunk/
repository #REPOSITORY#.git
branch master
end match
match /branches/([^/]+)/
repository #REPOSITORY#.git
branch \1
end match
# Important:
# Subversion doesn't understand the Git concept of tags
# In Subversion, tags are really branches
#
# Only a post-processing (i.e., after converting to Git) of the tag
# branches can we be sure that a tag wasn't moved or changed from the
# branch it was copied from
#
# This rule will create tags that don't exist in any of the
# branches. It's not what you want.
# See the merged-branches-tags.rules file
match /tags/([^/]+)/
repository #REPOSITORY#.git
branch refs/tags/\1
end match
# Unmatched files or directories will be copied to master branch (including tag directory)
match /
repository #REPOSITORY#.git
branch master
end match
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment