getCommit() public method

Instanciates a commit object or fetches one from the cache.
public getCommit ( string $hash ) : Gitonomy\Git\Commit
$hash string A commit hash, with a length of 40
return Gitonomy\Git\Commit
Beispiel #1
0
 public function get($hash, $array = false)
 {
     $commit = $this->repository->getCommit($hash);
     if ($array) {
         return $this->commitToArray($commit);
     }
     return $commit;
 }
Beispiel #2
0
 /**
  * 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());
     }
 }
Beispiel #3
0
 /**
  * @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;
 }