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

Run composer install after adding a patch #9

Merged
merged 4 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ Example:
composer patch-add drupal/core "SA-CORE-2018-002" "https://cgit.drupalcode.org/drupal/rawdiff/?h=8.5.x&id=5ac8738fa69df34a0635f0907d661b509ff9a28f"
```

The patch add command accepts the following options.

* `--no-update` Use this option to prevent composer to update the package and apply the patch. The patch will only end
up in your `composer.json`, not `composer.lock` file.

* `--update-no-dev` Run the dependency update with the --no-dev option.

You can omit arguments for an interactive mode.

### Patch List
Expand Down
26 changes: 26 additions & 0 deletions src/Composer/PatchAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Composer\Json\JsonFile;
use Composer\Json\JsonManipulator;
use Composer\Installer;

class PatchAddCommand extends PatchBaseCommand {

Expand All @@ -17,6 +19,8 @@ protected function configure() {
new InputArgument('package', InputArgument::REQUIRED),
new InputArgument('description', InputArgument::REQUIRED),
new InputArgument('url', InputArgument::REQUIRED),
new InputOption('no-update', null, InputOption::VALUE_NONE, 'Do not run an update: as side effect patch will not be applied.'),
new InputOption('update-no-dev', null, InputOption::VALUE_NONE, 'Run the dependency update with the --no-dev option.'),
]);

parent::configure();
Expand Down Expand Up @@ -44,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$package = $input->getArgument('package');
$description = $input->getArgument('description');
$url = $input->getArgument('url');
$updateDevMode = !$input->getOption('update-no-dev');
szeidler marked this conversation as resolved.
Show resolved Hide resolved

// Validate the patch url argument.
if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
Expand Down Expand Up @@ -78,6 +83,27 @@ protected function execute(InputInterface $input, OutputInterface $output) {
file_put_contents($config->getPatchesFile(), $manipulator->getContents());

$output->writeln('The patch was successfully added.');

if (!$input->getOption('no-update')) {
// Trigger install command after adding a patch.
$install = Installer::create($this->getIO(), $this->getComposer());

// We run an update, because the patch will otherwise not end up in the
// composer.lock. Beware: This could update the package unwanted.
$install->setUpdate(TRUE)
// Forward the option
->setVerbose($input->getOption('verbose'))
// Only update the current package
->setUpdateWhitelist([$package])
// Don't update the dependencies of the patched package.
->setWhitelistTransitiveDependencies(FALSE)
->setWhitelistAllDependencies(FALSE)
// Patches are always considered to be applied in "dev mode".
// This is also required to prevent composer from removing all installed
// dev dependencies.
->setDevMode($updateDevMode)
->run();
}
}

}