TQ\Git\Repository\Repository::getObjectInfo PHP Method

getObjectInfo() public method

The information returned is an array with the following structure array( 'type' => blob|tree|commit, 'mode' => 0040000 for a tree, 0100000 for a blob, 0 otherwise, 'size' => the size )
public getObjectInfo ( string $path, string $ref = 'HEAD' ) : array
$path string The path to the object
$ref string The version ref
return array The object info
    public function getObjectInfo($path, $ref = 'HEAD')
    {
        $info = array('type' => null, 'mode' => 0, 'size' => 0);
        /** @var $result CallResult */
        $result = $this->getGit()->{'cat-file'}($this->getRepositoryPath(), array('--batch-check'), sprintf('%s:%s', $ref, $path));
        $result->assertSuccess(sprintf('Cannot cat-file "%s" at "%s" from "%s"', $path, $ref, $this->getRepositoryPath()));
        $output = trim($result->getStdOut());
        $parts = array();
        if (preg_match('/^(?<sha1>[0-9a-f]{40}) (?<type>\\w+) (?<size>\\d+)$/', $output, $parts)) {
            $mode = 0;
            switch ($parts['type']) {
                case 'tree':
                    $mode |= 040000;
                    break;
                case 'blob':
                    $mode |= 0100000;
                    break;
            }
            $info['sha1'] = $parts['sha1'];
            $info['type'] = $parts['type'];
            $info['mode'] = (int) $mode;
            $info['size'] = (int) $parts['size'];
        }
        return $info;
    }