public
Last active

Migrates multiple SVN repos to GitHub, without anything fancy (no Ruby, no dependencies, no issues with Cygwin paths).

  • Download Gist
svn-to-git
1 2 3 4 5 6 7 8 9 10 11
Migrates multiple SVN repos to GitHub, without anything fancy (no Ruby, no dependencies, no issues with Cygwin paths). SVN tags are created as Git tags and properly pushed to GitHub. To run:
 
1) Edit run-authors.sh to have your SVN repos. Run it to get an authors.txt file.
 
2) Edit the authors.txt to have GitHub names and emails if you like. You must use GitHub user email addresses if you want contributions to be associated with GitHub accounts.
 
3) Create the GitHub projects, without populating it with a readme or license.
 
4) Edit run-convert.sh to have your SVN repos, GitHub user URL, and GitHub project name. Run it.
 
5) Done!
authors.sh
Shell
1 2 3 4
cp authors.txt authors.temp
svn log -q $1 | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u >> authors.temp
cat authors.temp | sort -u > authors.txt
rm authors.temp
convert.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
svn_url=$1;
github_url=$2;
name=$3;
 
echo "Cloning SVN repository to $name.svn... $svn_url"
rm -rf $name.svn
git svn clone $svn_url --no-metadata -A authors.txt --stdlayout $name.svn
cd $name.svn
 
echo "Creating .gitignore file..."
git svn show-ignore > .gitignore
git add .gitignore
git commit -m 'Convert svn:ignore properties to .gitignore.'
 
echo "Initializing git repository... $name.git"
cd ..
rm -rf $name.git
git init --bare $name.git
cd $name.git
git symbolic-ref HEAD refs/heads/trunk
 
echo "Pushing to git repository... $name.git"
cd ../$name.svn
git remote add bare ../$name.git
git config remote.bare.push 'refs/remotes/*:refs/heads/*'
git push bare
 
echo "Renaming trunk to master..."
cd ../$name.git
git branch -m trunk master
 
echo "Converting SVN tag branches to git tags..."
git for-each-ref --format='%(refname)' refs/heads/tags | cut -d / -f 4 |
while read ref
do
git tag -a "$ref" -m "Tag: $ref" "refs/heads/tags/$ref";
git branch -D "tags/$ref";
done
 
echo "Pushing to github... $github_url$name"
git push --mirror --follow-tags $github_url$name
 
echo "Done!"
run-authors.sh
Shell
1 2 3 4 5 6 7 8 9 10 11
rm authors.txt
sh authors.sh http://kryo.googlecode.com/svn
sh authors.sh http://kryonet.googlecode.com/svn
sh authors.sh http://minlog.googlecode.com/svn
sh authors.sh http://reflectasm.googlecode.com/svn
sh authors.sh http://jsonbeans.googlecode.com/svn
sh authors.sh http://yamlbeans.googlecode.com/svn
sh authors.sh http://tablelayout.googlecode.com/svn
sh authors.sh http://reflectasm.googlecode.com/svn
sh authors.sh http://wildcard.googlecode.com/svn
sh authors.sh http://scar.googlecode.com/svn
run-convert.sh
Shell
1 2 3 4 5 6 7 8 9 10
sh convert.sh http://reflectasm.googlecode.com/svn https://github.com/EsotericSoftware/ reflectasm
sh convert.sh http://kryo.googlecode.com/svn https://github.com/EsotericSoftware/ kryo
sh convert.sh http://minlog.googlecode.com/svn https://github.com/EsotericSoftware/ minlog
sh convert.sh http://kryonet.googlecode.com/svn https://github.com/EsotericSoftware/ kryonet
sh convert.sh http://reflectasm.googlecode.com/svn https://github.com/EsotericSoftware/ reflectasm
sh convert.sh http://jsonbeans.googlecode.com/svn https://github.com/EsotericSoftware/ jsonbeans
sh convert.sh http://yamlbeans.googlecode.com/svn https://github.com/EsotericSoftware/ yamlbeans
sh convert.sh http://table-layout.googlecode.com/svn https://github.com/EsotericSoftware/ tablelayout
sh convert.sh http://wildcard.googlecode.com/svn https://github.com/EsotericSoftware/ wildcard
sh convert.sh http://scar.googlecode.com/svn https://github.com/EsotericSoftware/ scar

Thanks, your scripts were very handy.
Had some issue with git svn show-ignore that failed: fixed it by using --id trunk argument.

Also had special needs (no GitHub, preserve empty directories, add a develop branch) so I've improved them.
If that's of any help to anyone, here they are: https://github.com/C-Duv/sysadmin-scripts/tree/master/gitlab/svn2gitlab

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.