composer-patches
composer-patches copied to clipboard
Issue if trying to patch file with CRLF line ending
Hi cweagans,
Recently just faced with issue stated in the title. The file I wanted to patch is using Windows standard new line characters (\r\n or CRLS). The main problem, that patch command itself stripping trailing CRs from patch so I am continuously getting different line endings error messages. To prevent this we can use --binary switch on patch command, but as automated deployment, if I am patching your Patches class, that only will be available of the next run only ... and have to re-patch your patcher every time so the patching will failing over and over again.
Could be possible to add a settings/switch to composer.patch.json to use --binary option during patch ... something like
{
"patches": {
"magento/module-email": {
"https://github.com/magento/magento2/pull/22469": "patches/vendor/magento/module-email/Model/Template.php.patch",
"settings": [
"binary": true/false(default if not present)
]
}
}
}
Thanks, Robert Szeker aka Mammouth
Faced the same issue with LF CRLF
same issue
same issue.
same issue
same issue!
same issue
same issue!
The problem is in your patch file and your editor stripping line endings.
I managed to solve this issue by creating a patch via command line, omitting PHP Storm, for example:
git diff 27706c 6fc369 > destination-dir/your-patch.patch
And it worked for me.
I'm using the latest composer patches module (1.7.2)
hi @agata-maksymiuk
The problem is in your patch file and your editor stripping line endings. I managed to solve this issue by creating a patch via command line, omitting PHP Storm, for example:
git diff 27706c 6fc369 > destination-dir/your-patch.patch
And it worked for me. I'm using the latest composer patches module (1.7.2)
the issue is not with the patch file, but with the original file: if it has other than LF line endings, the patch
command cannot apply the patch as the command itself strips trailing CRs from line endings causing the different line ending issue - not sure about command git apply
: I am about 99% sure that for integrity point of view that also checking line ending, but the CRs might not getting stripped - in additional, git apply
also having a [binary option|https://git-scm.com/docs/git-apply#Documentation/git-apply.txt---allow-binary-replacement] available which is always on for latest git
as per the 1.x the code only uses git apply
if the install path of the package is a git repo, so for private repositories patching is falling back to the more general patch
command where the line ending is getting flagged and failing to patch (understandable we are want to the patches be applied, so using "composer-exit-on-patch-failure": true
flag is mandatory) - I am assuming you patched a module installed from a git repository directly this why you patch get applied with no issue
@mamsincl Hi i have a similar problem. File in vendor have crlf line ending and my patch have lf unix style file ending. I have put --binary to vendor/cweagans/composer-patches/src/Patches.php:410 like this:
if ($patched = $this->executeCommand("patch %s --no-backup-if-mismatch --binary -d %s < %s", $patch_level, $install_path, $filename)) {
Whit this mod when run composer install i have another problem:
patch: **** malformed patch at line 10:
But my patch it's ok.
any idea ?
thanks in advance
cweagans/composer-patches version 1.7.2
@mamsincl My original file has windows style line endings (\n\r), and I've created patch file with exactly the same line endings. And it works for me. Patch is being applied with no error. Original file still has windows line endings and content is patched properly.
The error I got before was:
- Applying patches for mageplaza/module-rma
patches/composer/2.4.2-p1/mageplaza/module-rma/WP-982-webapi.patch (Webapi fix)
patch '-p1' --no-backup-if-mismatch -d '/var/www/page/vendor/mageplaza/module-rma' < '/var/www/page/patches/composer/2.4.2-p1/mageplaza/module-rma/WP-982-webapi.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d '/var/www/page/vendor/mageplaza/module-rma' < '/var/www/page/patches/composer/2.4.2-p1/mageplaza/module-rma/WP-982-webapi.patch'
patching file etc/webapi.xml
Hunk #1 FAILED at 147 (different line endings).
1 out of 1 hunk FAILED -- saving rejects to file etc/webapi.xml.rej
Or maybe I just don't understand your issue.
Hi @agata-maksymiuk, but how do you convert ?
I try convert my patch with unix2dos command, but not work.
@mrrobotisback I did not convert. I keep the same line endings in original file and in patch. And it works. I've created patch by command (listed above) and it keeps the same line delimiter in patch file. First of all I've created git repository in vendor module
git init
git add .
git commit -m "init"
then I did some changes in module (I used vim editor), commited them, and created patch from diff between commits, e.g.
git diff 27706c 6fc369 > destination-dir/name-your-patch.patch
Binary patching will be supported in main
soon. I recommend fixing your patch though.
Hi @agata-maksymiuk, but how do you convert ?
I try convert my patch with unix2dos command, but not work.
I was able to get working patch after convert by unix2dos - it's require edit the patch (by mcedit for example, etc..) and remove ^M from any patch structure line that don't related to code.