Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches cannot be applied for files with CRLF line terminators #76

Open
VladyslavSikailo opened this issue Mar 9, 2021 · 2 comments
Open

Comments

@VladyslavSikailo
Copy link

VladyslavSikailo commented Mar 9, 2021

Patches cannot be applied for files with CRLF line terminators

Pre-requisites

  1. I use "vaimo/composer-patches": "4.21.1"
  2. I have "mageplaza/magento-2-seo-extension", from:
"repositories": {
    "mageplaza": {
        "type": "composer",
        "url": "https://repo.mageplaza.com"
    }
} 

To Reproduce
Steps to reproduce the behavior:

  1. Install mageplaza/magento-2-seo-extension to vendor
  2. Check that files from this module have CRLF line terminators: file -k vendor/mageplaza/magento-2-seo-extension/Plugin/SeoRender.php
  3. 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
  4. add this patch into patches list in composer.json
"extra": {
    "magento-force": "override",
    "patches": {
        "mageplaza/magento-2-seo-extension": {
            "asd": "m2-hotfixes/fix.patch"
        }
    }
},
  1. 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 Feature/post install patching #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.

@indykoning
Copy link

Have a look at: #46 (comment)
for a workaround

@chelevich
Copy link

chelevich commented Apr 13, 2021

Encountered the issue trying to patch Magento/Bundle/etc/events.xml
The vendor file has CRLF line endings in my magento/project-enterprise-edition@2.4.0 with magento/module-bundle@101.0.0

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants