Skip to content

Commit

Permalink
composer#11855 fix: add env only if bareRepository is explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-ciszewski committed May 11, 2024
1 parent c7bf2d5 commit 3dd8f75
Showing 1 changed file with 42 additions and 22 deletions.
64 changes: 42 additions & 22 deletions src/Composer/Util/ProcessExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,18 @@ public function executeTty($command, ?string $cwd = null): int

/**
* @param string|list<string> $command
* @param array<string, string>|null $env
* @param mixed $output
*/
private function doExecute($command, ?string $cwd, bool $tty, &$output = null): int
public function runProcess($command, ?string $cwd, ?array $env, bool $tty, &$output = null): ?int
{
$this->outputCommandRun($command, $cwd, false);

$this->captureOutput = func_num_args() > 3;
$this->errorOutput = '';

$env = null;

$requiresGitDirEnv = $this->requiresGitDirEnv($command);
$isBareRepository = !is_dir(sprintf('%s/.git', trim((string) $cwd, '/')));

if ($cwd !== null && $isBareRepository && $requiresGitDirEnv) {
$env = ['GIT_DIR' => $cwd];
}

if (is_string($command)) {
$process = Process::fromShellCommandline($command, $cwd, $env, null, static::getTimeout());
} else {
$process = new Process($command, $cwd, $env, null, static::getTimeout());
}

if (!Platform::isWindows() && $tty) {
if (! Platform::isWindows() && $tty) {
try {
$process->setTty(true);
} catch (RuntimeException $e) {
Expand All @@ -140,16 +127,21 @@ private function doExecute($command, ?string $cwd, bool $tty, &$output = null):
$this->outputHandler($type, $buffer);
};

$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP], function (string $signal) {
if ($this->io !== null) {
$this->io->writeError('Received '.$signal.', aborting when child process is done', true, IOInterface::DEBUG);
}
});
$signalHandler = SignalHandler::create([SignalHandler::SIGINT, SignalHandler::SIGTERM, SignalHandler::SIGHUP],
function (string $signal) {
if ($this->io !== null) {
$this->io->writeError(
'Received '.$signal.', aborting when child process is done',
true,
IOInterface::DEBUG
);
}
});

try {
$process->run($callback);

if ($this->captureOutput && !is_callable($output)) {
if ($this->captureOutput && ! is_callable($output)) {
$output = $process->getOutput();
}

Expand All @@ -166,6 +158,34 @@ private function doExecute($command, ?string $cwd, bool $tty, &$output = null):
return $process->getExitCode();
}

/**
* @param string|list<string> $command
* @param mixed $output
*/
private function doExecute($command, ?string $cwd, bool $tty, &$output = null): int
{
$this->outputCommandRun($command, $cwd, false);

$this->captureOutput = func_num_args() > 3;
$this->errorOutput = '';

$env = null;

$requiresGitDirEnv = $this->requiresGitDirEnv($command);
$isBareRepository = !is_dir(sprintf('%s/.git', trim((string) $cwd, '/')));

if ($cwd !== null && $isBareRepository && $requiresGitDirEnv) {
$configValue = null;
$this->runProcess('git config safe.bareRepository', $cwd, ['GIT_DIR' => $cwd], $tty, $configValue);
if ($configValue === 'explicit') {
$env = ['GIT_DIR' => $cwd];
}

}

return $this->runProcess($command, $cwd, $env, $tty, $output);
}

/**
* starts a process on the commandline in async mode
*
Expand Down

0 comments on commit 3dd8f75

Please sign in to comment.