X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGitInfo.php;h=fb75c256d6ab93871df02512d82efca26b3ecee4;hb=a620ccb99ce905d8d8afd51fce2bdb7647cad958;hp=3c600ed984057918d3a7f8c2bb07af0797e8bcbc;hpb=a8379682a46a428320c88702c800a6107c015137;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GitInfo.php b/includes/GitInfo.php index 3c600ed984..fb75c256d6 100644 --- a/includes/GitInfo.php +++ b/includes/GitInfo.php @@ -23,6 +23,8 @@ * @file */ +use MediaWiki\Shell\Shell; + class GitInfo { /** @@ -35,6 +37,11 @@ class GitInfo { */ protected $basedir; + /** + * Location of the repository + */ + protected $repoDir; + /** * Path to JSON cache file for pre-computed git information. */ @@ -56,6 +63,7 @@ class GitInfo { * @see precomputeValues */ public function __construct( $repoDir, $usePrecomputed = true ) { + $this->repoDir = $repoDir; $this->cacheFile = self::getCacheFilePath( $repoDir ); wfDebugLog( 'gitinfo', "Computed cacheFile={$this->cacheFile} for {$repoDir}" @@ -221,13 +229,22 @@ class GitInfo { is_executable( $wgGitBin ) && $this->getHead() !== false ) { - $environment = [ "GIT_DIR" => $this->basedir ]; - $cmd = wfEscapeShellArg( $wgGitBin ) . - " show -s --format=format:%ct HEAD"; - $retc = false; - $commitDate = wfShellExec( $cmd, $retc, $environment ); - if ( $retc === 0 ) { - $date = (int)$commitDate; + $cmd = [ + $wgGitBin, + 'show', + '-s', + '--format=format:%ct', + 'HEAD', + ]; + $gitDir = realpath( $this->basedir ); + $result = Shell::command( $cmd ) + ->environment( [ 'GIT_DIR' => $gitDir ] ) + ->restrict( Shell::RESTRICT_DEFAULT | Shell::NO_NETWORK ) + ->whitelistPaths( [ $gitDir, $this->repoDir ] ) + ->execute(); + + if ( $result->getExitCode() === 0 ) { + $date = (int)$result->getStdout(); } } $this->cache['headCommitDate'] = $date;