cweagans / composer-patches

Simple patches plugin for Composer
https://www.cweagans.net/project/composer-patches
BSD 3-Clause "New" or "Revised" License
1.52k stars 240 forks source link

Breaks with Git 2.14.0 #148

Closed joergLin closed 6 years ago

joergLin commented 7 years ago

Using Git 2.14.0 breaks appying Patches (Alpine Edge, Composer 1.5). Latest Working Version is 2.13.4.

Applying patches for drupal/core
    https://www.drupal.org/files/issues/2551373-35.patch (...)
cd 'web/core' && git --git-dir=. apply --check '-p1' '/tmp/5989b7ae422cc.patch'
warning: unable to access 'config': Is a directory
warning: unable to access 'config': Is a directory
fatal: unknown error occurred while reading the configuration files

cd 'web/core' && git --git-dir=. apply --check '-p0' '/tmp/5989b7ae422cc.patch'
warning: unable to access 'config': Is a directory

warning: unable to access 'config': Is a directory
fatal: unknown error occurred while reading the configuration files

cd 'web/core' && git --git-dir=. apply --check '-p2' '/tmp/5989b7ae422cc.patch'
warning: unable to access 'config': Is a directory
warning: unable to access 'config': Is a directory
fatal: unknown error occurred while reading the configuration files

patch '-p1' --no-backup-if-mismatch -d 'web/core' < '/tmp/5989b7ae422cc.patch'
patch: unrecognized option: no-backup-if-mismatch

BusyBox v1.25.1 (2016-10-26 16:15:20 GMT) multi-call binary.

Usage: patch [OPTIONS] [ORIGFILE [PATCHFILE]]

    -p,--strip N        Strip N leading components from file names
    -i,--input DIFF     Read DIFF instead of stdin
    -R,--reverse        Reverse patch
    -N,--forward        Ignore already applied patches
    -E,--remove-empty-files Remove output files if they become empty

patch '-p0' --no-backup-if-mismatch -d 'web/core' < '/tmp/5989b7ae422cc.patch'
patch: unrecognized option: no-backup-if-mismatch

BusyBox v1.25.1 (2016-10-26 16:15:20 GMT) multi-call binary.

Usage: patch [OPTIONS] [ORIGFILE [PATCHFILE]]

    -p,--strip N        Strip N leading components from file names
    -i,--input DIFF     Read DIFF instead of stdin
    -R,--reverse        Reverse patch
    -N,--forward        Ignore already applied patches
    -E,--remove-empty-files Remove output files if they become empty

patch '-p2' --no-backup-if-mismatch -d 'web/core' < '/tmp/5989b7ae422cc.patch'
patch: unrecognized option: no-backup-if-mismatch

BusyBox v1.25.1 (2016-10-26 16:15:20 GMT) multi-call binary.

Usage: patch [OPTIONS] [ORIGFILE [PATCHFILE]]

    -p,--strip N        Strip N leading components from file names
    -i,--input DIFF     Read DIFF instead of stdin
    -R,--reverse        Reverse patch
    -N,--forward        Ignore already applied patches
    -E,--remove-empty-files Remove output files if they become empty

   Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2551373-35.patch

