Fixed wrong git commit hash parsing, fixes #295, closes #297 (#299)

This commit is contained in:
SOFe 2017-01-27 18:49:54 +08:00 committed by Dylan K. Taylor
parent 09a6776674
commit 713ee753e4

View File

@ -470,9 +470,18 @@ namespace pocketmine {
exit(1); //Exit with error
}
if(file_exists(\pocketmine\PATH . ".git/refs/heads/master")){ //Found Git information!
define('pocketmine\GIT_COMMIT', strtolower(trim(file_get_contents(\pocketmine\PATH . ".git/refs/heads/master"))));
}else{ //Unknown :(
if(file_exists(\pocketmine\PATH . ".git/HEAD")){ //Found Git information!
$ref = trim(file_get_contents(\pocketmine\PATH . ".git/HEAD"));
if(preg_match('/^[0-9a-f]{40}$/i', $ref)){
define('pocketmine\GIT_COMMIT', strtolower($ref));
}elseif(substr($ref, 0, 5) === "ref: "){
$refFile = \pocketmine\PATH . ".git/" . substr($ref, 5);
if(is_file($refFile)){
define('pocketmine\GIT_COMMIT', strtolower(trim(file_get_contents($refFile))));
}
}
}
if(!defined('pocketmine\GIT_COMMIT')){ //Unknown :(
define('pocketmine\GIT_COMMIT', str_repeat("00", 20));
}