public
Created

svn2git.sh copies your plugin from WordPress svn repository to a local git repository and to GitHub.

  • Download Gist
svn2git.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 44 45 46 47 48 49 50 51 52 53 54 55 56 57
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.