protected function execute(InputInterface $input, OutputInterface $output) { $statusCode = 0; $output->writeln("<info>[[ Finding repositories ]]</info>"); $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getArgument('path')); $output->writeln("<info>[[ Fast-forwarding ]]</info>"); foreach ($gitRepos as $gitRepo) { /** @var \GitScan\GitRepo $gitRepo */ $path = $this->fs->formatPrettyPath($gitRepo->getPath(), $input->getArgument('path')); if ($gitRepo->getUpstreamBranch() === NULL) { $output->writeln("<comment>Skip {$path}: No upstream tracking branch</comment>"); } elseif (!$gitRepo->isLocalFastForwardable()) { $output->writeln("<comment>Skip {$path}: Cannot be fast-forwarded</comment>"); } else { $output->writeln("<comment>Fast-forward {$path} ({$gitRepo->getLocalBranch()} <= {$gitRepo->getUpstreamBranch()})...</comment>"); $process = $gitRepo->command('git pull --ff-only'); $process->run(); if (!$process->isSuccessful()) { $output->writeln("<error>Failed to update {$gitRepo->getPath()}/<error>"); if ($process->getOutput()) { $output->writeln("//---------- BEGIN STDOUT ----------\\\\"); $output->writeln($process->getOutput(), OutputInterface::OUTPUT_RAW); $output->writeln("\\\\----------- END STDOUT -----------//"); } if ($process->getErrorOutput()) { $output->writeln("//---------- BEGIN STDERR ----------\\\\"); $output->writeln($process->getErrorOutput(), OutputInterface::OUTPUT_RAW); $output->writeln("\\\\----------- END STDERR -----------//"); } $statusCode = 1; } } } return $statusCode; }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln("<info>[[ Finding repositories ]]</info>"); $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getArgument('path')); if ($input->getOption('status') == 'auto') { $input->setOption('status', count($gitRepos) > self::DISPLAY_ALL_THRESHOLD ? 'novel' : 'all'); } $output->writeln($input->getOption('fetch') ? "<info>[[ Fetching statuses ]]</info>" : "<info>[[ Checking statuses ]]</info>"); /** @var \Symfony\Component\Console\Helper\ProgressHelper $progress */ $progress = $this->getApplication()->getHelperSet()->get('progress'); $progress->start($output, 1 + count($gitRepos)); $progress->advance(); $rows = array(); $hiddenCount = 0; foreach ($gitRepos as $gitRepo) { /** @var \GitScan\GitRepo $gitRepo */ if ($input->getOption('fetch') && $gitRepo->getUpstreamBranch() !== NULL) { ProcessUtil::runOk($gitRepo->command('git fetch')); } if ($gitRepo->matchesStatus($input->getOption('status'))) { $rows[] = array($gitRepo->getStatusCode(), $this->fs->formatPrettyPath($gitRepo->getPath(), $input->getArgument('path')), $gitRepo->getLocalBranch(), $gitRepo->getUpstreamBranch()); } else { $hiddenCount++; } $progress->advance(); } $progress->finish(); $output->writeln("<info>[[ Results ]]</info>\n"); if (!empty($rows)) { $table = $this->getApplication()->getHelperSet()->get('table'); $table->setHeaders(array('Status', 'Path', 'Local Branch', 'Remote Branch'))->setRows($rows); $table->render($output); $chars = $this->getUniqueChars(ArrayUtil::collect($rows, 0)); foreach ($chars as $char) { switch ($char) { case ' ': break; case 'M': $output->writeln("[M] Modifications have not been committed"); break; case 'N': $output->writeln("[N] New files have not been committed"); break; case 'F': $output->writeln("[F] Fast-forwards are not possible"); break; case 'B': $output->writeln("[B] Branch names are suspiciously different"); break; case 'S': $output->writeln("[S] Stash contains data"); break; default: throw new \RuntimeException("Unrecognized status code [{$char}]"); } } } else { $output->writeln("No repositories to display."); } if ($hiddenCount > 0) { switch ($input->getOption('status')) { case 'novel': $output->writeln("NOTE: Omitted information about {$hiddenCount} boring repo(s). To display all, use --status=all."); break; case 'boring': $output->writeln("NOTE: Omitted information about {$hiddenCount} novel repo(s). To display all, use --status=all."); break; default: $output->writeln("NOTE: Omitted information about {$hiddenCount} repo(s). To display all, use --status=all."); } } }