@@ -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