flash.moe/src/GitInfo.php

25 lines
680 B
PHP
Raw Normal View History

2023-10-12 18:45:11 +00:00
<?php
namespace Makai;
final class GitInfo {
public static function log(string $format, string $args = ''): string {
return trim(shell_exec(sprintf('git log --pretty="%s" %s -n1 HEAD', $format, $args)));
}
public static function hash(bool $long = false): string {
return self::log($long ? '%H' : '%h');
}
public static function branch(): string {
return trim(`git rev-parse --abbrev-ref HEAD`);
}
public static function tag(): string {
return trim(`git describe --abbrev=0 --tags`);
}
public static function version(): string {
return self::branch() === 'HEAD' ? self::tag() : self::hash();
}
}