1
0
Fork 0

Make global exec execute commands in working directory

pull/8515/head
Chad Wade Day, Jr 2020-01-06 19:29:00 -08:00
parent 6034c2af01
commit 917680e0d4
2 changed files with 27 additions and 1 deletions

View File

@ -39,7 +39,7 @@ class ExecCommand extends BaseCommand
->setHelp( ->setHelp(
<<<EOT <<<EOT
Executes a vendored binary/script. Executes a vendored binary/script.
Read more at https://getcomposer.org/doc/03-cli.md#exec Read more at https://getcomposer.org/doc/03-cli.md#exec
EOT EOT
) )
@ -92,6 +92,14 @@ EOT
$output->setVerbosity(OutputInterface::VERBOSITY_QUIET); $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
} }
if (getcwd() !== $this->getApplication()->getWorkingDirectory()) {
try {
chdir($this->getApplication()->getWorkingDirectory());
} catch (\Exception $e) {
throw new \RuntimeException('Could not switch back to working directory "'.$this->getApplication()->getWorkingDirectory().'"', 0, $e);
}
}
return $dispatcher->dispatchScript('__exec_command', true, $input->getArgument('args')); return $dispatcher->dispatchScript('__exec_command', true, $input->getArgument('args'));
} }
} }

View File

@ -62,6 +62,12 @@ class Application extends BaseApplication
private $hasPluginCommands = false; private $hasPluginCommands = false;
private $disablePluginsByDefault = false; private $disablePluginsByDefault = false;
/**
* @var string Store the working directory so Composer
* can switch back to it if there are issues
*/
private $workingDirectory = '';
public function __construct() public function __construct()
{ {
static $shutdownRegistered = false; static $shutdownRegistered = false;
@ -91,6 +97,8 @@ class Application extends BaseApplication
$this->io = new NullIO(); $this->io = new NullIO();
$this->workingDirectory = getcwd();
parent::__construct('Composer', Composer::getVersion()); parent::__construct('Composer', Composer::getVersion());
} }
@ -491,4 +499,14 @@ class Application extends BaseApplication
return $commands; return $commands;
} }
/**
* Get the working directoy
*
* @return string
*/
public function getWorkingDirectory()
{
return $this->workingDirectory;
}
} }