/** * @return FilesCollection */ public function locate() { $diff = $this->repository->getWorkingCopy()->getDiffStaged(); $files = array(); /** @var File $file */ foreach ($diff->getFiles() as $file) { if ($file->isDeletion()) { continue; } $fileName = $file->isRename() ? $file->getNewName() : $file->getName(); $files[] = new SplFileInfo($fileName, dirname($fileName), $file); } return new FilesCollection($files); }
function let(GrumPHP $grumPHP, Repository $repository, IOInterface $io, WorkingCopy $workingCopy, Diff $unstaged) { $grumPHP->ignoreUnstagedChanges()->willReturn(true); $repository->getWorkingCopy()->willReturn($workingCopy); $workingCopy->getDiffPending()->willReturn($unstaged); $unstaged->getFiles()->willReturn(['file1.php']); $this->beConstructedWith($grumPHP, $repository, $io); }
function it_will_list_all_diffed_files(Repository $repository, Diff $diff, WorkingCopy $workingCopy) { $changedFile = $this->mockFile('file1.txt'); $movedFile = $this->mockFile('file2.txt', true); $deletedFile = $this->mockFile('file3.txt', false, true); $repository->getWorkingCopy()->willReturn($workingCopy); $workingCopy->getDiffStaged()->willReturn($diff); $diff->getFiles()->willReturn(array($changedFile, $movedFile, $deletedFile)); $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); }
/** * Check if there is a pending diff and stash the changes. * * @reurn void */ private function doSaveStash() { $pending = $this->repository->getWorkingCopy()->getDiffPending(); if (!count($pending->getFiles())) { return; } try { $this->io->write('<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>'); $this->repository->run('stash', array('save', '--quiet', '--keep-index', uniqid('grumphp'))); } catch (Exception $e) { // No worries ... $this->io->write(sprintf('<fg=red>Failed stashing changes: %s</fg=red>', $e->getMessage())); return; } $this->stashIsApplied = true; $this->registerShutdownHandler(); }
public function renderStatus(\Twig_Environment $env, Repository $repository) { $wc = $repository->getWorkingCopy(); return $this->renderBlock($env, 'status', array('diff_staged' => $wc->getDiffStaged(), 'diff_pending' => $wc->getDiffPending())); }
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(''); }
/** * @return FilesCollection */ public function locateFromGitRepository() { $diff = $this->repository->getWorkingCopy()->getDiffStaged(); return $this->parseFilesFromDiff($diff); }