From d759a729fa650dbc97fde678d426799363659d2c Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Wed, 8 Nov 2017 09:47:00 -0800 Subject: [PATCH 1/2] Fixes #148: Incompatible with Git 2.14+. --- src/Patches.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Patches.php b/src/Patches.php index 55301128..722ec8da 100644 --- a/src/Patches.php +++ b/src/Patches.php @@ -383,7 +383,7 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_levels = array('-p1', '-p0', '-p2', '-p4'); foreach ($patch_levels as $patch_level) { $checked = $this->executeCommand( - 'cd %s && git --git-dir=. apply --check %s %s', + 'git -C %s apply --check %s %s', $install_path, $patch_level, $filename @@ -391,7 +391,7 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, if ($checked) { // Apply the first successful style. $patched = $this->executeCommand( - 'cd %s && git --git-dir=. apply %s %s', + 'git -C %s apply %s %s', $install_path, $patch_level, $filename From 8c8c356ac59c3a210be5a9c17c9db8b6f3468487 Mon Sep 17 00:00:00 2001 From: Dane Powell Date: Thu, 9 Nov 2017 13:18:19 -0800 Subject: [PATCH 2/2] Check for failing git apply. --- src/Patches.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Patches.php b/src/Patches.php index 722ec8da..9bdf04ff 100644 --- a/src/Patches.php +++ b/src/Patches.php @@ -382,12 +382,24 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, // it might be useful. p4 is useful for Magento 2 patches $patch_levels = array('-p1', '-p0', '-p2', '-p4'); foreach ($patch_levels as $patch_level) { + if ($this->io->isVerbose()) { + $comment = 'Testing ability to patch with git apply.'; + $comment .= ' This command may produce errors that can be safely ignored.'; + $this->io->write('' . $comment . ''); + } $checked = $this->executeCommand( - 'git -C %s apply --check %s %s', + 'git -C %s apply --check -v %s %s', $install_path, $patch_level, $filename ); + $output = $this->executor->getErrorOutput(); + if (substr($output, 0, 7) == 'Skipped') { + // Git will indicate success but silently skip patches in some scenarios. + // + // @see https://github.com/cweagans/composer-patches/pull/165 + $checked = false; + } if ($checked) { // Apply the first successful style. $patched = $this->executeCommand(