composer-patches-plugin icon indicating copy to clipboard operation
composer-patches-plugin copied to clipboard

Question: How to remove a patch properly?

Open MajPay opened this issue 3 years ago • 4 comments

I used composer-patches-plugin to apply some patches to a package (local patch files) and that worked as expected. Thanks so far!

My patches got merged into the package and i don't need them anymore. So i increased the packages version number, patch-package version number, removed the required patches ran composer update (deleted the .patch files too). I finally checked in the composer.lock file to make all changes fixed for deployment.

Today i wanted to update a remote installation - i merged the project source which contains the composer.lock file. When i run composer install, i get the following error:

The "patches/{package}/4b4636293ac6d46e171eaae8e64ae50ce2cd0b29.patch" file could not be downloaded: failed to open stream: No such file or directory

But the patch is not required anymore - so why does composer-patches-plugin need the .patch file?

As a workaround i can delete the local package and run composer install - this will work as expected.

The "problem" seems to be caused by the contents of "installed.json" which contained the patch-file URLs, which did not exist anymore because they are not required in the version defined in composer.lock.

So, what is the "correct" way? Simply keep the patch files in the vcs?

IMO this is not very intuitive nor logical, it may be better to store a copy of the applied patches in some local cache directory (package directory or vendor/composer or even as string value inside installed.json). That way it would be more stable and patch files could be altered as well (i guess changing a patch could also be a problem).

MajPay avatar Jan 11 '22 08:01 MajPay

Hi @MajPay,

did you check https://github.com/netresearch/composer-patches-plugin#provide-patches-by-package-and-versions-or-version-constraints ?

CybotTM avatar Jan 11 '22 09:01 CybotTM

Yes, i tried to fix the patch-set to another version of the package but it did not work - i think it still tried to "rollback" the applied patches because they existed in installed.json.

MajPay avatar Jan 12 '22 08:01 MajPay

maybe @copitz can shed some light on it.

CybotTM avatar Jan 12 '22 10:01 CybotTM

Another problem regarding this issue: you cant work with branches where you need a patch in branch-a, then switch to branch-b (where no patch is needed and the patch file does not exist) and do a composer install because the patch file is missing and cant be rolled back. This is a major issue (!). My only workaround is to delete the "vendor/composer/installed.json".

If it is necessary to still have access to the patch file even if it is not required anymore, the patch file (contents) need to be persisted in the current composer state. You should probably add the contents of the patch file to installed.json and pass the string to the stdin of the patch tool. That way you can always rollback installed patches, even if the patch-files only exist in another branch or have been deleted.

MajPay avatar Feb 08 '22 08:02 MajPay