Skip to content

Instantly share code, notes, and snippets.

@neowinx
Forked from NathanSweet/ svn-to-git
Created December 19, 2013 12:53
Show Gist options
  • Save neowinx/8038684 to your computer and use it in GitHub Desktop.
Save neowinx/8038684 to your computer and use it in GitHub Desktop.
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!
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
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!"
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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment