composer-patches: Could not apply patch! Skipping. The error was: Cannot apply patch
For some reason I cannot use this plugin. I thought its a user rights thing so I gave 777 to the whole folder. Still it does not work.
The patch is ok. I just was able to include it by using phpstorm.
Thanks for help
$ composer update
1/1: http://packagist.org/p/provider-latest$40d29078e846e543e38d2771c7c700e88dfe049917735d752cc3fa12fa9f051d.json
Finished: success: 1, skipped: 0, failure: 0, total: 1
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
- Installing drupal/paragraphs (dev-1.x bedd55b): Cloning bedd55bbac from cache
- Applying patches for drupal/paragraphs
https://www.drupal.org/files/issues/embed_paragraph_content-2848878-43.patch (Add startup configuration for PHP server)
Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/embed_paragraph_content-2848878-43.patch
https://www.drupal.org/files/issues/2868155-16.patch (Issue #2868155: new hooks for editing paragraphs subforms)
> Drupal\Core\Composer\Composer::vendorTestCodeCleanup
Writing lock file
Generating autoload files
> Drupal\Core\Composer\Composer::preAutoloadDump
> Drupal\Core\Composer\Composer::ensureHtaccess
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 51 (14 by maintainers)
Commits related to this issue
- Add `patch` to support `composer-patches` @see https://github.com/cweagans/composer-patches/issues/226 — committed to ElijahLynn/docker-jenkins-slave-php-7.2.4 by ElijahLynn 5 years ago
- Add `patch` to support `composer-patches` @see https://github.com/cweagans/composer-patches/issues/226 — committed to ElijahLynn/docker-jenkins-slave-php-7.2.4 by ElijahLynn 5 years ago
- VAGOV-839 Remove safety `composer install`, real issue was found. https://github.com/cweagans/composer-patches/issues/226 — committed to ElijahLynn/va.gov-cms by ElijahLynn 5 years ago
- VAGOV-839 Remove safety `composer install`, real issue was found. https://github.com/cweagans/composer-patches/issues/226 — committed to ethanteague/va.gov-cms by ElijahLynn 5 years ago
For those who are looking for exact reason why the patch cannot be applied, try running
composer install -vvvwhich means debug level of verbosity. It should give you insight on what’s happening. In my case the error was only on the server and pretty stupid and self explanatory :- Applying patches for ... ... patch '-p1' --no-backup-if-mismatch -d '...' < '...' Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d '..' < '...' sh: patch: command not foundSome of the time problem maybe OS does not have patch module install.
sudo yum install patchcan solve this problem sometime.I am thinking that we need a PR to output a non-verbose-mode error with a failed return code if the
patchbinary does not exist.I had the problem in a GitHub Action. While the patch could without any problem be applied on the local system it was not working on in the GitHub Action. When installing with
composer install -vvvthe error message wassh: patch: not found. With the help of https://github.com/php-actions/composer/issues/98#issuecomment-1551934062 I realized that the problem was my own Docker Image: The apt packagepatchwas missing.Sometimes the patch might be missing in Linux Use the below command to install patch and try again
sudo yum install patchI’m not sure what the github standard is compared to a regular patch file, but I started comparing the diff that was working to the one from authorize.net and noticed that the github patch for the other hotfix used an “a/” prefix on the old and a “b/” prefix on the new files. I tried adding “a/” and “b/” in front of the respective lines in my modified authorize patch file and it appears to have worked.
This
and this really saved me after a few hours of debugging why
composerwasn’t installing certain files!Removing instances of
web/wp-content/plugins/lh-hsts/in the patch file still givesCould not apply patch! Skipping. The error was: Cannot apply patch lh-hsts-get-home-url.patchandCannot apply patch Use get_home_url in lh-hsts plugin (lh-hsts-get-home-url.patch)!My patch file is in the git root along with
composer.json. The file I am trying to patch, in thelh-hstspackage, isweb/wp-content/plugins/lh-hsts/lh-hsts.php.The patch file, with relative paths compared to the package installation at
web/wp-content/plugins/lh-hsts/, is:The patch file no longer works with
patchusing paths relative to the package installation rather than the git root, where the patch file is.@ucola You shouldn’t need to create a new repo for the files. You should commit files that aren’t managed by composer to the project repository. Changes to those files should be applied directly without composer-patches.
@fgm
Very likely due to differing versions of
patchand/orgit. Thanks for the detailed information. I’ll look through it and see if there’s anything that stands out as a reason why things would be going sideways.@ataylorme The patch needs to be relative to the root of the package that you’re trying to patch (
lh-hsts). In your patch, basically just remove all instances ofweb/wp-content/plugins/lh-hsts/and it should start working again.