This week I’ve been playing about with a neat tool by Dave Reid, called Drush Patch File, for tracking and applying patches to contrib modules on Drupal projects. We’ve found ourselves patching a few modules recently on several projects, including the Drupal 7 backport of Navbar so that the drop-downs work better on desktop.
The problem faced when patching contributed modules is that, if the module is updated but the patch isn’t included in the new release, then the module is effectively un-patched. Bad news. Therefore, we have to reapply the patch manually.
We were thinking the other day that it would be terrific if we could in fact automate this process. While we could have spent some time fiddling around with bash scripts and ansible playbooks, the Drush Patch File project looked like a clean implementation with some great features.
Installing the project is just a case of cloning inside the drush folder on your development machine, and specifying a patches.make file relative to your project’s Drush drushrc.php file. Then, when applying a patch, you can use
drush patch-add <module_name> http://drupal.org/link/to/patch to apply the patch and add it to the patch file so that it is reapplied when the module is updated. If the patch is no longer necessary or cannot be applied following the update, you’ll get a message when you run drush pm-update. Easy as that.