* @file
*/
+use MediaWiki\Shell\Shell;
+
class GitInfo {
/**
*/
protected $basedir;
+ /**
+ * Location of the repository
+ */
+ protected $repoDir;
+
/**
* Path to JSON cache file for pre-computed git information.
*/
* @see precomputeValues
*/
public function __construct( $repoDir, $usePrecomputed = true ) {
+ $this->repoDir = $repoDir;
$this->cacheFile = self::getCacheFilePath( $repoDir );
wfDebugLog( 'gitinfo',
"Computed cacheFile={$this->cacheFile} for {$repoDir}"
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;
$config = "{$this->basedir}/config";
$url = false;
if ( is_readable( $config ) ) {
- MediaWiki\suppressWarnings();
+ Wikimedia\suppressWarnings();
$configArray = parse_ini_file( $config, true );
- MediaWiki\restoreWarnings();
+ Wikimedia\restoreWarnings();
$remote = false;
// Use the "origin" remote repo if available or any other repo if not.