[Debug] Try/catch so that page loads normally in case git can't be executed on host

这个提交包含在:
Andreas 2023-07-14 23:29:54 +02:00
父节点 67b8332904
当前提交 36585d12f6

查看文件

@ -165,34 +165,39 @@
</div> </div>
<?php if (file_exists('.git')) { ?> <?php if (file_exists('.git')) { ?>
<?php <?php
$commitHash = trim(exec('git log --pretty="%H" -n1 HEAD')); //Below is a failsafe where git commands fail
$branch = ''; try {
$remote = ''; $commitHash = trim(exec('git log --pretty="%H" -n1 HEAD'));
$owner = ''; $branch = '';
// only proceed here if git can actually be executed $remote = '';
if ($commitHash != "") { $owner = '';
$commitDate = trim(exec('git log --pretty="%ci" -n1 HEAD')); // only proceed here if git can actually be executed
$line = trim(exec('git log -n 1 --pretty=%D HEAD')); if ($commitHash != "") {
$pieces = explode(', ', $line); $commitDate = trim(exec('git log --pretty="%ci" -n1 HEAD'));
$lastFetch = trim(exec('stat -c %Y .git/FETCH_HEAD')); $line = trim(exec('git log -n 1 --pretty=%D HEAD'));
//Below is a failsafe for systems without the stat command $pieces = explode(', ', $line);
try { $lastFetch = trim(exec('stat -c %Y .git/FETCH_HEAD'));
$dt = new DateTime("@$lastFetch"); //Below is a failsafe for systems without the stat command
} catch(Exception $e) { try {
$dt = new DateTime(date("Y-m-d H:i:s")); $dt = new DateTime("@$lastFetch");
} } catch(Exception $e) {
if (isset($pieces[1])) { $dt = new DateTime(date("Y-m-d H:i:s"));
$remote = substr($pieces[1], 0, strpos($pieces[1], '/'));
$branch = substr($pieces[1], strpos($pieces[1], '/')+1);
$url = trim(exec('git remote get-url '.$remote));
if (strpos($url, 'https://github.com') !== false) {
$owner = preg_replace('/https:\/\/github\.com\/(\w+)\/Cloudlog\.git/', '$1', $url);
} else if (strpos($url, 'git@github.com') !== false) {
$owner = preg_replace('/git@github\.com:(\w+)\/Cloudlog\.git/', '$1', $url);
} }
if (isset($pieces[1])) {
$remote = substr($pieces[1], 0, strpos($pieces[1], '/'));
$branch = substr($pieces[1], strpos($pieces[1], '/')+1);
$url = trim(exec('git remote get-url '.$remote));
if (strpos($url, 'https://github.com') !== false) {
$owner = preg_replace('/https:\/\/github\.com\/(\w+)\/Cloudlog\.git/', '$1', $url);
} else if (strpos($url, 'git@github.com') !== false) {
$owner = preg_replace('/git@github\.com:(\w+)\/Cloudlog\.git/', '$1', $url);
}
}
$tag = trim(exec('git describe --tags '.$commitHash));
} }
$tag = trim(exec('git describe --tags '.$commitHash)); } catch (\Throwable $th) {
} $commitHash = "";
}
?> ?>
<?php if($commitHash != "") { ?> <?php if($commitHash != "") { ?>