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

patch is rejected when change is in a Drupal module.info.yml file

Open johnennewdeeson opened this issue 4 years ago • 8 comments

I am using Drupal.

I've made patches plenty of times using git before and added them to the composer.json in the normal way and never previously had a problem, patch files appear to be applied during composer operations using the -p1 option.

However, I've just made a patch that composer-patches is deciding to use a -p4 option on and it fails saying it cannot find files in the patch file.

The patch in question is here, I can't see what there is about it that makes it special: https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch

My section of composer.json that adds it looks like this:

      "drupal/paragraphs_entity_embed": {
        "https://www.drupal.org/project/paragraphs_entity_embed/issues/3004077": "https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch"
      }

johnennewdeeson avatar Apr 22 '20 08:04 johnennewdeeson

Sorry, the -p4 thing is a red herring, composer does try and do a p1 and that fails then it does other -pn, -p4 was just the last thing it did before giving up

The first error was:

  - Applying patches for drupal/paragraphs_entity_embed
    https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch (https://www.drupal.org/project/paragraphs_entity_embed/issues/3004077)
Downloading https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch
patch '-p1' --no-backup-if-mismatch -d 'docroot/modules/contrib/paragraphs_entity_embed' < '/var/folders/6k/myw8_xzn1755tjd5qrg0nbdc0000gn/T/5ea0076f487d9.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d 'docroot/modules/contrib/paragraphs_entity_embed' < '/var/folders/6k/myw8_xzn1755tjd5qrg0nbdc0000gn/T/5ea0076f487d9.patch'
patching file js/plugins/drupalparagraph/plugin.js

patching file paragraphs_entity_embed.info.yml
Hunk #1 FAILED at 9.

1 out of 1 hunk FAILED -- saving rejects to file paragraphs_entity_embed.info.yml.rej

But there's nothing wrong with the patch:

git clone --branch 8.x-1.x https://git.drupalcode.org/project/paragraphs_entity_embed.git
cd paragraphs_entity_embed
git checkout 8.x-1.0-alpha8
curl https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch | patch '-p1' --no-backup-if-mismatch

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12904  100 12904    0     0  79165      0 --:--:-- --:--:-- --:--:-- 79165
patching file js/plugins/drupalparagraph/plugin.js
patching file paragraphs_entity_embed.info.yml
patching file paragraphs_entity_embed.install
patching file paragraphs_entity_embed.routing.yml
patching file src/Controller/ParagraphsEntityEmbedController.php
patching file src/EmbeddedParagraphsForm.php
patching file src/Entity/EmbeddedParagraphs.php
patching file src/Form/ParagraphEmbedDialog.php
patching file src/Plugin/Filter/ParagraphEmbedFilter.php
patching file src/Plugin/entity_embed/EntityEmbedDisplay/EntityReferenceRevisionFieldFormatter.php

johnennewdeeson avatar Apr 22 '20 09:04 johnennewdeeson

the rejection looks like this...

***************
*** 9,11 ****
    - paragraphs
    - embed
    - entity_embed
--- 9,12 ----
    - paragraphs
    - embed
    - entity_embed
+   - entity_reference_revisions

The only thing I can think is that the info file has additional drupal packaging information in it when installed from composer, but I still think this patch should apply. The file has this at the bottom which is not in the repo:

# Information added by Drupal.org packaging script on 2019-11-19
version: '8.x-1.0-alpha8'
project: 'paragraphs_entity_embed'
datestamp: 1574173341

johnennewdeeson avatar Apr 22 '20 09:04 johnennewdeeson

OK, so it is this - if I manually add the packaging info to the bottom of the info file in the repo the same error occurs:

$ curl https://www.drupal.org/files/issues/2020-04-21/paragraphs_entity_embed-revisioning-3004077-2.patch | patch '-p1' --no-backup-if-mismatch
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 12904  100 12904    0     0  92171      0 --:--:-- --:--:-- --:--:-- 92171
patching file js/plugins/drupalparagraph/plugin.js
patching file paragraphs_entity_embed.info.yml
Hunk #1 FAILED at 9.
1 out of 1 hunk FAILED -- saving rejects to file paragraphs_entity_embed.info.yml.rej
patching file paragraphs_entity_embed.install
patching file paragraphs_entity_embed.routing.yml
patching file src/Controller/ParagraphsEntityEmbedController.php
patching file src/EmbeddedParagraphsForm.php
patching file src/Entity/EmbeddedParagraphs.php
patching file src/Form/ParagraphEmbedDialog.php
patching file src/Plugin/Filter/ParagraphEmbedFilter.php
patching file src/Plugin/entity_embed/EntityEmbedDisplay/EntityReferenceRevisionFieldFormatter.php

So - must be a Drupal thing? How do we deal with apply a patch that changes the info.yml file?

johnennewdeeson avatar Apr 22 '20 09:04 johnennewdeeson

You could use git to download the module instead of downloading the packaged version from d.o. Maybe that would help?

cweagans avatar Apr 22 '20 16:04 cweagans

Drupal projects are supposed to be managed using composer. I have the same issue.

mbomb007 avatar Apr 27 '20 16:04 mbomb007

Drupal projects are supposed to be managed using composer.

I know. Composer will either download a release tarball or clone from Git. Tell it to clone from git and you won't have the packaging information in the .info.yml.

You can set the preferred install method on a per package basis: https://getcomposer.org/doc/06-config.md#preferred-install

Try setting the install method to "source" for the package that you're having problems with.

cweagans avatar Apr 27 '20 16:04 cweagans

I'm having the same issue when applying patches on Drupal 9.0.0.

sleepinzombie avatar Jun 04 '20 20:06 sleepinzombie

Drupal projects are supposed to be managed using composer.

I know. Composer will either download a release tarball or clone from Git. Tell it to clone from git and you won't have the packaging information in the .info.yml.

You can set the preferred install method on a per package basis: https://getcomposer.org/doc/06-config.md#preferred-install

Try setting the install method to "source" for the package that you're having problems with.

Thanks for tip. Seems that it helped to patch modules through composer for me.

sakonn avatar Aug 29 '20 13:08 sakonn