run() public method

This command is a facility command. You can run any command directly on git repository.
public run ( string $command, array $args = [] ) : string
$command string Git command to run (checkout, branch, tag)
$args array Arguments of git command
return string Output of a successful process or null if execution failed and debug-mode is disabled.
Beispiel #1
0
 /**
  * @return FilesCollection
  */
 public function locate()
 {
     $allFiles = trim($this->repository->run('ls-files'));
     $filePaths = preg_split("/\r\n|\n|\r/", $allFiles);
     $files = array();
     foreach ($filePaths as $file) {
         $files[] = new SplFileInfo($file, dirname($file), $file);
     }
     return new FilesCollection($files);
 }
Beispiel #2
0
 /**
  * @return FilesCollection
  */
 public function locate()
 {
     $allFiles = trim($this->repository->run('ls-files'));
     $filePaths = explode(PHP_EOL, $allFiles);
     $files = array();
     foreach ($filePaths as $file) {
         $files[] = new SplFileInfo($file, dirname($file), $file);
     }
     return new FilesCollection($files);
 }
Beispiel #3
0
 /**
  * Count commits, without offset or limit.
  *
  * @return int
  */
 public function countCommits()
 {
     if (count($this->revisions)) {
         $output = $this->repository->run('rev-list', array_merge(array('--count'), $this->revisions->getAsTextArray(), array('--'), $this->paths));
     } else {
         $output = $this->repository->run('rev-list', array_merge(array('--count', '--all', '--'), $this->paths));
     }
     return (int) $output;
 }
 /**
  * @return string
  */
 protected function guessGitDir()
 {
     $defaultGitDir = $this->config->getGitDir();
     try {
         $topLevel = $this->repository->run('rev-parse', array('--show-toplevel'));
     } catch (Exception $e) {
         return $defaultGitDir;
     }
     return rtrim($this->paths()->getRelativePath($topLevel), '/');
 }
 function it_will_list_all_diffed_files(Repository $repository)
 {
     $files = array('file1.txt', 'file2.txt');
     $repository->run('ls-files')->willReturn(implode(PHP_EOL, $files));
     $result = $this->locate();
     $result->shouldBeAnInstanceOf('GrumPHP\\Collection\\FilesCollection');
     $result[0]->getPathname()->shouldBe('file1.txt');
     $result[1]->getPathname()->shouldBe('file2.txt');
     $result->getIterator()->count()->shouldBe(2);
 }
