ronisaha
11/9/2017 - 2:11 AM

Using Git with Subversion Mirroring for WordPress Plugin Development

Using Git with Subversion Mirroring for WordPress Plugin Development

Update: please note that I have since switched to using a set of bash scripts instead of poluting the Git repository with git svn.

Using Git and GitHub with Subversion (SVN) Mirroring for WordPress Plugin Development

Author: Kaspars Dambis
kaspars.net / @konstruktors

Getting Started

We'll assume that your plugin is already hosted on the official WordPress plugin Subversion repository, and we'll use the Easy Digital Downloads plugin as an example.

  1. First, we need to get the revision number of the first commit to the WordPress Subversion repository, because otherwise Git will try to go through all the 100000+ commits in order to find it.

     $ svn log http://plugins.svn.wordpress.org/easy-digital-downloads/
    

    It is the last commit revision you seen on the screen:

     ------------------------------------------------------------------------
     r529177 | plugin-master | 2012-04-09 19:36:16 +0200 (Mon, 09 Apr 2012) | 1 line
    
     adding easy-digital-downloads by mordauk
     ------------------------------------------------------------------------
    

    In this case it is r529177. You can also use the official WordPress Trac browser to determine the first revision number.

  2. Now, create a local Git repository and import the first commit from the SVN repository:

     $ git svn clone --no-minimize-url -s -r529177 http://plugins.svn.wordpress.org/easy-digital-downloads/
    

    which returns the following:

     Initialized empty Git repository in /Users/kaspars/svn2git/easy-digital-downloads/.git/
     r529177 = e18c66d09d77e4d8a923f2f300f73606791071e1 (refs/remotes/trunk)
     Checked out HEAD:
       http://plugins.svn.wordpress.org/easy-digital-downloads/trunk r529177
    

    Notice the --no-minimize-url flag which is required to stop git svn clone from moving into the base folder of the remote SVN repository and going through all plugins (see git-svn docs). We also use the -s flag which is a shorthand way of setting trunk, tags, branches as the relative paths, which is the Subversion default (from git-svn docs).

  3. Finally, move inside the newly created Git repository:

     $ cd easy-digital-downloads
    

    and fetch all the other commits from the SVN repo:

     $ git svn fetch
    

    This step will take hours (!), so you can use the GIT_TRACE environment variable before the the command to see a verbose output:

     $ GIT_TRACE=1 git svn fetch
    

    To speed up git svn fetch especially with large SVN repositories you can try setting the --log-window-size parameter to request more commits per SVN request (read Experiences of Using Git-Svn on a Large Project). Increasing it to 10000 should decrease the fetch time significantly:

     $ git svn fetch --log-window-size 10000
    

    Once this process is finished you have a complete Git commit tree of the project. The final step is to move the SVN HEAD (files from SVN /trunk) into our Git master branch (I assume), which is done using:

     $ git svn rebase
    

    Now you should see all the latest plugin files in your local repository.

Inspecting the Newly Cloned Repository

Let's look at all the branches that were created:

$ git branch -a

which returns a list of all the available branches:

* master
  remotes/tags/1.0.1.1
  remotes/tags/1.0.1.2
  remotes/tags/1.0.1.3
  remotes/tags/1.0.1.4
  ...
  remotes/tags/1.1.8
  remotes/tags/1.2
  remotes/tags/1.2.1
  remotes/tags/1.2.1.1
  remotes/trunk