public function getInformation()
{
$process = $this->exec('symbolic-ref HEAD');
if (0 !== $process->getExitCode() && stristr($process->getErrorOutput(), 'ref HEAD is not')) {
$branchName = '(unnamed branch)';
} elseif (0 === $process->getExitCode()) {
preg_match('{^refs/heads/(.*)$}', $process->getOutput(), $matches);
$branchName = $matches[1];
} else {
throw new \RuntimeException(sprintf('Encountered error when determining git branch exide code: %s, stderr: "%s"', $process->getExitCode(), $process->getErrorOutput()));
}
$commitshRef = sprintf('%s/%s/%s', getcwd(), '.git/refs/heads', $branchName);
if (!file_exists($commitshRef)) {
$version = null;
} else {
$version = trim(file_get_contents($commitshRef));
}
return new VcsInformation('git', $branchName, $version);
}