Split out git common dir detection to handle file_get_contents error cases

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-03-31 00:01:25 +02:00
parent cb141f2092
commit 4c99a7d8f8
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889

View File

@ -497,6 +497,19 @@ class Git
return [$hash, $branch];
}
private function getCommonDirContents(string $gitFolder): ?string
{
if (! is_file($gitFolder . '/commondir')) {
return null;
}
$commonDirContents = @file_get_contents($gitFolder . '/commondir');
if ($commonDirContents === false) {
return null;
}
return trim($commonDirContents);
}
/**
* detects Git revision, if running inside repo
*/
@ -518,10 +531,9 @@ class Git
return null;
}
$common_dir_contents = @file_get_contents($gitFolder . '/commondir');
if ($common_dir_contents !== false) {
$gitFolder .= DIRECTORY_SEPARATOR . trim($common_dir_contents);
$commonDirContents = $this->getCommonDirContents($gitFolder);
if ($commonDirContents !== null) {
$gitFolder .= DIRECTORY_SEPARATOR . $commonDirContents;
}
[$hash, $branch] = $this->getHashFromHeadRef($gitFolder, $ref_head);