-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could not apply patch! Skipping. The error was: Cannot apply patch #226
Comments
Same issue |
1 similar comment
Same issue |
If you're getting "Cannot apply patch", it's likely because your patch does not apply. In this case, you're attempting to apply the patch from https://www.drupal.org/project/paragraphs/issues/2868155#comment-12261810, and it doesn't apply because it was already committed to the 8.x-1.x branch in that module repo. You don't even need that patch anymore. |
no, the problem is on a custom patch (i.e. for .htaccess) |
@ucola I was referring to the OP. For your case, I can't say for certain, but if the words "Cannot apply patch" appear in the output, it's probably because the patch doesn't apply. See if you can apply it manually with |
@cweagans thank you for your answer, the patch is very easy, you can see it here: https://drupal-patch.soul.media/drupal8/core/htaccess-003.patch and with patch it works fine...
|
The patch doesn't apply. |
@cweagans sorry my fault, i was retrying.... check now the output as first, i try to do a composer update, the output was this here
after this, i try to patch the file manually... and it works
|
Can you supply a complete composer.json that reproduces the problem? |
Of corse.... composer.json
composer.patches.json
|
@cweagans any ideas for our issue? |
The |
Realy? How we can execute a patch for the .htaccess or a robots.txt? |
Just change the file and commit it. IMO, you should do that with anything outside the |
You mean to create a own repository for this files? |
I have had a similar issue with several patches ( https://www.drupal.org/files/issues/2018-03-13/0001-Issue-2912779-by-JulienD-Drush-9-commands.patch and https://www.drupal.org/files/issues/2018-06-05/0001-Issue-2968172-by-WidgetsBurritos-fgm-Support-Drush-9.patch more specifically) appear recently, and on some instances only. They work on some machines and not others, with the same composer.json/composer.lock. When going to the module directories and doing a "git apply" with the downloaded patch files, they apply without error. Stranger then. When doing "composer install" a second time, the patches apply flawlessly. Shortened example: First pass
Checking and cleaning up
Second pass
And this time everything is OK:
NoteworthyOn the first
So apparently, the patch is applied twice failing the second time since it is already patched. And although we have a A bit laterOne thing I noticed is the fact that the problem happens when using dev branches instead of releases and applying patches to them in a later install. I that case, the module is cloned (from cache), and remains installed as a git repo. Then when the install comes from a later version which now adds a patch, the patching apparently applies once using "git apply" (and works), then (probably because it's a prefer-dist) tries to reapply it with "patch" (and fails, being already patched). So I suppose some code gets confused by having a patched dist install on top of a repository which is actually in VCS form. |
Digging around the code, I suspect the culprit is in
Apparently, in this scenario, getPatches does not detect that the component should be added to the remove list, which is needed because the format (VCS/dist) has changed between deployments. |
I am getting the same "Cannot apply patch" error, even though the patch applies with andrewtaylor:ataylorme-wordpress/ (master*) $ composer update 09/12/18 at 4:28:44
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 wpackagist-plugin/lh-hsts (1.23): Loading from cache
- Applying patches for wpackagist-plugin/lh-hsts
lh-hsts-get-home-url.patch (Use get_home_url in lh-hsts plugin)
Could not apply patch! Skipping. The error was: Cannot apply patch lh-hsts-get-home-url.patch
[Exception]
Cannot apply patch Use get_home_url in lh-hsts plugin (lh-hsts-get-home-url.patch)!
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [--with-dependencies] [--with-all-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [-i|--interactive] [--root-reqs] [--] [<packages>]...
andrewtaylor:ataylorme-wordpress/ (master*) $ patch -p1 < lh-hsts-get-home-url.patch 09/12/18 at 4:29:18
patching file web/wp-content/plugins/lh-hsts/lh-hsts.php It is a simple, one-line patch. Here are the contents
I use Composer Patches on Drupal projects without issue using patch URLs from Drupal.org. This is my first attempt to use it with a patch file I created myself. I thought the patch file might have an issue but it applies with I would use those directly but they aren't good options for either to ignore patches already applied. |
@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.
Very likely due to differing versions of @ataylorme The patch needs to be relative to the root of the package that you're trying to patch ( |
Removing instances of My patch file is in the git root along with The patch file, with relative paths compared to the package installation at
The patch file no longer works with |
I take it back - updating the patch to use paths relative to the package worked when I did the replacement with Vim. Not sure why it failed in Visual Studio Code. Thanks, @cweagans! |
For those who are looking for exact reason why the patch cannot be applied, try running
|
@aposudevsky Hey man, i got the you same error |
@aposudevsky we resolved, you right! was self-explanatory! thank you |
Haha @aposudevsky thanks !!! Sometimes it's so stupid it's even difficult to think about it :) |
Some of the time problem maybe OS does not have patch module install. |
This
and this really saved me after a few hours of debugging why |
I am thinking that we need a PR to output a non-verbose-mode error with a failed return code if the |
related/duplicate: #245 |
I recently installed this to implement one of the magento patches for v2.2.4. It worked fine for that. More recently, authorize.net released a patch for the end-of-life of the md5 hash checksum and I get this error on that patch.
I even tried rebuilding the patch manually in case there were changes in the version installed. Still same error. As I say, it works from the command line just fine:
(keep in mind, both 'patch' and 'git' are installed as it's working with the other github magento 2 patch for v2.2.4 theme change patch) |
Just a thought, I wonder if it is an issue with the composer-patches/src/Plugin/Patches.php Lines 317 to 341 in 17fe176
|
I'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. |
That makes sense, glad you got it working and thanks for posting your solution here! |
np, thanks for tolerating my frustrated testing. I'm glad it was something simple and stupid. |
For me, the issue was I had the key wrong in the composer.patches.json. Verbose output helped highlight this to me. |
I have same problem; using composer install -vvv shows me what if I have spaces in full path to patch, patch doesn't applied. |
Also if your system/image uses busybox (for example |
I have a Could not apply patch! Skipping. issue while trying to update the drupal core. That patch is mentioned in GOVCMS installation profile composer.json. Issue is patch is already applied for panelizer module and auto generated in (modules/contrib/panelizer/PATCHES.txt) . And there is a project composer file which is outside docroot using which I am trying to update drupal core. There is another patch mentioned in project's composer.json file for the panelizer module. So whenever I try to update the drupal core, panelizer module is getting deleted and trying to apply both the patches one mentioned in GOVCMS composer.json and one mentioned in project's composer.json file. I tried to remove the patch mentioned in GOVCMS composer.json file but still the issue is ther. Can any one tell me how could I remove the patch completely from GOVCMS composer.json, auto generated by cweagans/composer-patches in modules/contrib/panelizer/PATCHES.txt etc? |
I also have the same issue patching drupal/core (while phpstorm apply fine): composer.json:
|
I have removed patched from the project's composer file then govcms patch applied successfully while running updates and then didn't have to apply the patch mentioned in the project's composer file as it was covered with the govcms patch and module update. |
Just a heads up for anyone who stumbles across this issue/comment now, sometime later, like me. As of Drupal 8.8.x this is no longer true, |
I am using Drupal 9 and getting this error when trying to apply the following patch : Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2020-03-06/3109534-94.patch Below is a snippet from my composer.json file: |
UPDATE: Make 100% sure that the file path provided at the top of your .patch-file is a path relative to the module/dependency that you would like to patch. This explains why composer-patch fails to apply a patch, but doing the same via "git apply" does work. Instead of e.g. "--- a/src/vendor/name-of-module/name-of-file" the path is sufficient to be "--- a/name-of-file". |
I've run into this when trying to get patches applied in GitHub Actions, during a composer run. Although the patch command says the patches apply OK, composer thinks it returns a non-zero exit status and the composer run fails. I suspect running under docker messes with the console or stdin, or whatever is providing the shell in the docker container does not like doing redirects (could be busybox?). After some poking at it, it looks like using the The pull request is at #375 If you want to test this locally, add the git repo as a new repository in composer.json:
and then require |
I've reviewed all of the comments here, but can not solve my seemingly simple issue. Hoping some one can point me in the right direction. I need this patch to be applied with The file i'm trying to patch has CRLF line endings. My patch file does not. In the verbose output below, you can see the first attempt with -p1 option, failes due to different line endings. (also note in this first attempt, it finds the target file without issue, outputing The subsequent attempts ( -p0, -p2, -p4) all fail saying they can't find the file. I have tried many different patch file formats, including relative and absolute paths. I've also tried changing line endings on my patch file to match the target file. For whatever reason, it always seems to fail in the end with Any guidence would be greatly appreciated. Here is important output from composer install -vvv:
Here is the patch file:
|
it was solved when changed using the cmd.exe with the great git command line |
centos 8 stream, it works |
There are a lot of different issues here and many of them are now solved in |
I think the Besides that, the documentation is unclear about the support for local patches in folders + what |
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. |
Sometimes the patch might be missing in Linux |
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
The text was updated successfully, but these errors were encountered: