WordCamp Phoenix 2013

WP 401:
Git Patches, Plugins,
& Updates

Paul Clark
WordCamp Phoenix 2013

pdclark on twitter, wordpress.org

About Me

Company

Technical Director at Brainstorm Media

WordPress

WordPress.org is on SVN

Core is on SVN

You use Git

SVN Makes You :'(

What should you do?

WordPress Core

git-svn :'(

# Pros: This comes from Mark Jaquith, who is a genius
# Cons: Your first checkout will take all night
git svn clone -t tags -b branches -T trunk http://core.svn.wordpress.org/

github :)

# Repo used to be on Mark's account. Now on WordPress/WordPress
# Updated every 15 minutes
git clone https://github.com/WordPress/WordPress.git

Setup .gitignore

We don't want to submit patches with your personal settings.
wp-config.php
.gitignore
wp-content/uploads

Format Patches for Trac. Find a ticket!

# Do this once as a global setting

git config --global diff.noprefix true

Create a feature branch

# Omit "master" if you're already on the master branch
# 123 is a ticket number
# f/ is my personal, arbitrary prefix for a feature branch
# breakthrough is what we'll be working on
git checkout master -b f/123-breakthrough
# Tip for the lazy: Use "git co" instead of git checkout with aliases
#     git config alias.co checkout
#     git config alias.s status
#     git config alias.br "branch -va"

Work on things, make commits

# [ Do amazing work ]

git commit -am "Reticulated splines"

# [ Discover amazing solution ]

git commit -am "Acheived breakthrough"

Create patch

# Diff between feature branch and master
git diff master f/123-breakthrough > breakthrough.123.diff

# Diff between current branch and master
git diff master... > breakthrough.123.diff

# Diff between current changes and master
# e.g., you're being lazy and didn't create a branch or any commits
git diff master > quick-n-dirty.123.diff

Plugins

git-svn

There are better ways. Here are some articles anyway.

Deploy script :)

Setup

PLUGINSLUG="example-plugin"   # Slug on wp.org (from the plugin URL)
MAINFILE="example-plugin.php" # Name of main php file in plugin
SVNUSER="username"            # SVN username on wordpress.org

Usage

./deploy.sh

Get it
github.com/pdclark/deploy-plugin-to-wordpress-dot-org

Auto-updates
What to do when your plugin is not on .org

Auto-update from Git instead of .org

jkudish: Awesome original

if (is_admin()) { // note the use of is_admin() to double check that this is happening in the admin
    $config = array(
        'slug' => plugin_basename(__FILE__), // this is the slug of your plugin
        'proper_folder_name' => 'plugin-name', // this is the name of the folder your plugin lives in
        'api_url' => 'https://api.github.com/repos/username/repository-name', // the github API url of your github repo
        'raw_url' => 'https://raw.github.com/username/repository-name/master', // the github raw url of your github repo
        'github_url' => 'https://github.com/username/repository-name', // the github url of your github repo
        'zip_url' => 'https://github.com/username/repository-name/zipball/master', // the zip url of the github repo
        'sslverify' => true // wether WP should check the validity of the SSL cert when getting an update, see https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/2 and https://github.com/jkudish/WordPress-GitHub-Plugin-Updater/issues/4 for details
        'requires' => '3.0', // which version of WordPress does your plugin require?
        'tested' => '3.3', // which version of WordPress is your plugin tested up to?
        'readme' => 'README.md', // which file to use as the readme for the version number
        'access_token' => '', // Access private repositories by authorizing under Appearance > Github Updates when this example plugin is installed
    );
    new WPGitHubUpdater($config);
}

pdclark: Added one-line config, Gitweb support

/*
Plugin Name: Example Plugin
Plugin URI: https://github.com/jkudish/WordPress-GitHub-Plugin-Updater
*/

Thank you! (Questions?)


Slides online at
brainstormmedia.com/wcphx2013