/**
  * @Then file :file should be staged for commit
  */
 public function fileShouldBeStagedForCommit($file)
 {
     $status = $this->repository->getStatus();
     $added = $status->added();
     $matched = $added->filter(function (StatusFile $addedFile) use($file) {
         return $addedFile->getName() === $file;
     });
     if (count($matched) !== 1) {
         throw new \UnexpectedValueException('Failed to located added file');
     }
 }
Exemplo n.º 2
0
 /**
  * rev-parse command - often used to return a commit tag.
  *
  * @param array         $options the options to apply to rev-parse
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  * @throws \Symfony\Component\Process\Exception\RuntimeException
  * @return array
  */
 public function revParse(array $options = array())
 {
     $c = RevParseCommand::getInstance()->revParse($this, $options);
     $caller = $this->repository->getCaller();
     $caller->execute($c);
     return array_map('trim', $caller->getOutputLines(true));
 }
Exemplo n.º 3
0
 /**
  * get output lines from git-remote show [name]
  *
  * NOTE: for technical reasons $name is optional, however under normal
  * implementation it SHOULD be passed!
  *
  * @param string        $name         Name of remote to show details
  * @param RemoteCommand $remoteCmd    Optionally provide RemoteCommand object
  * @param bool          $queryRemotes Do not fetch new information from remotes
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Process\Exception\LogicException
  * @throws \Symfony\Component\Process\Exception\InvalidArgumentException
  * @throws \Symfony\Component\Process\Exception\RuntimeException
  * @return array
  */
 public function getShowOutput($name = null, RemoteCommand $remoteCmd = null, $queryRemotes = true)
 {
     if (!$remoteCmd) {
         $remoteCmd = RemoteCommand::getInstance($this->repository);
     }
     $command = $remoteCmd->show($name, $queryRemotes);
     return $this->repository->getCaller()->execute($command)->getOutputLines(true);
 }
Exemplo n.º 4
0
 public function getRemotes($queryRemotes = true)
 {
     $retval = [];
     foreach (parent::getRemotes($queryRemotes) as $r) {
         /** @var $r Remote */
         $retval[$r->getName()] = $r;
     }
     return $retval;
 }
Exemplo n.º 5
0
 /**
  * @Given I tag :tag with message :message
  */
 public function iTagWithMessage($tag, $message)
 {
     $this->repo->createTag($tag, null, $message);
 }
Exemplo n.º 6
0
 public function run()
 {
     if ($this->templateType === self::TEMPLATE_TYPE_DIR) {
         $cakeJson = $this->join(realpath($this->template), 'cheesecake.json');
     } elseif ($this->templateType === self::TEMPLATE_TYPE_REMOTE_GIT) {
         $repo = Repository::createFromRemote($this->template);
         $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json');
     } elseif ($this->templateType === self::TEMPLATE_TYPE_LOCAL_GIT) {
         $repo = Repository::open($this->template);
         $cakeJson = $this->join(realpath($repo->getPath()), 'cheesecake.json');
     } else {
         throw new CheesecakeUnknownTemplateException();
     }
     if (!file_exists($cakeJson)) {
         throw new CheesecakeNotFoundExeption();
     }
     $replace = [];
     $args = json_decode(file_get_contents($cakeJson), true);
     // Detect if we need the cli promt
     $diff = array_diff(array_keys($args), array_keys($this->params));
     if (count($diff) > 0 && false === $this->noInteraction) {
         foreach ($args as $key => $value) {
             // :S
             $args[$key] = cli\prompt($key, $value, $marker = ' : ');
         }
     } else {
         // Merge constructor params with cheesecake.json
         $args = array_merge($args, $this->params);
     }
     $replace = ['cheesecake' => $args];
     $tmpDir = $this->join(sys_get_temp_dir(), sha1(uniqid()));
     if (!$this->fs->copyDirectory($this->template, $tmpDir)) {
         throw new CheesecakeFilesystemExeption();
     }
     $this->processHook('pre_gen.php', $tmpDir);
     $this->processDirs($tmpDir, $replace);
     $this->processFiles($tmpDir, $replace);
     if (!$this->fs->delete($this->join($tmpDir, 'cheesecake.json'))) {
         throw new CheesecakeFilesystemExeption();
     }
     if (!$this->fs->copyDirectory($tmpDir, $this->output)) {
         throw new CheesecakeFilesystemExeption();
     }
     if (!$this->fs->deleteDirectory($tmpDir)) {
         throw new CheesecakeFilesystemExeption();
     }
     $this->processHook('post_gen.php', $this->output);
     $hookDir = $this->join($this->output, 'hooks');
     if (is_dir($hookDir)) {
         if (!$this->fs->deleteDirectory($hookDir)) {
             throw new CheesecakeFilesystemExeption();
         }
     }
     return true;
 }
