コード例 #1
0
ファイル: VcsFileInfoTest.php プロジェクト: aburva1/vcs
 public function testGetReferenceName()
 {
     $fileInfo = new VcsFileInfo('path/to/conveyor', array('master', VcsFileInfo::BRANCH), VcsFileInfo::DIR);
     $this->assertEquals('master', $fileInfo->getReferenceName());
 }
コード例 #2
0
ファイル: AbstractSvn.php プロジェクト: aburva1/vcs
 /**
  * Returns url for a specific path
  *
  * @param  string|VcsFileInfo $path
  * @return string
  */
 public function getSvnUrl($path)
 {
     $head = $this->head;
     if ($path instanceof Reference) {
         $head = $path;
         $path = '/';
     }
     if (null === $path) {
         $path = '/';
     }
     if (is_string($path)) {
         $path = new VcsFileInfo($path, array($head->getName(), $head->getType()));
     }
     if ($path->inBranch()) {
         $branchName = $path->getReferenceName();
         if ('trunk' === $branchName) {
             $basePath = $this->basePaths['trunk'];
         } else {
             $basePath = $this->basePaths['branches'] . '/' . $branchName;
         }
     } elseif ($path->inTag()) {
         $tagName = $path->getReferenceName();
         $basePath = $this->basePaths['tags'] . '/' . $tagName;
     }
     $retval = $this->url;
     if (isset($basePath)) {
         $retval .= '/' . $basePath;
     }
     $retval .= '/' . ltrim($path->getPathname(), '/');
     $retval = rtrim($retval, '/');
     return $retval;
 }
コード例 #3
0
ファイル: AbstractTest.php プロジェクト: aburva1/vcs
 /**
  * @dataProvider existingPathProvider
  */
 public function testDiff($filename)
 {
     // first we need a checkout
     $result = $this->client->checkout($this->checkoutDir);
     // next modify a file
     $tmpfile = $this->checkoutDir . '/' . $filename;
     file_put_contents($tmpfile, uniqid(null, true));
     // added to the staged file list
     $this->client->add($filename);
     // now let's commit it
     $this->client->commit("changed file contents");
     // get the log
     $log = $this->client->log($filename);
     $firstLog = end($log);
     $firstRevision = $firstLog->getRevision();
     $diff = $this->client->diff($filename, $filename, $firstRevision);
     $file = new VcsFileInfo($filename, $this->client->getHead());
     $file->setStatus(Status::MODIFIED);
     $expected = array($file);
     $this->assertContainsOnlyInstancesOf('Webcreate\\Vcs\\Common\\VcsFileInfo', $diff);
     $this->assertEquals($expected, $diff);
 }
コード例 #4
0
ファイル: CliParser.php プロジェクト: aburva1/vcs
 /**
  * Parse the diff command output to FileInfo objects
  *
  * @param  string                                  $output
  * @param  array                                   $arguments
  * @throws \Exception
  * @return string|\Webcreate\Vcs\Common\VcsFileInfo[]
  */
 public function parseDiffOutput($output, array $arguments = array())
 {
     if (!isset($arguments['--name-status']) || false === $arguments['--name-status']) {
         // non name-status results are not supported
         return $output;
     }
     $lines = explode("\n", rtrim($output));
     $retval = array();
     foreach ($lines as $line) {
         if (preg_match('/([ACDMRTUXB])\\s+(.*)?/', $line, $matches)) {
             list($fullmatch, $x, $file) = $matches;
             $file = new VcsFileInfo($file, $this->getClient()->getHead());
             $file->setStatus($x);
             $retval[] = $file;
         } else {
             throw new \Exception('Unable to parse line "' . $line . '"');
         }
     }
     return $retval;
 }
コード例 #5
0
ファイル: CliParser.php プロジェクト: aburva1/vcs
 /**
  * Parse the Xml result from Subversion
  *
  * @param  string $output
  * @param  array  $arguments
  * @return array
  */
 protected function parseDiffOutput($output, array $arguments = array())
 {
     if (!isset($arguments['--xml']) || false === $arguments['--xml']) {
         // non xml results are not supported
         return $output;
     }
     if (!isset($arguments['--summarize']) || false === $arguments['--summarize']) {
         // non summarized results are not supported
         return $output;
     }
     $sxml = simplexml_load_string($output);
     $retval = array();
     foreach ($sxml->xpath('//path') as $item) {
         $url = (string) $item;
         $path = ltrim(str_replace($this->client->getSvnUrl(''), '', $url), '/');
         // @todo move to a Mapper class?
         $status = (string) $item->attributes()->item;
         switch ($status) {
             case "modified":
                 $status = Status::MODIFIED;
                 break;
             case "added":
                 $status = Status::ADDED;
                 break;
             case "deleted":
                 $status = Status::DELETED;
                 break;
         }
         $file = new VcsFileInfo($path, $this->getClient()->getHead());
         $file->setStatus($status);
         $retval[] = $file;
     }
     return $retval;
 }
コード例 #6
0
ファイル: Git.php プロジェクト: aburva1/vcs
 /**
  * (non-PHPdoc)
  * @see Webcreate\Vcs.VcsInterface::ls()
  */
 public function ls($path)
 {
     if (!$this->hasCheckout) {
         $this->checkout();
     }
     if ($path == '/') {
         $path = '';
     }
     if (false === file_exists($this->cwd . '/' . $path)) {
         throw new NotFoundException(sprintf('The path \'%s\' is not found in %s', $path, $this->cwd));
     }
     $finder = new Finder();
     $files = $finder->in($this->cwd . '/' . $path)->exclude(".git")->ignoreDotFiles(false)->depth('== 0');
     $filelist = array();
     $entries = array();
     foreach ($files as $file) {
         $log = $this->log(($path ? $path . '/' : '') . $file->getRelativePathname(), null, 1);
         $commit = reset($log);
         $kind = $file->isDir() ? VcsFileInfo::DIR : VcsFileInfo::FILE;
         $file = new VcsFileInfo($file->getFilename(), $this->getHead(), $kind);
         $file->setCommit($commit);
         $entries[] = $file;
     }
     return $entries;
 }