Skip to content

Instantly share code, notes, and snippets.

@mmalina
Forked from nickboldt/SVN To GitHub Migration
Created September 20, 2012 14:53
Show Gist options
  • Save mmalina/3756392 to your computer and use it in GitHub Desktop.
Save mmalina/3756392 to your computer and use it in GitHub Desktop.
SVN To GitHub Migration
== Migration from SVN to Git ==
This is a fork of nbolt's svn-to-github script. It is modified to be used for swt bot tests migration. We need to migrate these folders out of the original svn repo:
./archives/tests/org.jboss.tools.archives.ui.bot.test
./as/tests/org.jboss.ide.eclipse.as.ui.bot.test
./bpel/tests/org.jboss.tools.bpel.ui.bot.test
./build/aggregate/soatests-site/tests/org.jboss.tools.drools.ui.bot.test
./esb/tests/org.jboss.tools.esb.ui.bot.test
./forge/tests/org.jboss.tools.forge.ui.bot.test
./freemarker/tests/org.jboss.tools.freemarker.ui.bot.test
./hibernatetools/tests/org.jboss.tools.hibernate.ui.bot.test
./jbpm/tests/org.jboss.tools.jbpm.ui.bot.test
./jsf/tests/org.jboss.tools.jsf.ui.bot.test
./jst/tests/org.jboss.tools.jst.ui.bot.test
./maven/tests/org.jboss.tools.maven.ui.bot.test
./modeshape/tests/org.jboss.tools.modeshape.rest.ui.bot.test
./openshift/tests/org.jboss.tools.openshift.ui.bot.test
./portlet/tests/org.jboss.tools.portlet.ui.bot.test
./runtime/tests/org.jboss.tools.runtime.as.ui.bot.test
./seam/tests/org.jboss.tools.seam.ui.bot.test
./struts/tests/org.jboss.tools.struts.ui.bot.test
./tests/plugins/org.jboss.tools.ui.bot.ext
./tests/tests/org.jboss.tools.dummy.ui.bot.test
./tests/tests/org.jboss.tools.ui.bot.ext.test
./vpe/tests/org.jboss.tools.vpe.ui.bot.test
./ws/tests/org.jboss.tools.ws.ui.bot.test
This operation will require a fair amount of disk. Each copy of the overall jbosstools-svn-mirror git repo is about 2.6Gb.
After the migration, Freemarker was only 4.4Mb.
1. Check out entire git repo:
git clone git@github.com:jbosstools/jbosstools-svn-mirror.git
or
git clone https://github.com/jbosstools/jbosstools-svn-mirror.git
2. Copy local repo to new working folder
targetName=jbosstools-integration-tests
rsync -aPz jbosstools-svn-mirror tmp; mv tmp/jbosstools-svn-mirror ${targetName}_tmp; rmdir tmp
3. Enter the new copy folder, and clean out all but the content we care about
cd ${targetName}_tmp/
# remove all but the branches/tags we want
branches="jbosstools-3.2.x jbosstools-3.3.x jbosstools-4.0.0.Alpha1 tags/jbosstools-3.2.2.Final tags/jbosstools-3.3.1.Final"
for i in $branches; do git branch -t $i origin/$i; done
# Branch jbosstools-3.2.x set up to track remote branch jbosstools-3.2.x from origin.
# Branch jbosstools-3.3.x set up to track remote branch jbosstools-3.3.x from origin.
# Branch jbosstools-4.0.0.Alpha1 set up to track remote branch jbosstools-4.0.0.Alpha1 from origin.
# Branch tags/jbosstools-3.2.2.Final set up to track remote branch tags/jbosstools-3.2.2.Final from origin.
# Branch tags/jbosstools-3.3.1.Final set up to track remote branch tags/jbosstools-3.3.1.Final from origin.
# remove the origin to avoid pushing there and to make sure that old commits will not be referenced by the origin
git remote rm origin
# list branches
git branch -a
# jbosstools-3.2.x
# jbosstools-3.3.x
# jbosstools-4.0.0.Alpha1
# tags/jbosstools-3.2.2.Final
# tags/jbosstools-3.3.1.Final
# * trunk
# remove all tags - note that for an svn2git repo like jbosstools-svn-mirror this has no effect because svn2git put all the tags as branches under tags/jbosstools-*
# git tag -l | xargs git tag -d
#git status .
# if anything needs to be committed, do so now
#git commit -m "prepare local repo copy for filtering" .
# get git_fast_filter and set it up
cd .. && git clone git://gitorious.org/git_fast_filter/mainline.git git_fast_filter
echo > git_fast_filter/file_filter.py <<_EOF
#!/usr/bin/env python
from git_fast_filter import Blob, Reset, FileChanges, Commit, FastExportFilter
def drop_file_by_contents(blob):
bad_file_contents = 'The launch code is 1-2-3-4.'
#if blob.data == bad_file_contents:
# blob.skip()
def drop_files_by_name(commit):
new_file_changes = []
for change in commit.file_changes:
if (change.filename.find('.ui.bot.') > 0):
new_file_changes.append(change)
commit.file_changes = new_file_changes
filter = FastExportFilter(blob_callback = drop_file_by_contents,
commit_callback = drop_files_by_name)
filter.run()
_EOF
chmod +x git_fast_filter/file_filter.py
export PYTHONPATH=`pwd`/git_fast_filter:$PYTHONPATH
#prepare the new repo and run the filter
mkdir $targetName && cd $targetName && git init
#this will take up to 1 hour
(cd ../jbosstools-svn-mirror/ && git fast-export --all) | ../git_fast_filter/testcases/file_filter.py | git fast-import
4. Create new remote repo in github, named as above ${targetName}, eg. jbosstools-integration-tests
5. Connect local to new remote repo in github
git remote add origin git@github.com:mmalina/jbosstools-integration-tests.git
# each branch could take >4 mins to complete.
# note that the "+" before the branch when pushing means FORCE regardless of fast-forward or merging issues
for branch in $branches; do
echo "git checkout $branch ..."
git checkout -q -f ${branch}
echo "git push origin +${branch} ..."
git push origin +${branch}
done
# Counting objects: 4224, done.
# Delta compression using up to 8 threads.
# Compressing objects: 100% (3163/3163), done.
# Writing objects: 100% (4224/4224), 22.24 MiB | 104 KiB/s, done.
# Total 4224 (delta 1252), reused 3023 (delta 588)
# To git@github.com:nickboldt/jbosstools-Base_v2.git
# * [new branch] trunk -> trunk
# Branch trunk set up to track remote branch trunk from origin.
6. To set the default branch in github, click the "admin" link on the right-hand side of the project main page
# https://github.com/nickboldt/jbosstools-forge/admin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment