Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow forcing the patch level (-pX) for a particular package #101

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,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 @@ -333,9 +333,10 @@ protected function getPackageFromOperation(OperationInterface $operation) {
* @param RemoteFilesystem $downloader
* @param $install_path
* @param $patch_url
* @param $package
* @throws \Exception
*/
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url) {
protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path, $patch_url, $package) {

// Local patch file.
if (file_exists($patch_url)) {
Expand All @@ -356,6 +357,9 @@ protected function getAndApplyPatch(RemoteFilesystem $downloader, $install_path,
// p0 is next likely. p2 is extremely unlikely, but for some special cases,
// it might be useful.
$patch_levels = array('-p1', '-p0', '-p2');
if(!empty($this->composer->getPackage()->getExtra()['patchLevel'][$package->getName()])){
$patch_levels = array($this->composer->getPackage()->getExtra()['patchLevel'][$package->getName()]);
}
foreach ($patch_levels as $patch_level) {
$checked = $this->executeCommand('cd %s && GIT_DIR=. git apply --check %s %s', $install_path, $patch_level, $filename);
if ($checked) {
Expand Down