Skip to content

Commit

Permalink
Merge pull request #36 from phenaproxima/master
Browse files Browse the repository at this point in the history
Dependencies' patches are ignored if the root package does not define any
  • Loading branch information
cweagans committed Mar 28, 2016
2 parents 972fac4 + 568b8b5 commit 8de7c73
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public static function getSubscribedEvents() {
* @param Event $event
*/
public function checkPatches(Event $event) {
if (!$this->isPatchingEnabled()) {
return;
}

try {
$repositoryManager = $this->composer->getRepositoryManager();
$localRepository = $repositoryManager->getLocalRepository();
Expand Down Expand Up @@ -133,11 +137,14 @@ public function gatherPatches(PackageEvent $event) {
if (isset($this->patches['_patchesGathered'])) {
return;
}
// If patching has been disabled, bail out here.
elseif (!$this->isPatchingEnabled()) {
return;
}

$this->patches = $this->grabPatches();
if ($this->patches == FALSE) {
if (empty($this->patches)) {
$this->io->write('<info>No patches supplied.</info>');
return;
}

// Now add all the patches from dependencies that will be installed.
Expand Down Expand Up @@ -217,7 +224,7 @@ public function grabPatches() {
}
}
else {
return FALSE;
return array();
}
}

Expand Down Expand Up @@ -356,6 +363,25 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path,
}
}

/**
* Checks if the root package enables patching.
*
* @return bool
* Whether patching is enabled. Defaults to TRUE.
*/
protected function isPatchingEnabled() {
$extra = $this->composer->getPackage()->getExtra();

if (empty($extra['patches'])) {
// The root package has no patches of its own, so only allow patching if
// it has specifically opted in.
return isset($extra['enable-patching']) ? $extra['enable-patching'] : FALSE;
}
else {
return TRUE;
}
}

/**
* Writes a patch report to the target directory.
*
Expand Down

0 comments on commit 8de7c73

Please sign in to comment.