Gitamin\Services\Git\Repository::getBlame PHP Method

getBlame() public method

Blames the provided file and parses the output.
public getBlame ( string $file ) : array
$file string File that will be blamed
return array Commits hashes containing the lines
    public function getBlame($file)
    {
        $blame = [];
        $logs = $this->getClient()->run($this, "blame --root -sl {$file}");
        $logs = explode("\n", $logs);
        $i = 0;
        $previousCommit = '';
        foreach ($logs as $log) {
            if ($log == '') {
                continue;
            }
            preg_match_all("/([a-zA-Z0-9]{40})\\s+.*?([0-9]+)\\)(.+)/", $log, $match);
            $currentCommit = $match[1][0];
            if ($currentCommit != $previousCommit) {
                ++$i;
                $blame[$i] = ['line' => '', 'commit' => $currentCommit, 'commitShort' => substr($currentCommit, 0, 8)];
            }
            $blame[$i]['line'] .= $match[3][0] . PHP_EOL;
            $previousCommit = $currentCommit;
        }
        return $blame;
    }