From 713ee753e4083d6d53a36a7b7942a3200cd9c2a5 Mon Sep 17 00:00:00 2001 From: SOFe Date: Fri, 27 Jan 2017 18:49:54 +0800 Subject: [PATCH] Fixed wrong git commit hash parsing, fixes #295, closes #297 (#299) --- src/pocketmine/PocketMine.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 9bae8be4d..8b9d83a97 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -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)); }