Tag Archives: patches

Applying Patches to Drupal or Modules on Mac OS X

I’ve had to run a number of patches to Drupal modules before, and I’ve always done them on my Windows machine simply because that is what has the most instructions available to do so. At the moment though I am away on holidays and only have my Macbook Pro, so when I needed to run a patch I debated going to the effort of doing it through a Windows virtual machine that isn’t set up for it, or set up Eclipse and run it through their software. After much debating, I decided to look up the instructions again and see if there was a recommendation. While I was hunting around, I noticed two very, very useful things:

  1. Apple’s Xcode suite allows you to run Drupal patches.
  2. You can patch files using the OS X terminal without any need to install special software such as what I needed to do to run patches through the Windows Command Prompt. You don’t even need to have Xcode installed!

I already have Apple Xcode, as does every Mac user (if they choose to install it from their OS X disc), so that seemed like it would potentially be the easiest option, then I saw the instructions to patch a Drupal module using the OS X Terminal. It is so easy I can’t believe I didn’t start patching on my Mac sooner!

The process to patch a Drupal module on Mac

  1. Place both the original module file and the patch in the same folder.
  2. Make sure that they have the same name, with different extensions, so you would need my_module.patch and my_module.module.
  3. Open up the Terminal application. Either search for Terminal in Spotlight, or go to Applications > Utilities > Terminal.
  4. Navigate to the folder containing your files using the Terminal cd command. By default Terminal will start in your user directory, so if your files are in a folder called patch/my_module inside your user directory, you would type: cd patch/my_module. A little trick here to save yourself some trouble is just type cd and then drag the folder into the Terminal window. OS X will auto-fill the folder path for you.
  5. Run the patch using the patch command: patch < my_module.patch

That’s it! Simple as that.

If you would like to take a back up of the original patch file, type: patch -b < my_module.patch and a backup file will be created for you entitled my_module.module.orig

If you are patching Drupal core, the process is slightly different, you need to use the -p0 attribute to stop patch from asking you what file to patch, so you would do this as: patch -p0 < my_module.patch

Those are probably the main things you’ll use, but for more information, here are some other references:

One other thing to note is that if your .patch and .module files don’t have the same name, then Terminal does sometimes have issues with it. I’m not sure why exactly.

Hope that helps! If you’ve got any other tips for patching on OS X I’d love to hear them!