Ejemplo n.º 1
0
 /**
  * get the commits path to the passed commit. Useful to count commits in a repo
  *
  * @param \GitElephant\Objects\Commit $commit commit instance
  * @param int                         $max    max count
  *
  * @throws \RuntimeException
  * @return string
  */
 public function commitPath(Commit $commit, $max = 1000)
 {
     $this->clearAll();
     $this->addCommandName(static::GIT_REVLIST);
     $this->addCommandArgument(sprintf('--max-count=%s', $max));
     $this->addCommandSubject($commit->getSha());
     return $this->getCommand();
 }
Ejemplo n.º 2
0
 /**
  * get a diff of a root commit with the empty repository
  *
  * @param \GitElephant\Objects\Commit $commit the root commit object
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @return string
  */
 public function rootDiff(Commit $commit)
 {
     if (!$commit->isRoot()) {
         throw new \InvalidArgumentException('rootDiff method accepts only root commits');
     }
     $this->clearAll();
     $this->addCommandName(static::DIFF_TREE_COMMAND);
     $this->addCommandArgument('--cc');
     $this->addCommandArgument('--root');
     $this->addCommandArgument('--dst-prefix=DST/');
     $this->addCommandArgument('--src-prefix=SRC/');
     $this->addCommandSubject($commit);
     return $this->getCommand();
 }
Ejemplo n.º 3
0
 private function parseOutputLines($outputLines, $limit)
 {
     $this->commits = array();
     $commits = Utilities::pregSplitFlatArray($outputLines, '/^[' . preg_quote('*_|\\ ') . ']+commit (\\w+)$/');
     foreach ($commits as $commitOutputLinesRaw) {
         $commitOutputLines = array();
         if (substr($commitOutputLinesRaw[0], 0, 1) != '*') {
             continue;
         }
         $shift = strpos($commitOutputLinesRaw[0], 'commit');
         foreach ($commitOutputLinesRaw as $line) {
             $commitOutputLines[] = substr($line, $shift);
         }
         $this->commits[] = Commit::createFromOutputLines($this->getRepository(), $commitOutputLines);
         if (count($this->commits) == $limit) {
             break;
         }
     }
 }
Ejemplo n.º 4
0
 public function testRevParse()
 {
     $this->getRepository()->init();
     $this->addFile('test');
     $this->repository->stage();
     $commit = Commit::create($this->repository, 'first commit', true);
     $revParse = $commit->revParse();
     $this->assertEquals($commit->getSha(), $revParse[0]);
 }
Ejemplo n.º 5
0
 private function parseOutputLines($outputLines)
 {
     $commitLines = null;
     $this->rangeCommits = array();
     foreach ($outputLines as $line) {
         if (preg_match('/^commit (\\w+)$/', $line) > 0) {
             if (null !== $commitLines) {
                 $this->rangeCommits[] = Commit::createFromOutputLines($this->getRepository(), $commitLines);
             }
             $commitLines = array();
         }
         $commitLines[] = $line;
     }
     if (null !== $commitLines && count($commitLines) > 0) {
         $this->rangeCommits[] = Commit::createFromOutputLines($this->getRepository(), $commitLines);
     }
 }
Ejemplo n.º 6
0
 /**
  * Get the revision SHA digest
  * @param boolean $short True to get only first 8 characters, false to return all 40 characters
  * @return string
  */
 public function getSHA($short = false)
 {
     return $this->commit->getSha($short);
 }
Ejemplo n.º 7
0
 protected function auditEvent(Commit $new_head, Commit $old_head = null, $by = null)
 {
     if (($fn = $this->getAuditFile()) && ($file = \fopen($fn, 'a'))) {
         // event name
         $event = '';
         if (!$old_head) {
             $event = 'INIT';
         } elseif ($new_head->getSha() == $old_head->getSha()) {
             $event = 'RESET';
         } elseif ($new_head->getDatetimeAuthor() > $old_head->getDatetimeAuthor()) {
             $event = 'UPDATE';
         } else {
             $event = 'ROLLBACK';
         }
         if ($new_head->getSha() == $this->getRepo()->getCommit($this->branch_name)) {
             $event .= ' TO LATEST';
         }
         $audit = new Audit($by ?: '-', $event, $old_head ? sprintf('%s @ %s - %s', $old_head->getSha(true), $old_head->getDatetimeAuthor()->format('Ymd_Hi'), $old_head->getMessage()) : null, sprintf('%s @ %s - %s', $new_head->getSha(true), $new_head->getDatetimeAuthor()->format('Ymd_Hi'), $new_head->getMessage()));
         \fwrite($file, $audit->serialize() . "\n");
         \fclose($file);
     }
 }
Ejemplo n.º 8
0
 private function parseOutputLines($outputLines)
 {
     $this->commits = array();
     $commits = Utilities::pregSplitFlatArray($outputLines, '/^commit (\\w+)$/');
     foreach ($commits as $commitOutputLines) {
         $this->commits[] = Commit::createFromOutputLines($this->getRepository(), $commitOutputLines);
     }
 }
Ejemplo n.º 9
0
 /**
  * count the commit to arrive to the given treeish
  *
  * @param string $start
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Process\Exception\RuntimeException
  * @return int|void
  */
 public function countCommits($start = 'HEAD')
 {
     $commit = Commit::pick($this, $start);
     return $commit->count();
 }