composer-patches
composer-patches copied to clipboard
Patches cannot be applied for files with CRLF line terminators
Patches cannot be applied for files with CRLF line terminators
Pre-requisites
- I use "vaimo/composer-patches": "4.21.1"
- I have "mageplaza/magento-2-seo-extension", from:
"repositories": { "mageplaza": { "type": "composer", "url": "https://repo.mageplaza.com" } }
To Reproduce Steps to reproduce the behavior:
- Install mageplaza/magento-2-seo-extension to vendor
- Check that files from this module have CRLF line terminators: file -k vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php
- Make some patch from this file: git add -f vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php -- add some changes into file git diff vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php >> m2-hotfixes/diff.patch
- add this patch into patches list in composer.json
"extra": { "magento-force": "override", "patches": { "mageplaza/magento-2-seo-extension": { "asd": "m2-hotfixes/fix.patch" } } },
- Run: composer:install to apply this patch
Expected Patch should be installed
Actual
Applying patches for mageplaza/magento-2-seo-extension (1) ~ magento/project-community-edition: m2-hotfixes/fix.patch [NEW] asd Failed to apply the patch. Halting execution! Probable causes for the failure:
PATCH
@ b/Plugin/SeoRender.php
! Hunk #1 FAILED at 365.(For full, unfiltered details please use: composer patch:apply -vvv)
Notes Looks like it happens because when I added vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php into git indexation, file becomes from CRLF to LF line terminator (becuase I have done it on Mac, but it was developed on Windows). Git showed me following warning:
warning: CRLF will be replaced by LF in vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php
And patch contains LF line terminator. But when composer:install is executed, file again becomes to CRLF.
Have a look at: https://github.com/vaimo/composer-patches/issues/46#issuecomment-769016997 for a workaround
Encountered the issue trying to patch Magento/Bundle/etc/events.xml
The vendor file has CRLF line endings in my magento/[email protected]
with magento/[email protected]
My patch file is built with LF line endings as it also contains changes for PHP files of the Magento/Bundle module and they have LF line endings.
Proposed fix: add --ignore-whitespace
option to "PATCH" applier by default into "check" and "patch" operations.
Workaround: add this option to applier manually in your composer.json
"extra": {
"patcher": {
"appliers": {
"PATCH": {
"check": {
"default": "[[bin]] -t --verbose -p{{level}} --no-backup-if-mismatch --ignore-whitespace --dry-run < {{file}}"
},
"patch": {
"default": "[[bin]] -t -p{{level}} --no-backup-if-mismatch --ignore-whitespace < {{file}}"
}
}
}
},
UPDATE: as mentioned in other thread --ignore-whitespace
does not help.
I ended up with creating a separate patch built with CRLF for etc/events.xml