In the Release Notes (https://github.com/git/git/blob/master/Documentation/RelNotes/2.14.0.txt) are changes to "gitdir" and "git apply", maybe its one of them?

cweagans commented 7 years ago

Oh boy. Thanks for reporting this. Really not looking forward to debugging this. :/

git--

andypost commented 7 years ago

yep, there's changes in git https://lkml.org/lkml/2017/8/4/481

probably

Git now avoids blindly falling back to ".git" when the setup sequence said we are not in Git repository.

tstoeckler commented 7 years ago

Was also hitting this, see PR for something that fixes this on my system

RalfEisler commented 7 years ago

Having issues installing and updating Drupal Lightning on FreeBSD

composer update -vvv
Running 1.5.2 (2017-09-11 16:59:25) with PHP 7.1.9 on FreeBSD / 10.3-RELEASE-p20

- Applying patches for drupal/core
    https://www.drupal.org/files/issues/2652138-41.patch (2652138 - ImageFormatter does not support SVGs)
Downloading https://www.drupal.org/files/issues/2652138-41.patch
cd 'docroot/core' && git --git-dir=. apply --check '-p1' '/tmp//59ca7004e02cf.patch'
Executing command (CWD): cd 'docroot/core' && git --git-dir=. apply --check '-p1' '/tmp//59ca7004e02cf.patch'
warning: unable to access 'config': Is a directory
warning: unable to access 'config': Is a directory
fatal: unknown error occurred while reading the configuration files
timcosgrove commented 7 years ago

Just adding a voice, that I'm also seeing this. Issue posted in acquia/lightning, cross-posting here: https://github.com/acquia/lightning/issues/473

I've confirmed that it does not happen under git 2.13.3, but does happen under git 2.14.1.

timcosgrove commented 7 years ago

I can also confirm, anecdotally, that https://github.com/cweagans/composer-patches/pull/152 fixes the issue I'm seeing.

danepowell commented 6 years ago

I'm also seeing these errors when running composer update -vvv, but the patches do seem to be applied correctly in the end, at least in my test cases.

Can anyone explain that discrepancy, and/or provide a clear case where these errors actually prevent a patch being applied?

This needs to be fixed regardless, but I want to understand the exact scope and severity of this bug.

RalfEisler commented 6 years ago

@danepowell

I am working with the Drupal Lightning distribution on a shared hosting provider. The actual Git-version is 2.15.0. I became aware of the problem with Git-version 2.14.3.

The problem is severe, because the projects are not maintainable on this server, which is important for small projects.

The Drupal Lightning projects are managed with Composer and the Drupal shell Drush. Composer patches are managed with cweagans/composer-patches.

Clean installations and updates fail since patches are not applied. However, I can download the patches and apply them manually.

Software: "cweagans/composer-patches": "^1.6.0", Drush Commandline Tool 9.0-dev-g809c7fc3 (global install) Drush Commandline Tool 9.0.0-beta8 (local install in the project) Composer version 1.5.2 2017-09-11 16:59:25 PHP 7.1.11 (cli) (built: Oct 30 2017 11:34:00) ( NTS )

installation-protocoll.txt

danepowell commented 6 years ago

I get the same error messages as you when running verbose composer commands, but in the end the patches do seem to be applied. I'm trying to understand why the patches are correctly applied for me but not for you (regardless of the error messages).

RalfEisler commented 6 years ago

On my installation, the patches are clearly not applied. In the above installation, I download and apply the first patch:

$ cd docroot
$ wget https://www.drupal.org/files/issues/1356276-408--8.4.x.patch
$ patch -p1 < 1356276-408--8.4.x.patch

patching.txt

All I know is comping from this post:

https://github.com/cweagans/composer-patches/pull/152

By the way:

The installation can be done with an other shared hosting provider and an old Git-version, without issues. The installations and updates run also on my local machines with older Git-versions.

danepowell commented 6 years ago

Okay I think I've figured out the discrepancy. This is an interplay between composer-patches, Git, and GNU patch.

composer-patches starts throwing errors for Git versions >= 2.14.0

However, depending on the version of GNU patch on your system, these errors may or may not actually be harmful. It appears that newer versions can recover more gracefully from this problem.

With Git 2.15.0 and Patch 2.5 (the default for Mac OS), I get errors and the patches fail to apply.

With Git 2.15.0 and Patch 2.7.5 (the default for Ubuntu), I get errors but the patches still successfully apply.

RalfEisler commented 6 years ago

uname -a

FreeBSD 10.3-RELEASE-p21 #13 r322349M: Thu Aug 10 09:47:17 UTC 2017

danepowell commented 6 years ago

See my new PR for this here, including an in-depth explanation of why patches were still applying in spite of the errors: https://github.com/cweagans/composer-patches/pull/165

Also note that this PR reveals another bug, which is that git apply probably can't be used to apply patches in this context.

danepowell commented 6 years ago

n.b. if you need to update your Patch version on Mac OS: brew install gpatch and restart your session/shell

danepowell commented 6 years ago

This may have introduced a regression for older versions of Git :(

https://github.com/cweagans/composer-patches/issues/174

pwolanin commented 6 years ago

Yes, this is causing patch install to fail on the git version from Ubuntu 16.04 git version 2.7.4

mortenson commented 6 years ago

Installing gpatch on OS X 10.12.5 didn't fix this for me, I had to upgrade to High Sierra (10.13.2).

grasmash commented 6 years ago

@pwolanin @mortenson Even when using composer-patches 1.6.4?

mortenson commented 6 years ago

@grasmash It looks like that released the day I made my comment, so I'm not sure we were on it at the time.

pwolanin commented 6 years ago

The 1.6.4 release seems to have fixed it.

RalfEisler commented 6 years ago

Unfortunately, my hosting provider will not update patch. So 1.6.4 does not fix the problem.

git version 2.15.1 patch 2.0-12u10 FreeBSD "cweagans/composer-patches": "^1.6.4"

Error messages: Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/1356276-408--8.4.3.patch etc.

danepowell commented 6 years ago

@RalfEisler it's unlikely that this bug would produce that particular error. The bug related to patch version generally fails silently. Are you absolutely sure that the patch you are referencing applies cleanly outside of Composer?

RalfEisler commented 6 years ago

Are you absolutely sure that the patch you are referencing applies cleanly outside of Composer?

@danepowell -- I am failing to clean install or update Drupal Lightning projects in a specific context. Patches are not applied.

php --version
PHP 7.1.12 (cli) (built: Dec 11 2017 19:54:55) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.1.12, Copyright (c) 1999-2017, by Zend Technologies

git version 2.15.1

patch 2.0-12u10 FreeBSD

Composer version 1.5.2 2017-09-11 16:59:25

Drupal Lightning version 2.2.5

"cweagans/composer-patches": "^1.6.4"

lightning-installation.txt

However, I could apply them manually:

wget https://www.drupal.org/files/issues/1356276-408--8.4.3.patch

patch -p1 < 1356276-408--8.4.3.patch 

patch-install.txt

danepowell commented 6 years ago

Oh it's not just the one core patch, it's every patch not applying. Yeah that seems like a bug, but you should probably open a new issue.