Using git and svn for WordPress plugin development.

For software development I use git as a source code management system and my WordPress plugins are no exception. The “problem” is that the WordPress plugin repository is a subversion repository. You can use git-svn but I choose a different approach. I use a shell script when I’m ready to release a new version of a WordPress plugin to copy the needed files to the SVN repository.

Development setup

I develop in the directory /d1/development/wordpress and I create separate directories for the WordPress SVN structure and the git environment.

├── avh_plugins
│   ├── avh-first-defense-against-spam
│   │   └── source
│   └── extended-categories-widget
│   │   └── source
    ├── avh-first-defense-against-spam
    │   ├── branches
    │   ├── tags
    │   └── trunk
    └── extended-categories-widget
        ├── branches
        ├── tags
        └── trunk

In every source directory is a separate git repository for that plugin. And to simplify the script I use the same directory names in git as I do in the SVN repository.
All the development is done only in git repository, I never manually change source code in the SVN repository.

The shell script

I named the shell script avh-release-script and placed in a directory that’s also in the $PATH environment variable.
When I’m ready to release a new version of a plugin I run the following script in the directory source.


#Package Name

# New Version to deploy
NEW=`grep "^Stable tag" readme.txt|awk '{ print $NF}'`

#Path to local SVN repository

#WordPress SVN Username and Password

# Tag the new version in git
git tag v$NEW

# Update the SVN repository

# Remove all the files and directories from the SVN trunk
find $SVN_PATH/$PACKAGE/trunk/ -mindepth 1 -maxdepth 1 -not -path .svn -print0|xargs -0 -I REPFILES svn rm REPFILES

# Copy everything from the git directory to the svn trunk
git checkout-index -a -f --prefix=${SVN_PATH}/$PACKAGE/trunk/

# Add and commit the files and directories into the SVN repository
svn add --force $SVN_PATH/$PACKAGE/trunk/*
svn ci -m \"Release v$NEW\" $SVN_PATH/$PACKAGE/trunk/ --username=$USERNAME --password=$PWD

# Copy the trunk to the new tag in the SVN repository
svn copy $SVN_PATH/$PACKAGE/trunk/ $SVN_PATH/$PACKAGE/tags/$NEW --username=$USERNAME --password=$PWD
svn ci -m \"Tagging v$NEW\" $SVN_PATH/$PACKAGE/ --username=$USERNAME --password=$PWD


In the directory /d1/development/wordpress/avh_plugins/avh-first-defense-against-spam/source execute

This article is filed under the categories Development » WordPress and has no tags associated with it.