/**
  * Find branch containing the commit
  *
  * @param boolean $local  set true to try to locate a commit on local repository
  * @param boolean $remote set true to try to locate a commit on remote repository
  *
  * @return array An array of Reference\Branch
  */
 public function getIncludingBranches($local = true, $remote = true)
 {
     $arguments = array('--contains', $this->revision);
     if ($local && $remote) {
         $arguments[] = '-a';
     } elseif (!$local && $remote) {
         $arguments[] = '-r';
     } elseif (!$local && !$remote) {
         throw new InvalidArgumentException('You should a least set one argument to true');
     }
     try {
         $result = $this->repository->run('branch', $arguments);
     } catch (ProcessException $e) {
         return array();
     }
     if (!$result) {
         return array();
     }
     $branchesName = explode("\n", trim(str_replace('*', '', $result)));
     $branchesName = array_filter($branchesName, function ($v) {
         return false === StringHelper::strpos($v, '->');
     });
     $branchesName = array_map('trim', $branchesName);
     $references = $this->repository->getReferences();
     $branches = array();
     foreach ($branchesName as $branchName) {
         if (false === $local) {
             $branches[] = $references->getRemoteBranch($branchName);
         } elseif (0 === StringHelper::strrpos($branchName, 'remotes/')) {
             $branches[] = $references->getRemoteBranch(str_replace('remotes/', '', $branchName));
         } else {
             $branches[] = $references->getBranch($branchName);
         }
     }
     return $branches;
 }
Exemple #2
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;
 }