flash.moe/src/GitInfo.php

24 lines
680 B
PHP

<?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();
}
}