Git version validation fix (#14042)

Instead of erroring because the date is empty, print the error message from git.
This commit is contained in:
Tony Murray
2022-06-14 13:36:46 -05:00
committed by GitHub
parent 1d35d9391d
commit c1a59e29e5

View File

@@ -35,6 +35,7 @@ use LibreNMS\Util\Git;
use LibreNMS\Util\Version;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;
use Symfony\Component\Process\Process;
class Updates extends BaseValidation
{
@@ -64,6 +65,13 @@ class Updates extends BaseValidation
$local_ver = Version::get()->localCommit();
$remote_ver = Version::get()->remoteCommit();
if ($local_ver['sha'] != ($remote_ver['sha'] ?? null)) {
if (empty($local_ver['date'])) {
$process = new Process(['git', 'show', '-q', '--pretty=%H|%ct'], base_path());
$process->run();
$error = rtrim($process->getErrorOutput());
$validator->fail('Failed to fetch version from local git: ' . $error);
} else {
try {
$commit_date = new DateTime('@' . $local_ver['date'], new DateTimeZone(date_default_timezone_get()));
if ($commit_date->diff(new DateTime())->days > 0) {
@@ -76,6 +84,7 @@ class Updates extends BaseValidation
$validator->fail($e->getMessage());
}
}
}
if ($local_ver['branch'] != 'master') {
if ($local_ver['branch'] == 'php53') {