Giter Club home page Giter Club logo

composer-patches-plugin's Introduction

composer-patches-plugin

This plugin allows you to provide patches for any package from any package.

If you don't want a patch package outside the root package, consider providing it as package in the repositories key

{
    "name": "vendor/package",
    "type": "project",
    "repositories": [
        {
            "type": "package",
            "package": {
                "type": "metapackage",
                "name": "vendor/package-patches",
                "version": "1.0.0",
                "require": {
                    "netresearch/composer-patches-plugin": "~1.0"
                },
                "extra": {
                    "patches": {
                        "vendor/name": [
                            {
                                "url": "https://my-domain.com/path/to/my.patch"
                            }
                        ]
                    }
                }
            }
        }
    ],
    "require": {
        "vendor/package-patches": "~1.0"
    }
}

See this presentation for the original idea of this plugin: http://de.slideshare.net/christianopitz/distributed-patching-with-composer

Patch properties

Key Description Required
url The url or path to the patch โœ“
title Title to display when applying or reverting the patch
args string, which will be added to the patch command
sha1 SHA1 checksum of the patch contents for security check - when given the patches actual checksum and this value are compared and if they don't match an exception will be thrown

You may provide patches per package and optionally by version constraints:

Provide patches by package only

{
    "name": "netresearch/typo3-patches",
    "version": "1.0.0",
    "type": "metapackage",
    "require": {
        "netresearch/composer-patches-plugin": "~1.0"
    },
    "extra": {
        "patches": {
            "typo3/cms": [
                {
                    "title": "[FEATURE] Allow registration of different login forms",
                    "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/32f331fead9c7aa50d9248c54e3c0af75d793539"
                },
                {
                    "title": "[PATCH] [BUGFIX] Flexform \"required\" on input fields applies to last field only",
                    "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/a48f8b0dae11ce7246eff43132d986bccf55b786"
                }
            ]
        }
    }
}

Provide patches by package and versions or version constraints


composer.json:

{
    "name": "netresearch/typo3-patches",
    "version": "1.0.0",
    "type": "metapackage",
    "require": {
        "netresearch/composer-patches-plugin": "~1.0"
    },
    "extra": {
        "patches": {
            "typo3/cms":     {
                "6.2.0-beta1": [
                    {
                        "title": "[FEATURE] Allow registration of different login forms",
                        "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/32f331fead9c7aa50d9248c54e3c0af75d793539"
                    },
                    {
                        "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": [
                    {
                        "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.*": [
                    {
                        "title": "[BUGFIX] Ignore dependencies on non typo3-cms-extension",
                        "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/9fe856ac96e6a53fef8277f36a4a80bace6f0ae9",
                        "sha1": "b56a1c47a67d1596c0bd8270e61c44f8911af425"
                    }
                ]
            }
        }
    }
}

Note: When multiple version constraints match the version of the target package, all of the matching patches will be applied (canonicalized by theyr checksums, so no duplicates should occure).

Provide patches from URLs or paths

You can put any part of the patches object into another JSON and load it via an URL (or a path):

composer.json:

{
    "name": "netresearch/typo3-patches",
    "version": "1.0.0",
    "type": "metapackage",
    "require": {
        "netresearch/composer-patches-plugin": "~1.0"
    },
    "extra": {
        "patches": {
            "typo3/cms": "http://example.com/typo3-patches.json"
        }
    }
}

http://example.com/typo3-patches.json

{
    "6.2.0-beta1": [
        {
            "title": "[FEATURE] Allow registration of different login forms",
            "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/32f331fead9c7aa50d9248c54e3c0af75d793539"
        },
        {
            "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": [
        {
            "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.*": [
        {
            "title": "[BUGFIX] Ignore dependencies on non typo3-cms-extension",
            "url": "https://git.typo3.org/Packages/TYPO3.CMS.git/patch/9fe856ac96e6a53fef8277f36a4a80bace6f0ae9",
            "sha1": "b56a1c47a67d1596c0bd8270e61c44f8911af425"
        }
    ]
}

Provide patches from local stored files

You can use absolute paths or paths relative to the application root.

composer.json:

"repositories": [
        {
            "type": "package",
            "package": {
                "type": "metapackage",
                "name": "vendor/package-patches",
                "version": "1.0.0",
                "require": {
                    "netresearch/composer-patches-plugin": "~1.0"
                },
                "extra": {
                    "patches": {
                        "typo3/cms":     [
                            {
                                    "title": "[FEATURE] Allow registration of different login forms",
                                    "url": "patches/example_local_file.patch"
                            }
                        ]
                    }
                }
            }
        }
    ],
   "require": {
        ....
    },

I have also added a new folder at the same level as the composer.json called "patches" and add a patch file example_local_file.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

Requiring the patches:

just require the package with the patches.

{
    "name": "netresearch/patched-typo3",
    "type": "project",
    "description": "A patched version of typo3",
    "minimum-stability": "dev",
    "require": {
        "netresearch/typo3-patches": "~1.0",
        "typo3/cms": "6.2.0-beta3"
    }
}

composer-patches-plugin's People

Contributors

c33s avatar copitz avatar cweiske avatar cybottm avatar dooug avatar dudilag avatar gitsko avatar igormukhingmailcom avatar illyamoskvin avatar jparkinson1991 avatar kasperg avatar rednut avatar vergissberlin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

composer-patches-plugin's Issues

Already deployed patches are redeployed

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"
                }
              ]
            }
          }

Does not support Windows

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.

Support version constraints in patches configuration

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"
        }
    }
}

Applying patch results in Fatal when upgrading to 1.2.0

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.

Usage example

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?

Clear cache

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"
}
]
}

Exit code unequal 0 when patches cannot be applied

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.

Generate PATCHES.txt

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?

Apply patch to installed dependency.

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?

Add documentation about patches in local files

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

Deprecated VersionConstraint

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

patch does not have parameter --no-backup-if-mismatch on FreeBSD

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.

composer 2.x latest version support, Type error with composer 2.4.4

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?

Support for composer-plugin-api 2

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.

Patch gets applied everytime composer install is run

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. :(

Caching patch content

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

  1. add "patch repository" to required
  2. composer update - patches have been applied properly
  3. change patch A content in the "patch repository" and update main composer.json
  4. composer update
    4.a - reverting patches (caching patch content)
    4.b - changing branch / tag on "patch repository"
    4.c - apply patches (patch content is taken from the cache, not from the files - which are changed)

Use composer-patches-plugin for Magento (1)

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

GPL Licensing

I have two questions regarding licensing:

  • Was picking the GPL v2 as a license a conscious choice and if so, would you be open to/would it be possible to change that to a more permissive license (Apache, BSD)?
  • What do you consider derivative work in that context that would be affected by the derivative work clause of the GPL? The composer.json? The whole application?

Sorry for the boring questions on a Friday afternoon.

Missing a require statement

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?

Applying multiple patches to same a package results in second patch applied multiple times.

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:
Alt text

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...

Allow for a directory paramater

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.

Don't try to reapply patches on composer update

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.

Checksum compare should be case insensivite

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}'");
        }
    }

Question: How to remove a patch properly?

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).

Add patch property for fuzz value

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.