2

I have encountered a weird issue in which a patch I rolled for Commerce does not apply with Composer; it gives no errors, but the patch is not actually applied.

  "extra": {
    "patches": {
      "drupal/commerce" : {
        "Allow order types to have no cart": "https://www.drupal.org/files/issues/commerce-direct-checkout-2.2-2810723-37.patch"
      },

However, the same patch applies correctly after downloading and using the patch command:

/web/modules/contrib/commerce$ patch -p1 < ../../../../patches/commerce-direct-checkout-2.2-2810723-37.patch
patching file modules/cart/src/Form/AddToCartForm.php
patching file modules/cart/tests/src/Functional/AddToCartFormTest.php
patching file modules/cart/tests/src/Functional/CartBrowserTestBase.php
patching file modules/product/config/schema/commerce_product.schema.yml
patching file modules/product/src/Plugin/Field/FieldFormatter/AddToCartFormatter.php
patching file modules/product/src/ProductLazyBuilders.php

What is wrong with my patch that makes it fail in Composer?

2
  • That is a weird issue. I added your patch in my composer.json file and it was applied correctly. I noticed that you have a comma at the end of the drupal/commerce patch entry in your composer.json and am assuming you have other patches. Do they get applied correctly with composer?
    – Evil E
    Dec 7, 2017 at 6:15
  • @Patrick Kenny if below answer doesn't work for you try to remove /web from patch file when applying with composer since it tries to apply it based on Drupal/core repo Nov 14, 2019 at 15:25

2 Answers 2

3

It turns out this is an issue with Drupal patches for composer when using an older version of Git. The problem is with composer-patches 1.6.3.

Three possible solutions for now until the bug gets fixed.

Force 1.6.2

In composer.json, specify 1.6.2:

"require": {
"composer/installers": "^1.0.20",
"cweagans/composer-patches": "1.6.2",

Force git clone with 1.6.3

In composer.json, instead of "dist", use "source":

"config": {
    "preferred-install": "source"
  },

Update git to the latest version

1

The above didn't work for me but I debugged this issue by running composer install -v for verbosity.

It will show you, for example that it is running the command

patch '-p1' --no-backup-if-mismatch -d 'web/core' < '/my/path/to/patch.patch'

I believe the -d indicates that we are running the patch from the web/core directory. When I look at this patch it looked like:

diff --git a/web/core/modules/quickedit/js/quickedit.js b/web/core/modules/quickedit/js/quickedit.js
index 4548c013a..f930746b3 100644
--- a/web/core/modules/quickedit/js/quickedit.js
+++ b/web/core/modules/quickedit/js/quickedit.js
@@ -170,7 +170,10 @@
   // code here

The a/b indicates the location of the files to patch. Since we are already in the web/core folder, it cannot find the web/core directory inside there and so fails. If we edit those two lines without that in there, it worked. ie

diff --git a/web/core/modules/quickedit/js/quickedit.js b/web/core/modules/quickedit/js/quickedit.js
index 4548c013a..f930746b3 100644
--- a/modules/quickedit/js/quickedit.js
+++ b/modules/quickedit/js/quickedit.js
@@ -170,7 +170,10 @@
// code here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.