Skip to content

Commit

Permalink
Allow force installation of hooks
Browse files Browse the repository at this point in the history
You can now force the installation of all hooks by setting
a flag in the composer.json configuration.

"extra": {
  "captainhook": {
    "force-install": true
  }
}
  • Loading branch information
sebastianfeldmann committed May 6, 2021
1 parent 1063b4c commit def8812
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/ComposerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function installHooks(Event $event): void
$this->io->write(' <comment>plugin is disabled</comment>');
return;
}

if (getenv('CI') === 'true') {
$this->io->write(' <comment>disabling plugin due to CI-environment</comment>');
return;
Expand Down Expand Up @@ -205,15 +205,20 @@ private function runCaptainCommand(string $command): void
// Respect composer CLI settings
$ansi = $this->io->isDecorated() ? ' --ansi' : ' --no-ansi';
$interaction = $this->io->isInteractive() ? '' : ' --no-interaction';
$executable = escapeshellarg($this->executable);

// captainhook config and repository settings
$configuration = ' -c ' . escapeshellarg($this->configuration);
$repository = $command === self::COMMAND_INSTALL ? ' -g ' . escapeshellarg($this->gitDirectory) : '';
$skip = $command === self::COMMAND_INSTALL ? ' -s' : '';
$executable = escapeshellarg($this->executable);
$repository = '';
$forceOrSkip = '';

if ($command === self::COMMAND_INSTALL) {
$repository = ' -g ' . escapeshellarg($this->gitDirectory);
$forceOrSkip = $this->isForceInstall() ? ' -f' : ' -s';
}

// sub process settings
$cmd = $executable . ' ' . $command . $ansi . $interaction . $skip . $configuration . $repository;
$cmd = $executable . ' ' . $command . $ansi . $interaction . $forceOrSkip . $configuration . $repository;
$pipes = [];
$spec = [
0 => ['file', 'php://stdin', 'r'],
Expand Down Expand Up @@ -314,4 +319,15 @@ private function isPluginDisabled(): bool
$extra = $this->composer->getPackage()->getExtra();
return (bool) ($extra['captainhook']['disable-plugin'] ?? false);
}

/**
* Is a force installation configured
*
* @return bool
*/
private function isForceInstall(): bool
{
$extra = $this->composer->getPackage()->getExtra();
return (bool) ($extra['captainhook']['force-install'] ?? false);
}
}

0 comments on commit def8812

Please sign in to comment.