PocketMine-MP 5.23.3 git-f7687af337d001ddbcc47b8e773f014a33faa662
Loading...
Searching...
No Matches
Git.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\utils;
25
26use function str_repeat;
27use function strlen;
28use function trim;
29
30final class Git{
31
32 private function __construct(){
33 //NOOP
34 }
35
41 public static function getRepositoryState(string $dir, bool &$dirty) : ?string{
42 if(Process::execute("git -C \"$dir\" rev-parse HEAD", $out) === 0 && $out !== false && strlen($out = trim($out)) === 40){
43 if(Process::execute("git -C \"$dir\" diff --quiet") === 1 || Process::execute("git -C \"$dir\" diff --cached --quiet") === 1){ //Locally-modified
44 $dirty = true;
45 }
46 return $out;
47 }
48 return null;
49 }
50
55 public static function getRepositoryStatePretty(string $dir) : string{
56 $dirty = false;
57 $detectedHash = self::getRepositoryState($dir, $dirty);
58 if($detectedHash !== null){
59 return $detectedHash . ($dirty ? "-dirty" : "");
60 }
61 return str_repeat("00", 20);
62 }
63}
static getRepositoryStatePretty(string $dir)
Definition Git.php:55
static getRepositoryState(string $dir, bool &$dirty)
Definition Git.php:41
static execute(string $command, ?string &$stdout=null, ?string &$stderr=null)
Definition Process.php:163