Exemplo n.º 7
0
 public function isRepositoryDirty(Repository $repo)
 {
     $status = $repo->getWorkingTreeStatus();
     return $status->modified()->count() > 0 || $status->added()->count() > 0 || $status->deleted()->count() > 0;
 }
Exemplo n.º 8
0
 /**
  * testSubmodule
  */
 public function testSubmodule()
 {
     $tempDir = realpath(sys_get_temp_dir()) . 'gitelephant_' . md5(uniqid(rand(), 1));
     $tempName = tempnam($tempDir, 'gitelephant');
     $path = $tempName;
     unlink($path);
     mkdir($path);
     $repository = new Repository($path);
     $repository->init();
     $repository->addSubmodule($this->repository->getPath());
     $repository->commit('test', true);
     $tree = $repository->getTree();
     $this->assertContains('.gitmodules', $tree);
     $this->assertContains($this->repository->getHumanishName(), $tree);
     $submodule = $tree[0];
     $this->assertEquals(Object::TYPE_LINK, $submodule->getType());
 }
Exemplo n.º 9
0
 /**
  * Creates a new branch on the repository and returns it
  *
  * @param \GitElephant\Repository $repository repository instance
  * @param string                  $name       branch name
  * @param string                  $startPoint branch to start from
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Process\Exception\LogicException
  * @throws \Symfony\Component\Process\Exception\InvalidArgumentException
  * @throws \Symfony\Component\Process\Exception\RuntimeException
  * @return \GitElephant\Objects\Branch
  */
 public static function create(Repository $repository, $name, $startPoint = null)
 {
     $repository->getCaller()->execute(BranchCommand::getInstance($repository)->create($name, $startPoint));
     return new self($repository, $name);
 }
Exemplo n.º 10
0
<?php

use GitElephant\Repository;
use Sami\Version\GitVersionCollection;
$dir = __DIR__ . '/src';
$versions = GitVersionCollection::create($dir);
$versions->add('master', 'master branch');
foreach (Repository::open('.')->getTags() as $tag) {
    $versions->addFromTags($tag->getName());
}
return new Sami\Sami($dir, array('build_dir' => 'build/%version%', 'cache_dir' => 'cache/%version%', 'title' => 'GitElephant API', 'default_opened_level' => 2, 'versions' => $versions));
Exemplo n.º 11
0
 /**
  * Creates a new tag on the repository and returns it
  *
  * @param \GitElephant\Repository $repository repository instance
  * @param string                  $name       branch name
  * @param string                  $startPoint branch to start from
  * @param string                  $message    tag message
  *
  * @throws \RuntimeException
  * @return \GitElephant\Objects\Branch
  */
 public static function create(Repository $repository, $name, $startPoint = null, $message = null)
 {
     $repository->getCaller()->execute(TagCommand::getInstance($repository)->create($name, $startPoint, $message));
     return $repository->getTag($name);
 }
 /**
  * @param string $filePath
  */
 public function stageFile($filePath)
 {
     $this->repository->stage($filePath);
 }
Exemplo n.º 13
0
 /**
  * create a repository from a remote git url, or a local filesystem
  * and save it in a temp folder
  *
  * @param string|Repository $git            the git remote url, or the filesystem path
  * @param null              $repositoryPath path
  * @param GitBinary         $binary         binary
  * @param null              $name           repository name
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Filesystem\Exception\IOException
  * @return Repository
  */
 public static function createFromRemote($git, $repositoryPath = null, GitBinary $binary = null, $name = null)
 {
     if (null === $repositoryPath) {
         $tempDir = realpath(sys_get_temp_dir());
         $repositoryPath = sprintf('%s%s%s', $tempDir, DIRECTORY_SEPARATOR, sha1(uniqid()));
         $fs = new Filesystem();
         $fs->mkdir($repositoryPath);
     }
     $repository = new Repository($repositoryPath, $binary, $name);
     if ($git instanceof Repository) {
         $git = $git->getPath();
     }
     $repository->cloneFrom($git, $repositoryPath);
     $repository->checkoutAllRemoteBranches();
     return $repository;
 }
Exemplo n.º 14
0
 /**
  * create from git command
  */
 private function createFromCommand()
 {
     $command = MainCommand::getInstance($this->repository)->status(true);
     $lines = $this->repository->getCaller()->execute($command)->getOutputLines(true);
     $this->parseOutputLines($lines);
 }
Exemplo n.º 15
0
 protected function getMockRepository()
 {
     return $this->getMock('GitElephant\\Repository', array(), array($this->repository->getPath(), $this->getMockBinary()));
 }