For the first time in a long time, I ran into a composer issue today with no clear evidence of a problem (no error messages) and no clear path forward. I had to do some sleuthing and digging (and thankfully Google delivered, as always). But I wanted to flag the issue here since it is such an oddball issue and I was really surprised to come across it.
TLDR: I was trying to patch a project (as a temporary measure) using Composer to patch off of a Github pull request. The patch was applying successfully… but the end result was my project was only partially patched. The file that needed to change DID change, but the files that should have been renamed (1) and deleted (1) were not.
Really strange. Let’s dig into it!
The Situation
I’m working with an open source project on a Drupal build. We found an issue related to order of operations in the project, and we have a fix we are experimenting with. In the pull request for the experiment, we are:
changing an inventory file’s contents to re-order packages
combining two files into a single file
Due to the way Git tracks file changes, that second item actually resulted in one file being deleted, and another being renamed. However, when the patch is applied via composer patches, I am not seeing these results. The patch does apply cleanly (good) but the end result is that my files don’t align with the patch (meaning, the file didn’t get deleted and the file didn’t get renamed) which is bad.
Fixing the Problem
I came an issue on the Composer Patches Github issue queue that my colleague Dane opened some time back. The proposed solution in this case is to add an additional package via Homebrew locally. I can confirm that this DID solve the problem for me.
brew install gpatch
After install gpatch, I re-ran the composer patch and this time as expected it revised my file system (and removed / renamed the appropriate files).
This is a great example of a silently failing failure that can have massive implications!
Dependency trees can be massive, and with the upcoming Drupal 10 release PHP 8.1 could have a significant impact on your project.