mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 21:59:52 +00:00
Improved git hash handling, add dirty git detection and disable automatic reporting for dirty builds
This commit is contained in:
parent
7ba807fd42
commit
6a2a74a457
@ -467,18 +467,16 @@ namespace pocketmine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$gitHash = str_repeat("00", 20);
|
$gitHash = str_repeat("00", 20);
|
||||||
if(file_exists(\pocketmine\PATH . ".git/HEAD")){ //Found Git information!
|
#ifndef COMPILE
|
||||||
$ref = trim(file_get_contents(\pocketmine\PATH . ".git/HEAD"));
|
if(\Phar::running(true) === ""){
|
||||||
if(preg_match('/^[0-9a-f]{40}$/i', $ref)){
|
if(Utils::execute("git rev-parse HEAD", $out) === 0){
|
||||||
$gitHash = strtolower($ref);
|
$gitHash = trim($out);
|
||||||
}elseif(substr($ref, 0, 5) === "ref: "){
|
if(Utils::execute("git diff --quiet") === 1 or Utils::execute("git diff --cached --quiet") === 1){ //Locally-modified
|
||||||
$refFile = \pocketmine\PATH . ".git/" . substr($ref, 5);
|
$gitHash .= "-dirty";
|
||||||
if(is_file($refFile)){
|
|
||||||
$gitHash = strtolower(trim(file_get_contents($refFile)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
define('pocketmine\GIT_COMMIT', $gitHash);
|
define('pocketmine\GIT_COMMIT', $gitHash);
|
||||||
|
|
||||||
|
|
||||||
|
@ -2159,6 +2159,11 @@ class Server{
|
|||||||
$report = false;
|
$report = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(strrpos(\pocketmine\GIT_COMMIT, "-dirty") !== false){
|
||||||
|
$this->logger->debug("Not sending crashdump due to locally modified");
|
||||||
|
$report = false; //Don't send crashdumps for locally modified builds
|
||||||
|
}
|
||||||
|
|
||||||
if($report){
|
if($report){
|
||||||
$url = ($this->getProperty("auto-report.use-https", true) ? "https" : "http") . "://" . $this->getProperty("auto-report.host", "crash.pmmp.io") . "/submit/api";
|
$url = ($this->getProperty("auto-report.use-https", true) ? "https" : "http") . "://" . $this->getProperty("auto-report.host", "crash.pmmp.io") . "/submit/api";
|
||||||
$reply = Utils::postURL($url, [
|
$reply = Utils::postURL($url, [
|
||||||
|
@ -492,4 +492,36 @@ class Utils{
|
|||||||
}
|
}
|
||||||
return $hash;
|
return $hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $command Command to execute
|
||||||
|
* @param string|null &$stdout Reference parameter to write stdout to
|
||||||
|
* @param string|null &$stderr Reference parameter to write stderr to
|
||||||
|
*
|
||||||
|
* @return int process exit code
|
||||||
|
*/
|
||||||
|
public static function execute(string $command, string &$stdout = null, string &$stderr = null) : int{
|
||||||
|
$process = proc_open($command, [
|
||||||
|
["pipe", "r"],
|
||||||
|
["pipe", "w"],
|
||||||
|
["pipe", "w"]
|
||||||
|
], $pipes);
|
||||||
|
|
||||||
|
if($process === false){
|
||||||
|
$stderr = "Failed to open process";
|
||||||
|
$stdout = "";
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$stdout = stream_get_contents($pipes[1]);
|
||||||
|
$stderr = stream_get_contents($pipes[2]);
|
||||||
|
|
||||||
|
foreach($pipes as $p){
|
||||||
|
fclose($p);
|
||||||
|
}
|
||||||
|
|
||||||
|
return proc_close($process);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user