Skip to content

Instantly share code, notes, and snippets.

@ozh
Forked from markjaquith/gist:2628225
Created November 7, 2012 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozh/4032822 to your computer and use it in GitHub Desktop.
Save ozh/4032822 to your computer and use it in GitHub Desktop.
Script to sync WordPress SVN to GitHub
#!/bin/bash
# cd into the directory
cd ~/gitsync/github-wordpress-sync/;
# Make sure we are not already running
if [ -f .sync-running ];then
if test ! `find ".sync-running" -mmin +10`;then
# Currently running, but not stuck
exit 1;
fi
fi;
# Mark as running
touch .sync-running
# Switch to the master branch (which syncs to trunk)
git checkout master;
# Slurp down svn changes
git svn fetch;
# Rebase the changes from trunk into master
git svn rebase;
# Cycle through svn tags and create a git tag for each
git for-each-ref refs/remotes/tags | cut -d / -f 4- | while read ref; do git tag $ref refs/remotes/tags/$ref > /dev/null 2>&1; done;
# Cycle through svn branches and create a git branch for each
# Skip any branches that don't have changes to speed this up
svn list http://core.svn.wordpress.org/branches/ | grep -oE '[3-9]\.[0-9]' | while read branch; do git branch $branch-branch remotes/$branch > /dev/null 2>&1; git checkout $branch-branch; if [ '0' != `git diff --name-only remotes/$branch | wc -l | awk "{print $1}"` ]; then git svn rebase remotes/$branch; git push github $branch-branch; fi; done;
# Back to master
git checkout master;
# Push branches and tags to GitHub (markjaquith/WordPress)
git push --all github;
git push --tags github;
# Push branches and tags to GitHub (WordPress/WordPress)
git push --all wordpress;
git push --tags wordpress;
# Mark as not running
rm .sync-running
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment