protected function executeDelete(InputInterface $input, OutputInterface $output) { $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getOption('path')); $batch = new ProcessBatch('Deleting branch(es)...'); $tagName = $input->getArgument('tagName'); $tagQuoted = preg_quote($tagName, '/'); foreach ($gitRepos as $gitRepo) { /** @var \GitScan\GitRepo $gitRepo */ $relPath = $this->fs->makePathRelative($gitRepo->getPath(), $input->getOption('path')); $tags = $gitRepo->getTags(); $matches = array(); if ($input->getOption('prefix')) { $matches = preg_grep("/[-_]{$tagQuoted}\$/", $tags); } if (in_array($tagName, $tags)) { $matches[] = $tagName; } // TODO: Verify that user wants to delete these. foreach ($matches as $match) { $label = "In \"<info>{$relPath}</info>\", delete tag \"<info>{$match}</info>\" ."; $batch->add($label, $gitRepo->command("git tag -d " . escapeshellarg($match))); } } $batch->runAllOk($output, $input->getOption('dry-run')); }
protected function execute(InputInterface $input, OutputInterface $output) { $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getOption('path')); $remote = $input->getArgument('remote'); $batch = new ProcessBatch('Pushing...'); $branchQuoted = preg_quote($input->getArgument('refspec'), '/'); $branchRegex = $input->getOption('prefix') ? "/^((.+[-_])|){$branchQuoted}\$/" : "/^{$branchQuoted}\$/"; foreach ($gitRepos as $gitRepo) { /** @var \GitScan\GitRepo $gitRepo */ $relPath = $this->fs->makePathRelative($gitRepo->getPath(), $input->getOption('path')); $remotes = $gitRepo->getRemotes(); if (!in_array($remote, $remotes)) { $output->writeln("<error>Repo \"<info>{$relPath}</info>\" does not have remote \"<info>{$remote}</info>\"</error>"); return 1; } $names = array_merge($gitRepo->getBranches(), $gitRepo->getTags()); $matchedNames = preg_grep($branchRegex, $names); // TODO: Interactively confirm/filter. foreach ($matchedNames as $name) { $batch->add("In \"<info>{$relPath}</info>\", push \"<info>{$name}</info>\" to \"<info>{$remote}</info>\"", $gitRepo->command(sprintf("git push %s %s", escapeshellarg($remote), escapeshellarg($name)))); } } $batch->runAllOk($output, $input->getOption('dry-run')); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!$input->getOption('command')) { $output->writeln("<error>Missing required option: --command</error>"); return 1; } $statusCode = 0; if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln("<info>[[ Finding repositories ]]</info>"); } $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getArgument('path')); foreach ($gitRepos as $gitRepo) { /** @var \GitScan\GitRepo $gitRepo */ if (!$gitRepo->matchesStatus($input->getOption('status'))) { continue; } $topLevel = $this->fs->findFirstParent($gitRepo->getPath(), $input->getArgument('path')); if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln("<info>[[ {$gitRepo->getPath()} ]]</info>"); } $process = new \Symfony\Component\Process\Process($input->getOption('command')); $process->setWorkingDirectory($gitRepo->getPath()); // $process->setEnv(...); sucks in Debian/Ubuntu putenv("path=" . $this->fs->makePathRelative($gitRepo->getPath(), $topLevel)); putenv("toplevel=" . $topLevel); $errorOutput = $output; if (is_callable($output, 'getErrorOutput') && $output->getErrorOutput()) { $errorOutput = $output->getErrorOutput(); } $process->run(function ($type, $buffer) use($output, $errorOutput) { if (\Symfony\Component\Process\Process::ERR === $type) { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $errorOutput->write("<error>STDERR</error> "); } $errorOutput->write($buffer, FALSE, OutputInterface::OUTPUT_RAW); } else { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->write("<comment>STDOUT</comment> "); } $output->write($buffer, FALSE, OutputInterface::OUTPUT_RAW); } }); if (!$process->isSuccessful()) { $errorOutput->writeln("<error>[[ {$gitRepo->getPath()}: exit code = {$process->getExitCode()} ]]</error>"); $statusCode = 2; } } putenv("path"); putenv("toplevel"); return $statusCode; }
protected function execute(InputInterface $input, OutputInterface $output) { $scanner = new \GitScan\GitRepoScanner(); $paths = $input->getArgument('path'); if (count($paths) != 1) { $output->writeln('<error>Expected only one root path</error>'); return; } $gitRepos = $scanner->scan($paths); foreach ($gitRepos as $gitRepo) { /** @var GitRepo $gitRepo */ $path = $input->getOption('absolute') ? $gitRepo->getPath() : $this->fs->makePathRelative($gitRepo->getPath(), $paths[0]); $path = rtrim($path, '/'); $output->writeln($path); } }
protected function execute(InputInterface $input, OutputInterface $output) { $rules = array(); foreach ($this->getPatchExprs($input, $output) as $expr) { $rule = new AutoMergeRule($expr); $rules[] = $rule; } $scanner = new \GitScan\GitRepoScanner(); $gitRepos = $scanner->scan($input->getOption('path')); $checkouts = array(); // array(string $absDir => TRUE) foreach ($gitRepos as $gitRepo) { /** @var GitRepo $gitRepo */ $relPath = $this->fs->makePathRelative($gitRepo->getPath(), $input->getOption('path')); $hasPatch = 0; foreach (array_keys($rules) as $ruleId) { /** @var AutoMergeRule $rule */ $rule = $rules[$ruleId]; $rule->fetch(); if ($rule->isMatch($gitRepo)) { unset($rules[$ruleId]); $hasPatch = 1; if (!isset($checkouts[$gitRepo->getPath()])) { $this->checkoutAutomergeBranch($input, $output, $gitRepo, $relPath); $checkouts[$gitRepo->getPath()] = 1; } $output->writeln("In \"<info>{$relPath}</info>\", apply \"<info>{$rule->getExpr()}</info>\" on top of \"<info>{$gitRepo->getCommit()}</info>\"."); $process = $gitRepo->applyPatch($rule->getPatch(), $input->getOption('passthru')); $output->writeln($process->getOutput()); } } if ($hasPatch) { $output->writeln("In \"<info>{$relPath}</info>\", final commit is \"<info>{$gitRepo->getCommit()}</info>\"."); } } foreach ($rules as $ruleId => $rule) { $output->writeln("<error>Failed to match {$rule->getExpr()} to a local repo. Ensure that one of the repos has the proper remote URL.</error>"); } if (!empty($rules)) { return 1; } }