Skip to content

Commit

Permalink
Merge pull request #463 from veewee/fix-force-unix-hooks
Browse files Browse the repository at this point in the history
Force git hooks to contain unix styled commands
  • Loading branch information
veewee authored Feb 23, 2018
2 parents a93b32c + 4bb61aa commit 70e9d25
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
14 changes: 12 additions & 2 deletions spec/Process/ProcessBuilderSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,19 @@ function it_is_initializable()

function it_should_be_able_to_create_process_arguments_based_on_taskname(ExternalCommand $externalCommandLocator)
{
$externalCommandLocator->locate('grumphp')->willReturn('/usr/bin/grumphp');
$externalCommandLocator->locate('grumphp', false)->willReturn('/usr/bin/grumphp');

$arguments = $this->createArgumentsForCommand('grumphp');
$arguments = $this->createArgumentsForCommand('grumphp', false);
$arguments->shouldHaveType(ProcessArgumentsCollection::class);
$arguments[0]->shouldBe('/usr/bin/grumphp');
$arguments->count()->shouldBe(1);
}

function it_should_be_able_to_create_process_arguments_based_on_taskname_and_force_unix_path(ExternalCommand $externalCommandLocator)
{
$externalCommandLocator->locate('grumphp', true)->willReturn('/usr/bin/grumphp');

$arguments = $this->createArgumentsForCommand('grumphp', true);
$arguments->shouldHaveType(ProcessArgumentsCollection::class);
$arguments[0]->shouldBe('/usr/bin/grumphp');
$arguments->count()->shouldBe(1);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Git/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function generateHookCommand($command)
{
$configFile = $this->useExoticConfigFile();

$arguments = $this->processBuilder->createArgumentsForCommand('grumphp');
$arguments = $this->processBuilder->createArgumentsForCommand('grumphp', true);
$arguments->add($command);
$arguments->addOptionalArgument('--config=%s', $configFile);

Expand Down
15 changes: 3 additions & 12 deletions src/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ public function __construct(GrumPHP $config, ExternalCommand $externalCommandLoc

/**
* @param string $command
* @param bool $forceUnix
*
* @return ProcessArgumentsCollection
*/
public function createArgumentsForCommand($command)
public function createArgumentsForCommand($command, $forceUnix = false)
{
$executable = $this->getCommandLocation($command);
$executable = $this->externalCommandLocator->locate($command, $forceUnix);

return ProcessArgumentsCollection::forExecutable($executable);
}
Expand Down Expand Up @@ -87,16 +88,6 @@ private function guardWindowsCmdMaxInputStringLimitation(Process $process)
throw PlatformException::commandLineStringLimit($process);
}

/**
* @param string $command
*
* @return string
*/
private function getCommandLocation($command)
{
return $this->externalCommandLocator->locate($command);
}

/**
* @param Process $process
*/
Expand Down

0 comments on commit 70e9d25

Please sign in to comment.