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 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')); }