Skip to content

Instantly share code, notes, and snippets.

@soderlind-gist
Created February 5, 2013 00:59
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 soderlind-gist/4711214 to your computer and use it in GitHub Desktop.
Save soderlind-gist/4711214 to your computer and use it in GitHub Desktop.
svn2git.sh copies your plugin from WordPress svn repository to a local git repository and to GitHub.
#!/bin/bash
#
# svn2git.sh copies your plugin from WordPress svn repository to a local git repository and to GitHub.
# The GiHub repository will be created, using the GitHub API, if it doens't exist.
#
# You need to change the GITHUB_USERNAME and AUTHORS_FILE variables and create a authors file. The
# authors file is used to match your svn user with your GitHub user.
#
# .. and, copying from svn takes time :/
GITHUB_USERNAME="soderlind";
# #Sample AUTHORS_FILE, syntax: wordpressuser = githubuser <githubuser@mydomain.tld>
# plugin-master = soderlind <soderlind@mydomain.tld>
# PerS = soderlind <soderlind@mydomain.tld>
AUTHORS_FILE="$HOME/Development/authors.txt";
#
# You don't have to edit blow here
#
if [[ $# -eq 0 ]];then
echo "Syntax: $0 YOUR-PLUGIN-NAME, from: http://plugins.svn.wordpress.org/YOUR-PLUGIN-NAME";
exit 1;
fi
args=("$@");
PLUGIN_NAME=${args[0]};
svn info http://plugins.svn.wordpress.org/$PLUGIN_NAME
error=$?;
if [[ $error -ne 0 ]]; then
echo "Couldn't find plugin at http://plugins.svn.wordpress.org/$PLUGIN_NAME";
exit 1;
fi
REVISION_NUMBER=`svn log -r 1:HEAD --limit 1 http://plugins.svn.wordpress.org/$PLUGIN_NAME | grep "plugin-master" | awk '{print $1}'`
git svn clone -s -$REVISION_NUMBER --no-minimize-url --authors-file $AUTHORS_FILE http://plugins.svn.wordpress.org/$PLUGIN_NAME
cd $PLUGIN_NAME
git svn fetch
git svn rebase
#
# Create a new GitHub repo, will prompt for your password.
# You can replace $GITUSERNAME with $GITUSERNAME:password, but it's a securty risk
#
wget_output=$(wget -q "https://github.com/$GITHUB_USERNAME/$PLUGIN_NAME.git")
if [ "$?" -ne 0 ]; then
echo "Creating a new GitHub repository at https://github.com/$GITHUB_USERNAME/$PLUGIN_NAME.git"
curl -u "$GITHUB_USERNAME" https://api.github.com/user/repos -d "{\"name\":\"$PLUGIN_NAME\"}"
fi
git remote add origin git@github.com:$GITHUB_USERNAME/$PLUGIN_NAME.git
git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment