public function get($hash, $array = false) { $commit = $this->repository->getCommit($hash); if ($array) { return $this->commitToArray($commit); } return $commit; }
/** * Set git repo commit id to look up * * @param $commitHash string */ public function setCommit($commitHash) { try { $this->commit = $this->repository->getCommit($commitHash); } catch (GitInvalidArgumentException $e) { throw new InvalidArgumentException($e->getMessage()); } catch (GitRuntimeException $e) { throw new RuntimeException($e->getMessage()); } catch (GitReferenceNotFoundException $e) { throw new ReferenceNotFoundException($e->getMessage()); } }
/** * @return array */ public function getCommits() { $args = array('--encoding=' . StringHelper::getEncoding(), '--format=raw'); if (null !== $this->offset) { $args[] = '--skip=' . (int) $this->offset; } if (null !== $this->limit) { $args[] = '-n'; $args[] = (int) $this->limit; } if (null !== $this->revisions) { $args = array_merge($args, $this->revisions->getAsTextArray()); } else { $args[] = '--all'; } $args[] = '--'; $args = array_merge($args, $this->paths); try { $output = $this->repository->run('log', $args); } catch (ProcessException $e) { throw new ReferenceNotFoundException(sprintf('Can not find revision "%s"', implode(' ', $this->revisions->getAsTextArray())), null, $e); } $parser = new Parser\LogParser(); $parser->parse($output); $result = array(); foreach ($parser->log as $commitData) { $hash = $commitData['id']; unset($commitData['id']); $commit = $this->repository->getCommit($hash); $commit->setData($commitData); $result[] = $commit; } return $result; }