Beispiel #6
0
 public function run($command, $args = [])
 {
     $output = parent::run($command, $args);
     if ('diff-tree' === $command && null !== $this->perlCommand) {
         $p = ProcessBuilder::create([$this->perlCommand, __DIR__ . '/../Resources/bin/git-diff-highlight'])->setInput($output)->getProcess();
         $p->run();
         if ($p->isSuccessful()) {
             $output = $p->getOutput();
         }
     }
     return $output;
 }
 /**
  * @return void
  */
 private function doPopStash()
 {
     if (!$this->stashIsApplied) {
         return;
     }
     try {
         $this->io->write('<fg=yellow>Reapplying unstaged changes from stash.</fg=yellow>');
         $this->repository->run('stash', array('pop', '--quiet'));
     } catch (Exception $e) {
         throw new RuntimeException('The stashed changes could not be applied. Please run `git stash pop` manually!' . 'More info: ' . $e->__toString(), 0, $e);
     }
     $this->stashIsApplied = false;
 }
 /**
  * Returns all lines of the blame.
  *
  * @return array
  */
 public function getLines()
 {
     if (null !== $this->lines) {
         return $this->lines;
     }
     $args = array('-p');
     if (null !== $this->lineRange) {
         $args[] = '-L';
         $args[] = $this->lineRange;
     }
     $args[] = $this->revision->getRevision();
     $args[] = '--';
     $args[] = $this->file;
     $parser = new BlameParser($this->repository);
     $parser->parse($this->repository->run('blame', $args));
     $this->lines = $parser->lines;
     return $this->lines;
 }
 /**
  * Runs git commands on the repository.
  *
  * This is a wrapper around \Gitonomy\Git\Repository::run(). The GitClone
  * entity must catch whether or not the repository has actually been
  * initialized and any errors produced from the command executed.
  *
  * @param string $command
  *   Git command to run (checkout, branch, tag).
  * @param array $args
  *   Arguments of git command.
  * @param bool $return_output
  *   Toggle determining whether or not to return the output from $command.
  *
  * @return FALSE|string|GitClone
  *   Anytime there is an error, the return value will always be FALSE.
  *   If $return_output is set, the output of $command is returned.
  *   Otherwise, the current GitClone instance is returned for chainability.
  *
  * @see \Gitonomy\Git\Repository::run()
  *
  * @chainable
  */
 protected function run($command, array $args = array(), $return_output = FALSE)
 {
     $return = $return_output ? '' : $this;
     $command_hook = _git_clone_hook_name($command);
     $context = array('output' => $return_output);
     drupal_alter('git_clone_pre_' . $command_hook, $args, $this, $context);
     try {
         $output = $this->repository->run($command, $args);
         $this->log($command, $args, $output);
         drupal_alter('git_clone_post_' . $command_hook, $output, $this, $context);
         if ($return_output) {
             $return = $output;
         }
     } catch (\Exception $e) {
         watchdog('git_clone', $e->getMessage(), array(), WATCHDOG_ERROR);
         $return = FALSE;
     }
     return $return;
 }
 function it_should_pop_changes_when_an_error_occurs(Repository $repository)
 {
     $event = new RunnerEvent(new TasksCollection(), new GitPreCommitContext(new FilesCollection()), new TaskResultCollection());
     $repository->run('stash', Argument::containing('save'))->shouldBeCalled();
     $repository->run('stash', Argument::containing('pop'))->shouldBeCalled();
     $this->saveStash($event);
     $this->handleErrors();
 }
Beispiel #11
0
 /**
  * Mark commit by version tag
  *
  * @param string $hash     commit id
  * @param int $forthNumber @see VersionGenerator::version
  * @param string $tag
  */
 public function markCommit($hash, $forthNumber = null, $tag = "")
 {
     $version = 'v' . $this->version($forthNumber, $tag);
     $this->repo->getReferences()->createTag($version, $hash);
     $this->repo->run('push', array('origin', $version));
 }
