Gitonomy\Git\Repository::getHead PHP Method

getHead() public method

public getHead ( ) : Gitonomy\Git\Reference | Gitonomy\Git\Commit | null
return Gitonomy\Git\Reference | Gitonomy\Git\Commit | null current HEAD object or null if error occurs
    public function getHead()
    {
        $file = $this->gitDir . '/HEAD';
        if (!file_exists($file)) {
            $message = sprintf('Unable to find HEAD file ("%s")', $file);
            if (null !== $this->logger) {
                $this->logger->error($message);
            }
            if (true === $this->debug) {
                throw new RuntimeException($message);
            }
        }
        $content = trim(file_get_contents($file));
        if (null !== $this->logger) {
            $this->logger->debug('HEAD file read: ' . $content);
        }
        if (preg_match('/^ref: (.+)$/', $content, $vars)) {
            return $this->getReferences()->get($vars[1]);
        } elseif (preg_match('/^[0-9a-f]{40}$/', $content)) {
            return $this->getCommit($content);
        }
        $message = sprintf('Unexpected HEAD file content (file: %s). Content of file: %s', $file, $content);
        if (null !== $this->logger) {
            $this->logger->error($message);
        }
        if (true === $this->debug) {
            throw new RuntimeException($message);
        }
    }