Skip to content

Commit 730f0f6

Browse files
authored
Merge pull request #171 from danepowell/issue-148-1.x
Fixes #148: Incompatible with Git 2.14+.
2 parents d011661 + 4909c4a commit 730f0f6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Patches.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,22 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path,
368368
// it might be useful. p4 is useful for Magento 2 patches
369369
$patch_levels = array('-p1', '-p0', '-p2', '-p4');
370370
foreach ($patch_levels as $patch_level) {
371-
$checked = $this->executeCommand('cd %s && git --git-dir=. apply --check %s %s', $install_path, $patch_level, $filename);
371+
if ($this->io->isVerbose()) {
372+
$comment = 'Testing ability to patch with git apply.';
373+
$comment .= ' This command may produce errors that can be safely ignored.';
374+
$this->io->write('<comment>' . $comment . '</comment>');
375+
}
376+
$checked = $this->executeCommand('git -C %s apply --check -v %s %s', $install_path, $patch_level, $filename);
377+
$output = $this->executor->getErrorOutput();
378+
if (substr($output, 0, 7) == 'Skipped') {
379+
// Git will indicate success but silently skip patches in some scenarios.
380+
//
381+
// @see https://github.com/cweagans/composer-patches/pull/165
382+
$checked = false;
383+
}
372384
if ($checked) {
373385
// Apply the first successful style.
374-
$patched = $this->executeCommand('cd %s && git --git-dir=. apply %s %s', $install_path, $patch_level, $filename);
386+
$patched = $this->executeCommand('git -C %s apply %s %s', $install_path, $patch_level, $filename);
375387
break;
376388
}
377389
}

0 commit comments

Comments
 (0)