diff --git a/src/Patches.php b/src/Patches.php index 5c0c4a66..d7cb5b9e 100644 --- a/src/Patches.php +++ b/src/Patches.php @@ -289,6 +289,7 @@ public function postInstall(PackageEvent $event) { $extra = $this->composer->getPackage()->getExtra(); $exitOnFailure = getenv('COMPOSER_EXIT_ON_PATCH_FAILURE') || !empty($extra['composer-exit-on-patch-failure']); $skipReporting = getenv('COMPOSER_PATCHES_SKIP_REPORTING') || !empty($extra['composer-patches-skip-reporting']); + $removeNoBackupIfMismatch = getenv('COMPOSER_PATCHES_REMOVE_NO_BACKUP') || !empty($extra['composer-patches-remove-no-backup']); // Get the package object for the current operation. $operation = $event->getOperation(); @@ -321,7 +322,7 @@ public function postInstall(PackageEvent $event) { $this->io->write(' ' . $url . ' (' . $description. ')'); try { $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $url, $description)); - $this->getAndApplyPatch($downloader, $install_path, $url, $package); + $this->getAndApplyPatch($downloader, $install_path, $url, $package, $removeNoBackupIfMismatch); $this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::POST_PATCH_APPLY, $package, $url, $description)); $extra['patches_applied'][$description] = $url; } @@ -371,7 +372,7 @@ protected function getPackageFromOperation(OperationInterface $operation) { * @param PackageInterface $package * @throws \Exception */ - protected function getAndApplyPatch(HttpDownloader $downloader, $install_path, $patch_url, PackageInterface $package) { + protected function getAndApplyPatch(HttpDownloader $downloader, $install_path, $patch_url, PackageInterface $package, $removeNoBackupIfMismatch) { // Local patch file. if (file_exists($patch_url)) { @@ -409,8 +410,15 @@ protected function getAndApplyPatch(HttpDownloader $downloader, $install_path, $ foreach ($patch_levels as $patch_level) { // --no-backup-if-mismatch here is a hack that fixes some // differences between how patch works on windows and unix. - if ($patched = $this->executeCommand("patch %s --no-backup-if-mismatch -d %s < %s", $patch_level, $install_path, $filename)) { - break; + if($removeNoBackupIfMismatch) { + if ($patched = $this->executeCommand("patch %s -d %s < %s", $patch_level, $install_path, $filename)) { + break; + } + } + else { + if ($patched = $this->executeCommand("patch %s --no-backup-if-mismatch -d %s < %s", $patch_level, $install_path, $filename)) { + break; + } } } }