Skip to content

Commit

Permalink
Allows patch-level to be specified per-project.
Browse files Browse the repository at this point in the history
- Backport to `1.x`
- Reroll of #101
- Fixes #43
  • Loading branch information
jhedstrom committed Jan 12, 2018
1 parent 9504fbd commit 49dbb8f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function postInstall(PackageEvent $event) {
$this->io->write(' <info>' . $url . '</info> (<comment>' . $description. '</comment>)');
try {
$this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::PRE_PATCH_APPLY, $package, $url, $description));
$this->getAndApplyPatch($downloader, $install_path, $url);
$this->getAndApplyPatch($downloader, $install_path, $url, $package);
$this->eventDispatcher->dispatch(NULL, new PatchEvent(PatchEvents::POST_PATCH_APPLY, $package, $url, $description));
$extra['patches_applied'][$description] = $url;
}
Expand Down Expand Up @@ -344,9 +344,10 @@ protected function getPackageFromOperation(OperationInterface $operation) {
* @param RemoteFilesystem $downloader
* @param $install_path
* @param $patch_url
* @param PackageInterface $package
* @throws \Exception
*/
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url) {
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url, PackageInterface $package) {

// Local patch file.
if (file_exists($patch_url)) {
Expand All @@ -366,6 +367,10 @@ 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');

// Check for specified patch level for this package.
if (!empty($this->composer->getPackage()->getExtra()['patchLevel'][$package->getName()])){
$patch_levels = array($this->composer->getPackage()->getExtra()['patchLevel'][$package->getName()]);
}
// Attempt to apply with git apply.
$patched = $this->applyPatchWithGit($install_path, $patch_levels, $filename);

Expand Down

0 comments on commit 49dbb8f

Please sign in to comment.