Created
June 7, 2012 22:26
-
-
Save fstrube/2892072 to your computer and use it in GitHub Desktop.
Convert Subversion repositories to Git
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
## -- Usage -- ## | |
# | |
# svn-to-git <svn_repository_url> | |
# | |
# svn_repository_url e.g. svn+ssh://svn.example.com/projects/hello_world | |
# | |
SVN=$1 | |
TMP=/tmp | |
[ -z "$SVN" ] && echo 'Missing svn repository' >&2 && exit 1 | |
# Transform authors | |
svn log -q "$SVN" | \ | |
awk -F '|' '/^r/ { | |
sub("^ ", "", $2); | |
sub(" $", "", $2); | |
if ( $2 == "franklin" || $2 == "Franklin" ) { | |
print $2" = Franklin Strube <[email protected]>"; | |
} else if ( $2 == "tstuck" ) { | |
print $2" = Tony Stuck <[email protected]>"; | |
} else if ( $2 == "astroh" ) { | |
print $2" = Alexandra Stroh <[email protected]>"; | |
} else { | |
print $2" = "$2" <"$2">"; | |
} | |
}' | sort -u > $TMP/authors-transform.txt | |
[ $(cat $TMP/authors-transform.txt | wc -l | tr -d ' ' | cut -c1) -eq 0 ] && exit 1 | |
vi $TMP/authors-transform.txt | |
# Clone SVN repository to Git | |
git svn clone "$SVN" -A $TMP/authors-transform.txt --stdlayout $TMP/$(basename $SVN).git || exit 1 | |
cd $TMP/$(basename $SVN).git | |
# Converting svn:ignore to .gitignore | |
if [ ! -f .gitignore ]; then | |
git svn show-ignore > .gitignore || rm .gitignore | |
[ -f .gitignore ] && git add .gitignore && git commit -m 'Convert svn:ignore properties to .gitignore' | |
fi | |
# Convert tag remotes | |
git for-each-ref --format='%(refname)' refs/remotes/tags | cut -d / -f 4 | while read ref | |
do | |
git tag "$ref" "refs/remotes/tags/$ref"; | |
done | |
# Push repository to a bare git repository (remote origin) | |
echo '' | |
GITHUB_USER=$(git config --get user.email | cut -f1 -d@) | |
read -p "Remote Git repository [[email protected]:$GITHUB_USER/$(basename $SVN).git]: " REMOTE | |
${REMOTE:[email protected]:$GITHUB_USER/$(basename $SVN).git} | |
git remote add origin $REMOTE || exit 1 | |
echo '' | |
git config remote.origin.push 'refs/heads/*:refs/heads/*' || exit 1 | |
read -p 'Would you like to push to the remote repository? [Y|n] ' PUSH | |
case ${PUSH:-Y} in | |
[Yy]) | |
git push origin | |
git push origin refs/tags/* | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on http://john.albin.net/git/convert-subversion-to-git