/** * Show the data from a specific commit * * @param string $commitHash Hash of the specific commit to read data * @return array Commit data */ public function getCommit($commitHash) { $logs = $this->getClient()->run($this, "show --pretty=format:\"<item><hash>%H</hash>" . "<short_hash>%h</short_hash><tree>%T</tree><parents>%P</parents>" . "<author>%aN</author><author_email>%aE</author_email>" . "<date>%at</date><commiter>%cN</commiter><commiter_email>%cE</commiter_email>" . "<commiter_date>%ct</commiter_date>" . "<message><![CDATA[%s]]></message>" . "<body><![CDATA[%b]]></body>" . "</item>\" {$commitHash}"); $xmlEnd = strpos($logs, '</item>') + 7; $commitInfo = substr($logs, 0, $xmlEnd); $commitData = substr($logs, $xmlEnd); $logs = explode("\n", $commitData); // Read commit metadata $format = new PrettyFormat(); $data = $format->parse($commitInfo); $commit = new Commit(); $commit->importData($data[0]); if ($commit->getParentsHash()) { $command = 'diff ' . $commitHash . '~1..' . $commitHash; $logs = explode("\n", $this->getClient()->run($this, $command)); } $commit->setDiffs($this->readDiffLogs($logs)); return $commit; }
/** * Get and parse the output of a git command with a XML-based pretty format * * @param string $command Command to be run by git * @return array Parsed command output */ public function getPrettyFormat($command) { $output = $this->getClient()->run($this, $command); $format = new PrettyFormat(); return $format->parse($output); }
/** * @expectedException RuntimeException */ public function testIsNotParsingWithoutData() { $format = new PrettyFormat(); $format->parse(''); }