Score:0

Cannot apply patch; file not found

br flag

There is a specialized fix to a contrib theme that I am trying to apply. Because this theme is in the .gitignore file, it's incumbent upon me to generate a patch that composer can include. Please note that the dependency "cweagans/composer-patches" is required. Pantheon is using the composer.lock file and I cannot get composer update to find the target file. I built the patch file using diff and modified its headers like other successful Drupal patches. In composer.json

"patchLevel": {
        "drupal/core": "-p2",
        "drupal/dxpr_theme": "-p1"
    },
"enable-patching": "true",
    "patches": {
      "drupal/dxpr_theme": {
        "header patch": "./patches/header.patch"
      }

and the headers of header.patch

index fakehash..fakehash1 100644
--- a/js/dist/dxpr-theme-header.js
+++ b/js/dist/dxpr-theme-header.js
@@ -4,7 +4,7 @@

Since there is no git commit with this theme I faked a couple of hashes but left the line in, thx for the comment @Clive. Ensuring that in context of this theme folder I was able to successfully run the patch using patch -p1 < ../../../../patches/header.patch

In context of the Drupal project I ran: composer --verbose update ---lock

Applying patches for drupal/dxpr_theme ./patches/header.patch (header patch) patch '-p1' --no-backup-if-mismatch -d 'web/themes/contrib/dxpr_theme' < '/Users/sam/apps/myproject/patches/header.patch' patching file js/dist/dxpr-theme-header.js Reversed (or previously applied) patch detected! Assume -R? [n] Apply anyway? [n] Skipping patch.

What's curious is that the file is updated but I find no evidence in composer.lock. Perhaps it is and I don't know how it's indicated? I have removed any file with .rej, .orig and reset the target file to before any patch attempts. Same state as my successful attempt at patch by itself, apart from composer.

As mentioned, if I can get composer to update this file after patching I can then see if the composer.lock file is applying this patch.

id flag
Confirm that the `patch` command can apply your patch in the theme’s root directory. This may be closed as not pertaining directly to Drupal.
cn flag
If you look at every patch on drupal.org (and I've also looked at a few dozens custom patches across a few projects to confirm the same), they all have 2 extra lines in the header. `diff`, and the index one you mentioned. Whenever I generate custom patches I leave those lines in there, regardless, and I've never had a problem. Try restoring those first two header lines and see what happens
cn flag
If it's not that, I _think_ non-git patches might default to patch level 1, and your diff is for level 0. You could try adding `"patchLevel": {"drupal/dxpr_theme": "-p0"}` to `extra` in composer.json
id flag
Did you show us the precise output?
br flag
@Clive yes, since this theme is not in git, I added an index line with fake hashes. Did seem to improve.
br flag
```patch``` command does work in context of the theme folder. @cilefen but your comment helped.
miststudent2011 avatar
fr flag
>What's curious is that the file is updated but I find no evidence in composer.lock. Thats because it is removed in composer v2 , it was present in composer v1. There is a PR raised to reintroduce it in v2. Which is not merged yet.
Score:1
ua flag

It needs to be

"header patch": "./patches/header.patch"

and then run

composer update --lock

and it will apply the patch.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.