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

Composer skips patches

Open ugintl opened this issue 5 years ago • 7 comments

Whenever I try to download a drupal 8 distribution which have patches, composer skips the patches. One example is the varbase distribution. I am on windows 10, Acquia Dev Desktop. Composer 1.10 and PHP 7.2

I am looking for a solution for many months. Tried everything on the web I can find. Does your plugin solves this problem?

Do I have to add this plugin in the composer.json file of the distribution?

ugintl avatar Apr 14 '20 13:04 ugintl

This plugin does apply patches to composer projects. If your composer.json doesn't already have this plugin, that's why it's not applying patches. I'd recommend trying that first (this plugin has to be near the top of the require list -- anything in the list before this plugin won't get patched). If that doesn't work, feel free to post your composer.json here and maybe I can get you pointed in the right direction.

cweagans avatar Apr 14 '20 15:04 cweagans

Here is a composer.json file of a distribution I recently tried to download.

{
  "name": "apigee/devportal-kickstart-project",
  "description": "Composer project template for the Apigee Developer Portal Drupal distribution.",
  "type": "project",
  "license": "GPL-2.0-or-later",
  "repositories": [
    {
      "type": "composer",
      "url": "https://packages.drupal.org/8"
    }
  ],
  "config": {
    "process-timeout": 0
  },
  "require": {
    "composer/installers": "^1.2",
    "cweagans/composer-patches": "^1.6.5",
    "drupal-composer/drupal-scaffold": "^2.5",
    "apigee/apigee_devportal_kickstart": "^1.0.0",
    "drupal/apigee_m10n": "^1.0.0",
    "drupal/commerce": "^2.13",
    "php": "^7.1",
    "drush/drush": "^9.7"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "scripts": {
    "post-install-cmd": [
      "DrupalComposer\\DrupalScaffold\\Plugin::scaffold"
    ],
    "post-update-cmd": [
      "DrupalComposer\\DrupalScaffold\\Plugin::scaffold"
    ],
    "quick-start": [
      "composer install",
      "php web/core/scripts/drupal quick-start apigee_devportal_kickstart"
    ]
  },
  "extra": {
    "installer-paths": {
      "web/core": ["type:drupal-core"],
      "web/libraries/{$name}": ["type:drupal-library"],
      "web/modules/contrib/{$name}": ["type:drupal-module"],
      "web/profiles/contrib/{$name}": ["type:drupal-profile"],
      "web/themes/contrib/{$name}": ["type:drupal-theme"]
    },
    "enable-patching": true
  }
}

ugintl avatar Apr 15 '20 07:04 ugintl

Here is the result after running composer command to download apigee distribution composer-install-details.txt

ugintl avatar Apr 15 '20 08:04 ugintl

I am seeing this message from a couple different modules that composer tries to patch.

$ composer update Gathering patches for root package. Removing package drupal/image_widget_crop so that it can be re-installed and re-patched. - Removing drupal/image_widget_crop (2.3.0) Deleting modules/image_widget_crop/ - deleted Removing package drupal/like_and_dislike so that it can be re-installed and re-patched. - Removing drupal/like_and_dislike (1.0.0-beta1) Deleting modules/like_and_dislike/ - deleted Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 2 installs, 0 updates, 0 removals Gathering patches for root package. Gathering patches for dependencies. This might take a minute. - Installing drupal/like_and_dislike (1.0.0-beta1): Loading from cache - Applying patches for drupal/like_and_dislike https://www.drupal.org/files/issues/2848080-2-preview-fails-on-node.patch (Fix preview on node) Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2848080-2-preview-fails-on-node.patch
  • Installing drupal/image_widget_crop (2.3.0): Loading from cache
  • Applying patches for drupal/image_widget_crop https://www.drupal.org/files/issues/2019-02-13/3032584-verticaltabs-theme-override-removal-2.patch (Remove theme function override for verticalTabs) Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2019-02-13/3032584-verticaltabs-theme-override-removal-2.patch

After doing some digging, it appears that with image_widget_crop, the patch has already been applied. This is my first encounter with patching via composer; should the patch reference be automatically removed from composer.json once it has been applied? (i.e. should I manually remove that patch reference from composer.json?)

With the like_and_dislike patch, I find

$ patch -p1 I'm unsure what this even means.

I don't know if it is of any help or not, but here is the content of the .php.rej file mentioned above.

*************** *** 39,44 **** * {@inheritdoc} */ public function build($entity_type_id, $entity_id) { $account = \Drupal::currentUser(); // Load the entity for which like and dislikes icons should be shown. $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id); --- 39,51 ---- * {@inheritdoc} */ public function build($entity_type_id, $entity_id) { + + // If either the entity type or the entity id is not set, + // return and empty array. + if (empty($entity_type_id) || empty($entity_id)) { + return []; + } + $account = \Drupal::currentUser(); // Load the entity for which like and dislikes icons should be shown. $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($entity_id);

Hoping someone can point me in the right direction here. Thanks in advance for your help.

begrafx avatar Apr 26 '20 16:04 begrafx

(i.e. should I manually remove that patch reference from composer.json?)

yes. the plugin will not do it automatically.

cweagans avatar Apr 26 '20 20:04 cweagans

OK, Thank you.

begrafx avatar Apr 26 '20 21:04 begrafx

My problem is solved finally. I did 2 things. 1. Added C:\Program Files\Git\usr\bin to my system path. 2. Used cmd as a normal user. Previously I was using it as administrator.

ugintl avatar Apr 27 '20 14:04 ugintl

In my case, I thought composer was skipping patches, however it was just that after updating to composer 2, the patches applied were no longer being written to the composer.lock file. More info here.

georgezee avatar Feb 07 '23 05:02 georgezee

This seems resolved (and the referenced issue is also resolved).

cweagans avatar Feb 07 '23 19:02 cweagans

I found this issue looking for a solution for a mysteriously silently skipped Drupal core patch. Everything looked fine, except only the last patch was getting applied ... Then it dawned on me: The patches need to be grouped under the project!

Only patch number #2 (the last patch from Drupal core project) gets applied

"patches": {
    "drupal/core": {
        "2928793: REST views encoding": "assets/patches/2928793-46-rest-views-double-encoding-apostrophes.patch"
    },
    "drupal/core": {
        "3175164: Show core modules separate": "assets/patches/3175164-10-show-core-contrib-modules-separately-4084.diff"
    },
    "drupal/admin_toolbar": {
        "3317002: Access search shortcut": "assets/patches/3317002-2-admin_toolbar-search-shortcut-accesskey-38.diff"
    },
    "drupal/glossify": {
        "3347391: Add term name as token": "assets/patches/3347391-7-glossify-term-name-as-token-12.diff"
    }
},

All Drupal core patches get applied

"patches": {
    "drupal/core": {
        "2928793: REST views encoding": "assets/patches/2928793-46-rest-views-double-encoding-apostrophes.patch",
        "3175164: Show core modules separate": "assets/patches/3175164-10-show-core-contrib-modules-separately-4084.diff"
    },
    "drupal/admin_toolbar": {
        "3317002: Access search shortcut": "assets/patches/3317002-2-admin_toolbar-search-shortcut-accesskey-38.diff"
    },
    "drupal/glossify": {
        "3347391: Add term name as token": "assets/patches/3347391-7-glossify-term-name-as-token-12.diff"
    }
},

Leaving a comment here, in case someone else does the same thing, and finds this issue.

gitressa avatar Jun 05 '23 12:06 gitressa