composer-patches
composer-patches copied to clipboard
Unclear how bundle patches work for Magento 2
I'm trying to apply this patch: https://github.com/magento/magento2/commit/79a13b483db3bf066cda6bcb69737cec02f78d47.patch
This commit has changes in two files:
app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.phplib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
I'm trying to patch that with this config:
"patches": {
"*": {
"Patch title": {
"source": "https://github.com/magento/magento2/commit/79a13b483db3bf066cda6bcb69737cec02f78d47.patch",
"level": 5,
"targets": [
"magento/module-catalog",
"magento/framework"
]
}
}
}
This will generate the following response:
Hmm... Looks like a unified diff to me...
can't find file to patch at input line 15
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|From 79a13b483db3bf066cda6bcb69737cec02f78d47 Mon Sep 17 00:00:00 2001
|From: roman <[email protected]>
|Date: Mon, 24 Dec 2018 18:58:43 +0200
|Subject: [PATCH] MAGETWO-97081: Fixed incorrect behaviour of sync actions
|
|---
| .../ProductFrontendAction/Synchronizer.php | 62 ++++++++++---------
| .../Framework/DB/Adapter/Pdo/Mysql.php | 4 +-
| 2 files changed, 37 insertions(+), 29 deletions(-)
|
|diff --git a/app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php b/app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php
|index 7a1926cf642e..3c8d49cbdd74 100644
|--- a/app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php
|+++ b/app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php
--------------------------
No file to patch. Skipping patch.
Hunk #1 ignored at 138.
Hunk #2 ignored at 159.
2 out of 2 hunks ignored
Hmm... The next patch looks like a unified diff to me...
can't find file to patch at input line 95
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
|index 3d06e27542f0..acdc2b0f01f7 100644
|--- a/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
|+++ b/lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
--------------------------
No file to patch. Skipping patch.
Hunk #1 ignored at 2904.
1 out of 1 hunk ignored
done
Is it possible to apply such patches with this module?
The module works off of patching files that Composer packages provide. This means that the patches are basically always applied to the contents of vendor folder.
In your case I presume that you use mono-repo version of Magento (instead of using magento/product-community-edition).
In this case the following extra configuration is needed: https://github.com/vaimo/composer-patches#patches-patch-applier-cwd-options which will inform the patch applier that the patch should be applied relative to the root of the project (default CWD is the root of the vendor module).
As for the default behaviour of Bundled patch applier: it's using vendor folder as the CWD and resolve targets from the contents of the patch file.
In your situation there'll be another problem: you can't reset the patches (path:undo) because they're not provided by any Composer package that can be reinstalled.
I am using the composer packages but the patch was taken from Magento which has a different structure. I ended up creating my own patch file for this commit. Thanks for the explanation.
"patches": {
"*": {
"PRODSECBUG-2198": {
"source": "https://gist.githubusercontent.com/JeroenVanLeusden/554a8069f6109b5e84512726eacf0c50/raw/e1d9f1795e33f4653e2f60a2267f092723942bc3/PRODSECBUG-2198-2.2-CE.composer.patch",
"level": 1,
"cwd": "project"
}
}
}
Ah yes! it's based on github diff :) This actually gave me an idea :) Would be cool to be able to transform the paths in remote patch of a mono-repo to target correct packages :)
so that when downloaded, the patch paths would be transformed in the following manner ...
- app/code/Magento/Catalog/... would become magento/module-catalog/...
- lib/internal/Magento/Framework/... would become magento/framework/...
Anyhow: I'm happy that you found a solution :) Will toy around with the idea explained above.
PS: I think you can skip the "level" config as it'll try to apply it with 0-2 path stripping :) as long as the whole patch is not about file creation, it should only apply with p1 by silently :)
If path can be updated dynamically to match the composer package that would be awesome!
Also not clear to me how bundles are supposed to work with composer packages.
I even tried something like
@package magento/module-persistent
@level 1
diff --git a/module-persistent etc,etc
etc
@package magento/module-quote
@level 1
diff --git a/module-quote etc,etc
etc
Just going to make my own patch like Jeroen did