Beispiel #12
0
 public function parse()
 {
     $kwfTrlElements = array();
     if ($this->_kwfPoFilePath) {
         $this->_output->writeln('<info>Reading kwf-po file</info>');
         $kwfPoFile = \Sepia\PoParser::parseFile($this->_kwfPoFilePath);
         $trlElementsExtractor = new TrlElementsExtractor($kwfPoFile);
         $kwfTrlElements = $trlElementsExtractor->extractTrlElements();
     }
     $initDir = getcwd();
     $this->_output->writeln('<info>Changing into directory</info>');
     $repository = new Repository($this->_directory);
     $wc = $repository->getWorkingCopy();
     if ($wc->getDiffPending()->getRawDiff() != '' || $wc->getDiffStaged()->getRawDiff() != '') {
         $this->_output->writeln('<error>Uncommited changes</error>');
         exit;
     }
     chdir($initDir);
     $initBranch = trim($repository->run('rev-parse', array('--abbrev-ref', 'HEAD')));
     $trlElements = array();
     $errors = array();
     $repository = new Repository($this->_directory);
     $repository->run('fetch', array('origin'));
     if ($this->_kwfPoFilePath) {
         $this->_output->writeln('<info>Iterating over branches matching "^[1-9]+.[0-9]+$"</info>');
     } else {
         $this->_output->writeln('<info>Iterating over branches matching "^[3-9]+.[0-9]+$" and >=3.9</info>');
     }
     foreach ($repository->getReferences()->getBranches() as $branch) {
         $branchName = $branch->getName();
         if (strpos($branchName, 'origin/') === false) {
             continue;
         }
         $splited = explode('/', $branchName);
         $isVersionNumber = preg_match('/^[0-9]+.[0-9]+$/i', $splited[1]);
         if (sizeof($splited) >= 3) {
             continue;
         }
         if (!$isVersionNumber && $splited[1] != 'master' && $splited[1] != 'production') {
             continue;
         }
         if (!$this->_kwfPoFilePath && $isVersionNumber && version_compare($splited[1], '3.9', '<')) {
             continue;
         }
         $this->_output->writeln("<info>Checking out branch: {$branchName}</info>");
         $wc->checkout($branchName);
         // parse package
         $this->_output->writeln('Parsing source directory...');
         $parser = new ParseAll($this->_directory, $this->_output);
         $parser->setIgnoredFiles($this->_ignoredFiles);
         $trlElements = array_merge($parser->parseDirectoryForTrl(), $trlElements);
         $newErrors = $parser->getErrors();
         foreach ($newErrors as $key => $error) {
             $newErrors[$key]['branch'] = $branchName;
         }
         $errors = array_merge($newErrors, $errors);
     }
     $wc->checkout($initBranch);
     $sources = array();
     $filteredTrlElements = array();
     foreach ($trlElements as $trlElement) {
         $sources[$trlElement['source']] = true;
         if ($trlElement['source'] == $this->_source) {
             $filteredTrlElements[] = $trlElement;
         }
     }
     $trlElements = $filteredTrlElements;
     // generate po file
     $this->_output->writeln('Generate Po-File...');
     touch($this->_poFilePath);
     $this->_output->writeln($this->_poFilePath);
     $poFileGenerator = new PoFileGenerator($trlElements, $kwfTrlElements);
     $poFile = $poFileGenerator->generatePoFileObject($this->_poFilePath);
     $poFile->writeFile($this->_poFilePath);
     $this->_output->writeln('');
     $this->_output->writeln('Trl Errors:');
     foreach ($trlElements as $trlElement) {
         if (isset($trlElement['error_short']) && $trlElement['error_short']) {
             var_dump($trlElement);
         }
     }
     if (count($errors)) {
         $this->_output->writeln('');
         $this->_output->writeln('Php Parse-Errors:');
         foreach ($errors as $error) {
             $this->_output->writeln('  Branch: ' . $error['branch'] . ' | File: ' . $error['file']);
             $this->_output->writeln('    Error:' . $error['error']->getMessage());
             $this->_output->writeln('  -------------------------------------');
         }
     }
     $this->_output->writeln('');
     $this->_output->writeln('Every branch has been parsed an data is collected in ' . $this->_poFilePath);
     $this->_output->writeln('');
     $this->_output->writeln('1. Please check the mentioned Parse-Errors');
     $this->_output->writeln('2. Upload and translate file from ' . $this->_poFilePath . ' to lingohub or translate in another way');
     $this->_output->writeln('3. When using lingohub call "./vendor/bin/lingohub downloadTranslations" after translating');
     $this->_output->writeln('');
 }
 protected function run($command, array $args = array())
 {
     return $this->repository->run($command, $args);
 }
Beispiel #14
0
use Gitonomy\Git\Repository;
require __DIR__ . '/vendor/autoload.php';
require __DIR__ . '/src/PackageBuilder.php';
require __DIR__ . '/src/Dumper.php';
/**
 * @var Branch[] $branches
 */
$branches = [];
/**
 * @var Tag[] $tags
 */
$tags = [];
$repository = new Repository('tmp/drupal');
$repository->run('fetch');
$metapackage_repository = new Repository('tmp/metapackage');
$metapackage_repository->run('config', ['user.name', 'Florian Weber (via CircleCI)']);
$metapackage_repository->run('config', ['user.email', '*****@*****.**']);
$branches = array_filter($repository->getReferences()->getRemoteBranches(), function (Branch $branch) {
    if ($branch->isRemote() && preg_match('/^origin\\/8\\./', $branch->getName(), $matches)) {
        return TRUE;
    }
    return FALSE;
});
$tags = array_filter($repository->getReferences()->getTags(), function (Tag $tag) {
    return preg_match('/^8\\.[0-9]+\\.[0-9]+/', $tag->getName());
});
$refs = $tags + $branches;
$refs_array = [];
foreach ($refs as $ref) {
    $name = str_replace('origin/', '', $ref->getName());
    if ($ref instanceof Branch) {