Fix selftest when run in docker
This commit is contained in:
@@ -161,6 +161,40 @@ class Website
|
||||
return $this->config['prod'];
|
||||
}
|
||||
|
||||
public function gitStatus(): array|false {
|
||||
if (file_exists('/DOCKER_GIT_INFO'))
|
||||
{
|
||||
$dgi = preg_split("/\r\n|\n|\r/", file_get_contents('/DOCKER_GIT_INFO'));
|
||||
$branch = '';
|
||||
$sha = '';
|
||||
foreach ($dgi as $line)
|
||||
{
|
||||
$split = explode('=', $line, 2);
|
||||
if (count($split) !== 2) continue;
|
||||
|
||||
if ($split[0] === 'BRANCH') { $branch = $split[1]; continue; }
|
||||
if ($split[0] === 'HASH') { $sha = $split[1]; continue; }
|
||||
}
|
||||
|
||||
if ($branch !== '' && $sha !== '') return [$branch, $sha, true];
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = shell_exec('git status 2>&1');
|
||||
$branch = shell_exec('git rev-parse --abbrev-ref HEAD');
|
||||
$sha = shell_exec('git rev-parse HEAD');
|
||||
|
||||
if ($status === false || $status === null || $status === '') return false;
|
||||
if ($branch === false || $branch === null || $branch === '') return false;
|
||||
if ($sha === false || $sha === null || $sha === '') return false;
|
||||
|
||||
$clean = (str_contains($status, 'Your branch is up to date with')) && (str_contains($status, 'nothing to commit, working tree clean'));
|
||||
|
||||
return [$branch, $sha, $clean];
|
||||
}
|
||||
}
|
||||
|
||||
public function isLoggedInByCookie()
|
||||
{
|
||||
if ($this->isLoggedIn !== null) return $this->isLoggedIn;
|
||||
|
||||
Reference in New Issue
Block a user