protected function changeRepo($cachePath, $repo, $branch, $repoFilename, $name, $email, $comment, $callback)
{
$temporaryDirectory = '';
$tempRepo = '';
$hadError = false;
$command = '';
$output = '';
$outputs = [];
$trace = null;
try {
$temporaryDirectory = (new TemporaryDirectory($cachePath))->create();
$client = $this->getClient();
$repoPath = realpath($this->getPath());
$tempRepo = $temporaryDirectory->path();
$output = $client->run($this, 'clone ' . $repoPath . ' ' . $tempRepo);
$this->setPath($tempRepo);
$normalizedRepoFilePath = $this->isValidPath($tempRepo, $repoFilename, $outputs);
$filename = realpath($tempRepo . DIRECTORY_SEPARATOR . $repoFilename);
$command = "checkout $branch";
$output = $client->run($this, $command);
array_push($outputs, $output);
$message = $callback($client, $filename, $outputs, $tempRepo, $normalizedRepoFilePath);
array_push($outputs, $message);
$command = " -c \"user.name=$name\" -c \"user.email=$email\" commit -am \"$comment\" ";
$output = $client->run($this, $command);
array_push($outputs, $output);
// $command = "commit -am \"$comment\"";
// $output = $client->run($repository, $command);
$command = "push";
$output = $client->run($this, $command);
array_push($outputs, $output);
$command = " rev-parse HEAD ";
$lastCommit = $client->run($this, $command);
$result = (object)[
'status' => 'ok',
'output' => $message,
'outputs' => $outputs,
'last-commit' => $lastCommit,
'branch' => $branch,
];
return $result;
} catch (\Throwable $e) {
$hadError = $e;
} finally {
if ($temporaryDirectory !== '') {
@$temporaryDirectory->delete();
}
if ($hadError !== false) {
$message = $hadError->getMessage();
if ($message === '') {
$exceptionName = get_class($hadError);
$message = "Received exception without message with type '{$exceptionName}'. " . $hadError->getMessage();
$trace = $hadError->getTrace();
}
return ((object)[
'status' => $message === '' ? 'ok' : 'error',
'error' => $message === '' ? false : true,
//'temporaryDirectory' => $tempRepo,
'message' => $message,
//'currentdir' => getcwd(),
//'command' => $command,
'output' => $output,
'outputs' => $outputs,
'trace' => $trace,
//'$filename' => $filename,
//'$value' => $value,
]);
}
}
}
protected function isValidPath($tempRepo, $repoFilename, &$outputs)
{