Home

Awesome

Build Status

Composer Plugin For Applying Patchsets

‼️ NEW Supports both composer branches v1.x and v2.x.

This plugin can automatically apply patches to any dependency of your project.

One of the most distinguishing features is that it can apply patches from special composer packages of type patchset. This is quite convenient as you can store all your patches in one repository and apply them automatically on all systems including developers' machines in a very predictable way. Also you can easily distribute your patchset to the whole community via packagist.

It's (kind-of) an alternative to two other great plugins:

Continue reading this document for more in-depth description or skip right away directly to:

Feature comparison table

Featurecreativestyle/composer-plugin-patchsetcweagans/composer-patches 1.xnetresearch/composer-patches-plugin
Apply patch collection stored in a composer packageyesnono
Deduplicate patchesyesnoTBD
Guarantees proper application on the first installyesnoTBD
Full functional test-suite for all featuresyesnono tests at all
PHP Version Support confirmed by tests5.6+5.3+no information
Apply patches directly from remote locationsno (no support planned)yesyes
Specify target package version constraintsyesnoyes
Uninstall removed patches in all cases<sup>1</sup>yesnoTBD
Reapply package patches if order has changedyesTBDTBD
Choose application method (git/patch) per patchyesTBDTBD
Apply patches to root package/directoryyesnoTBD

<sup>1</sup> Root package patching is the exception, please see applying patches to root package in usage docs.

Feature description

Use Git for applying patches

By default the library will try to use the patch command if not available and fall back to git otherwise. You can force using git for each patch (see: Usage Documentation).

There were some problems using git apply reported in other plugins for packages that were not installed as source (did not have a git repo; .git dir). I was not able to reproduce this problem with git 2.X - however - a workaround for this potential problem has been implemented:

- If the target package has `.git` directory, then the patches are applied relative to target package root
- If no git repo in target package then patches are applied from root project directory

Chicken or egg problem

Patching via composer plugin has one big problem - you cannot catch all events on the first install. Furthermore applying patches on package install/remove is very error prone as you can never predict conflicts with other plugins. Therefor gathering and applying patches before everything was actually installed carries the risk of producing invalid state at the end. This plugin takes a different approach - it performs all actions at once, after the installation/update was performed, just before autoload dump (in case patching changes it).

This guarantees a consistent state as the plugin compares the current state with the desired one and peforms only the actions necessary to get there.

This has one drawback, if your project uses any composer plugins that copy files from vendors to the root of your project then you should patch the root package because the patch applications will happen after those plugins have done their work so patching source files in vendor will have no effect.

Why no remote patches

This plugin will not download patches from external sources directly (http). I consider this a bad practice and will never support it. I won't even comment on downloading patches using unencrypted connection without SHA check. Also what if somebody wants to use your software in 2 years and the patches are no longer available?

Also you will not be able to specify patches in any composer package. You have to use a dedicated packages for this purpose. I can hardly imagine a legit use case when it would be desirable that installing package X will automatically patch some other package Y in your project without explicitly being advertised as a patchset.