netresearch / composer-patches-plugin Goto Github PK
View Code? Open in Web Editor NEWPlugin for composer to apply patches onto dependencies.
License: GNU Affero General Public License v3.0
Plugin for composer to apply patches onto dependencies.
License: GNU Affero General Public License v3.0
First of all, I have very little experience with Composer, but I couldn't find anything usefull through Google. If I'm in the wrong place, I'm sorry, but this is the only relevant place I could find.
Every time I try to Install I gain the following error:
"/usr/local/php5/bin/php" "/usr/local/bin/composer.phar" "--ansi" "--no-interaction" "install"
[RuntimeException]
Plugin netresearch/composer-patches-plugin is missing a require statement for a version of the composer-plugin-api package.
Done.
Is this an error on my part?
I'm using Version 1.2.0. I have a package that I'm applying 2 patches to. I also have a process that every time I update my code, I do a composer install. This has proven to be problematic. For reference, this is my package in composer.json... Note for simplicity sake I'm only putting part of the package def in here.
{
"type": "package",
"package": {
"name": "promet/martincounty-patches",
"version": "1.3.0",
"type": "patches",
"require": {
"drupal/google_analytics": "7.2.1",
"netresearch/composer-patches-plugin": "~1.0"
},
"extra": {
"patches": {
"drupal/google_analytics": {
"7.2.1": [
{
"title": "Fixing issue with Undefined Index: Value in googleanalytics_page_alter() Line 217",
"url": "https://www.drupal.org/files/issues/googleanalytics-2392371-10.patch"
},
{
"title": "Allow Altering of Information sent to GA",
"url": "https://www.drupal.org/files/issues/google_analytics-allow_alter_of_page_url_sent_to_ga-2571429-1.patch"
}
]
}
}
}
Since this package was updated, I've run composer install 6 times. The second patch adds one line. That line has been duplicated 6 times:
This is the -vvv output when debugging:
Downloading https://www.drupal.org/files/issues/google_analytics-allow_alter_of_page_url_sent_to_ga-2571429-1.patch
Testing patch 3944b0c7b9b7eec411804a2247aeae143a51541d on drupal/google_analytics: Fixing issue with Undefined Index: Value in googleanalytics_page_alter() Line 217
Testing patch a557a69a763f247ffa3a2321340032b9d92fec6e on drupal/google_analytics: Allow Altering of Information sent to GA
Applying patch a557a69a763f247ffa3a2321340032b9d92fec6e to drupal/google_analytics: Allow Altering of Information sent to GA
I think there is a problem in testing the patch...
Any possibility in generating a PATCHES.txt file in the base directory of every patched package?
Simple list of the urls of patches applied for easy checking when browsing the source tree?
The tool patch
does not have the parameter --no-backup-if-mismatch
on FreeBSD (10.3-p5), therefore applying patches currently fails in my production environment.
Iโm not sure if there is a reliable way of detecting that parameter besides parsing the output of patch --help
, but I also think that parameter can be totally skipped if we do a dry run before actually applying it.
When I add a patch to the list, and update the version number, all previous patches are also ran.
How can I prevent this ?
type": "package", "package": { "name": "cgk/patches", "version": "1.0.12", "type": "patches", "require": { "netresearch/composer-patches-plugin": "~1.0" }, "extra": { "patches": { "drupal/domain": { "7.3.11": [ { "title": "Fixes the bootstrap problem", "url": "https://www.drupal.org/files/issues/domain-domain-bootstrap-1342740-38.patch" } ] }, "drupal/wysiwyg": { "7.2.2": [ { "title": "Fixes the ckeditor version not found problem", "url": "https://www.drupal.org/files/wysiwyg-support_v4_ckeditor-1853550-73.patch" } ] }, "drupal/lang_dropdown": { "7.2.5": [ { "title": "Fixes the jquery update ddslick issue.", "url": "https://www.drupal.org/files/issues/lang_dropdown-ddslick-version-compare-2271459-6.patch" } ] }, "drupal/nodequeue": { "7.2.0": [ { "title": "Fixes the apachesolr_mark_node issue.", "url": "https://www.drupal.org/files/nodequeue-7.x-2.0-beat1-apachesolr-1425326-6028750.patch" } ] } }
I added a patch with a wrong url, and I updated the url, but it is never updated when updateing composer.
"drupal/drupal": {
"7.35": [
{
"title": "Fixes the ckeditor version not found 1 problem.",
"url": "./patches/locale_throwing_notice_1.patch"
}
]
}
Installation of this package under Windows fails with this error:
Maintaining patches
'which' is not recognized as an internal or external command,
operable program or batch file.
[Netresearch\Composer\Patches\Exception]
Cannot find the 'patch' executable command - use your o/s package manager like 'sudo yum install patch'
There is an alternative to which
in PowerShell: Get-Command
.
To get the path to a program this command could be used: (Get-Command patch).Source
.
Though, patch
does not exist under Windows so that could be an issue as well.
A OS independent implementation could be used, for example xdiff_file_patch
.
Hi,
I really like your Composer patch plug-in and would like to use it for my Magento projects. I created the following composer.json.
{
"name": "shopbase-magento/patches",
"version": "0.1.0",
"type": "patches",
"require": {
"netresearch/composer-patches-plugin": "~1.0"
},
"extra": {
"patches": {
"magento/core": {
"1.9.1.0": {
"SUPEE-1533_EE_1.12_v1.patch": {
"title": "SUPEE-1533 - Addresses two potential remote code execution exploits. - Added Oct 3, 2014",
"url": "http://shopbase.nl/patches/SUPEE-1533_EE_1.12_v1.patch"
},
"SUPEE-5345_CE_1.7.0.2_v1.patch": {
"title": "SUPEE-5344 - Addresses a potential remote code execution exploit. - Added Feb 9, 2015",
"url": "http://shopbase.nl/patches/SUPEE-5345_CE_1.7.0.2_v1.patch"
}
}
}
}
}
}
But I get an error when running. This is probably because Magento (1) is not fully supporting composer. I'm therefor using the 'magento-hackathon/magento-composer-installer' module.
Error:
[Netresearch\Composer\Patches\PatchCommandException]
Patch SUPEE-1533_EE_1.12_v1.patch would fail!
Error executing command "patch -f -p1 --no-backup-if-mismatch -r - --dry-ru
n":
can't find file to patch at input line 8
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|SUPEE-1533 | EE_1.12 | v1 | _ | n/a | SUPEE-1533_EE_1.12_v1.patch
|
|__PATCHFILE_FOLLOWS__
|diff --git app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php app/code
/core/Mage/Adminhtml/Block/Dashboard/Graph.php
|index c698108..6e256bb 100644
|--- app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
|+++ app/code/core/Mage/Adminhtml/Block/Dashboard/Graph.php
--------------------------
No file to patch. Skipping patch.
1 out of 1 hunk ignored
can't find file to patch at input line 21
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git app/code/core/Mage/Adminhtml/controllers/DashboardController.ph
p app/code/core/Mage/Adminhtml/controllers/DashboardController.php
|index eebb471..f9cb8d2 100644
|--- app/code/core/Mage/Adminhtml/controllers/DashboardController.php
|+++ app/code/core/Mage/Adminhtml/controllers/DashboardController.php
--------------------------
No file to patch. Skipping patch.
1 out of 1 hunk ignored
I hope you can help with this. I really would like to use your module.
Best regards,
Otto Smittenaar
Currently it is required to have an exact version number in the patch configurations - it would be great, to allow version constraints there:
This
{
"6.2.*": {
"a48f8b0dae11ce7246eff43132d986bccf55b786 ": {
"title": "[PATCH] [BUGFIX] Flexform \"required\" on input fields applies to last field only",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/a48f8b0dae11ce7246eff43132d986bccf55b786"
}
}
"6.2.0-beta1": {
"32f331fead9c7aa50d9248c54e3c0af75d793539": {
"title": "[FEATURE] Allow registration of different login forms",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/32f331fead9c7aa50d9248c54e3c0af75d793539"
}
},
}
rather than this
```javascript
{
"6.2.0-beta1": {
"32f331fead9c7aa50d9248c54e3c0af75d793539": {
"title": "[FEATURE] Allow registration of different login forms",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/32f331fead9c7aa50d9248c54e3c0af75d793539"
},
"a48f8b0dae11ce7246eff43132d986bccf55b786 ": {
"title": "[PATCH] [BUGFIX] Flexform \"required\" on input fields applies to last field only",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/a48f8b0dae11ce7246eff43132d986bccf55b786"
}
},
"6.2.0-beta2": {
"a48f8b0dae11ce7246eff43132d986bccf55b786 ": {
"title": "[PATCH] [BUGFIX] Flexform \"required\" on input fields applies to last field only",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/a48f8b0dae11ce7246eff43132d986bccf55b786"
}
},
"6.2.0-beta3": {
"a48f8b0dae11ce7246eff43132d986bccf55b786 ": {
"title": "[PATCH] [BUGFIX] Flexform \"required\" on input fields applies to last field only",
"url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/a48f8b0dae11ce7246eff43132d986bccf55b786"
}
}
}
Caching patches content cause problems with reverting / applying, when patch content is changed.
Case:
All patches are in a separate repository, which is required by main repository with project.
On main repository
Thanks for sharing your work!
I have been looking into your plugin in an attempt to use Composer for managing Drupal projects but I am having trouble deciphering how it is supposed to work.
Do you have a publicly available example of the plugin in action?
As a package manager, I will get noticed when it is not possible to apply a patch.
It should be nice to have a parameter like composer update --patches-required
.
I need that for automated updates in our CI pipeline. Some out the patches are absolutely necessary.
Run
composer status
gives us the result
[InvalidArgumentException] Package our-namespace/ourpackage-version.0 seems not been installed properly
Seems related to this issue: composer/composer#2466
How can I install a patch from a local folder, and not an url?
currently i get an error as that the checksum is not the same even it is the same but only in the wrong case. changing the case in composer.json
has not helped me (maybe a caching issue? or windows issue?).
in the end the code would be more robust if a simple case normalization is done before comparing
public function __construct(\stdClass $info, PatchSet $patchSet)
{
$this->info = $info;
$this->patchSet = $patchSet;
$this->checksum = sha1($this->read());
if (isset($this->info->sha1) && strtoupper($this->info->sha1) !== strtoupper($this->checksum)) {
throw new Exception("Expected checksum '{$this->info->sha1}' but got '{$this->checksum}'");
}
}
stumbled upon the problem that it doesn't work on my windows system because of not simply calling patch
but calling which
before. also see #27
Deprecation Notice: The Composer\Package\LinkConstraint\VersionConstraint class is deprecated, use Composer\Semver\Constraint\Constraint instead. in phar:///usr/bin/composer/src/Composer/Package/LinkConstraint/VersionConstraint.php:17
Deprecation Notice: The Composer\Package\LinkConstraint\LinkConstraintInterface interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface instead. in phar:///usr/bin/composer/src/Composer/Package/LinkConstraint/LinkConstraintInterface.php:17
When you've got a patch set and you add a new patch, composer update will try to patch all the set, instead of skipping those already applied, thus failing in the process.
A workaround for this would be to have a new package every time you add patches to the project but that's quite inconvenient.
I used composer-patches-plugin to apply some patches to a package (local patch files) and that worked as expected. Thanks so far!
My patches got merged into the package and i don't need them anymore. So i increased the packages version number, patch-package version number, removed the required patches ran composer update (deleted the .patch files too). I finally checked in the composer.lock file to make all changes fixed for deployment.
Today i wanted to update a remote installation - i merged the project source which contains the composer.lock file. When i run composer install, i get the following error:
The "patches/{package}/4b4636293ac6d46e171eaae8e64ae50ce2cd0b29.patch" file could not be downloaded: failed to open stream: No such file or directory
But the patch is not required anymore - so why does composer-patches-plugin need the .patch file?
As a workaround i can delete the local package and run composer install - this will work as expected.
The "problem" seems to be caused by the contents of "installed.json" which contained the patch-file URLs, which did not exist anymore because they are not required in the version defined in composer.lock.
So, what is the "correct" way? Simply keep the patch files in the vcs?
IMO this is not very intuitive nor logical, it may be better to store a copy of the applied patches in some local cache directory (package directory or vendor/composer or even as string value inside installed.json). That way it would be more stable and patch files could be altered as well (i guess changing a patch could also be a problem).
[Netresearch\Composer\Patches\Exception]
Cannot find the 'patch' executable command - use your o/s package manager l
ike 'sudo yum install patch'
I have two questions regarding licensing:
Sorry for the boring questions on a Friday afternoon.
with composer 2.4.4 version netresearch/composer-patches-plugin throws below error:
[TypeError]
Composer\Json\JsonFile::__construct(): Argument #2 ($httpDownloader) must be of type ?Composer\Util\HttpDownloader, Composer\Util\RemoteFilesystem given, called in /my-project/vendor/netresearch/composer-patches-plugin/src/N
etresearch/Composer/Patches/Downloader/Composer.php on line 74
What is the recommended composer version to use netresearch/composer-patches-plugin?
So far this great tool has been able to handle everything I need in patching dependencies except for one.
I am trying to apply a new patch to an already installed project dependency. I added a new patch composer.json
and ran composer update
but it does not recognise the new patch unless I remove the vendor/
directory.
Is it possible to apply a patch to an already installed project dependency?
In some cases, the patch command might need a higher fuzz value (or other arguments) to apply correctly. Currently this isn't possible, so the patch will be rejected and reverted.
I'm working on a fix for this in my fork: https://github.com/dooug/composer-patches-plugin/tree/feature-apply-patch-fuzz
The branch name is misleading, this could be used to add any additional patch command arguments with the 'args' property.
Example use: https://gist.github.com/dooug/f57ac71951b964461530
"extra": {
"patches": {
"drupal/apachesolr": {
"7.1.6": [
{
"title": "allow the sort block to show despite no/1 result.",
"url": "https://www.drupal.org/files/issues/apachesolr-expose-minimum-sort-1421510-8.patch",
"args": " -F5"
}
]
}
}
}
bad example though, I think it applies without the extra fuzz. This demonstrates the args
property though.
It would be nice if you could apply patches with the --directory
parameter. This would allow patches that are not for the root of the package (but a subpackage or something of that sort) to be applied.
When updating my package, I did a composer install and my project upgraded netresearch/composer-patches-plugin from 1.1.1 to 1.2.0. I also had an update to a patches package that I had so the patches were reinstalling. When it got to the point of installing patches, I got the following error.
==> default: PHP Fatal error: Call to undefined method Netresearch\Composer\Patches\Patch::test() in /var/www/sites/martincounty.dev/vendor/netresearch/composer-patches-plugin/src/Netresearch/Composer/Patches/Plugin.php on line 188
==> default: PHP Stack trace:
==> default: PHP 1. {main}() /usr/local/bin/composer:0
==> default: PHP 2. require() /usr/local/bin/composer:25
==> default: PHP 3. Composer\Console\Application->run() phar:///usr/local/bin/composer/bin/composer:43
==> default: PHP 4. Symfony\Component\Console\Application->run() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:82
==> default: PHP 5. Composer\Console\Application->doRun() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:126
==> default: PHP 6. Symfony\Component\Console\Application->doRun() phar:///usr/local/bin/composer/src/Composer/Console/Application.php:147
==> default: PHP 7. Symfony\Component\Console\Application->doRunCommand() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:195
==> default: PHP 8. Symfony\Component\Console\Command\Command->run() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Application.php:874
==> default: PHP 9. Composer\Command\InstallCommand->execute() phar:///usr/local/bin/composer/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:257
==> default: PHP 10. Composer\Installer->run() phar:///usr/local/bin/composer/src/Composer/Command/InstallCommand.php:131
==> default: PHP 11. Composer\EventDispatcher\EventDispatcher->dispatchScript() phar:///usr/local/bin/composer/src/Composer/Installer.php:344
==> default: PHP 12. Composer\EventDispatcher\EventDispatcher->doDispatch() phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:92
==> default: PHP 13. call_user_func() phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:152
==> default: PHP 14. Netresearch\Composer\Patches\Plugin->apply() phar:///usr/local/bin/composer/src/Composer/EventDispatcher/EventDispatcher.php:152
Simply running composer install again allowed the patches to be installed, but wanted to report it so that others who have this issue would know what to do.
When running composer-patches-plugin
with the composer v2 alpha, this is what we get
- Root composer.json requires netresearch/composer-patches-plugin == 1.2.2.0 -> satisfiable by netresearch/composer-patches-plugin[1.2.2].
- netresearch/composer-patches-plugin 1.2.2 requires composer-plugin-api ^1.0 -> found composer-plugin-api[2.0.0] but it does not match the constraint.
I've never seen this problem before, but for some reason, this patch:
https://www.drupal.org/files/issues/contact_storage-default_redirect-2629630-2.patch
gets applied everytime composer install
is run, even if's already been applied.
Here's my composer.json file:
https://github.com/phototech/sailvenice/blob/develop/composer.json
If you run composer install
the first time, it applies the patch like it's supposed to, if you run composer install
again, it will again apply the patch (which causes a PHP syntax error). :(
I'm not sure what's cuasing the problem with this patch specifically, but the only work around I've found is to delete the web/modules/contrib/contact_storage
completely and then run composer install
again. :(
I think it could be good to have an example of how to use patches in local files as it could be confusing at first.
For example, in my case, I have added a new package in composer.json
like:
"repositories": [
{
"type": "package",
"package": {
"type": "metapackage",
"name": "vendor/package-patches",
"version": "1.0.0",
"require": {
"netresearch/composer-patches-plugin": "~1.0"
},
"extra": {
"patches": {
"zohocrm/php-sdk": [
{
"title": "Corregir warning 'Array and string offset access...' en el logger.",
"url": "parches/fixzohologgerwarning.patch"
}
]
}
}
}
}
],
"require": {
....
"php-64bit": ">=7.3.0",
"zohocrm/php-sdk": "^1.1",
"vendor/package-patches": "~1.0"
},
I have also added a new folder at the same level as the composer.json
called "parches" and add a patch file fixzohologgerwarning.patch
like:
# This patch file was generated by NetBeans IDE
# It uses platform neutral UTF-8 encoding and \n newlines.
--- a/src/com/zoho/crm/library/exception/Logger.php
+++ b/src/com/zoho/crm/library/exception/Logger.php
@@ -6,7 +6,7 @@
{
set_include_path(ZCRMConfigUtil::getConfigValue('applicationLogFilePath'));
$path=get_include_path();
- if($path{strlen($path)-1}!='\/')
+ if($path[strlen($path)-1]!='\/')
{
$path=$path."/";
}
Note that the patch will be called with the option -p1
(remove the first slash) and in the directory of the library.
Then run the commands to update the dependency and to install patches:
composer update vendor/package-patches
composer install
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.