Beispiel #1
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     foreach ($repositories->getAll() as $model) {
         $path = $model->getPath();
         if ($model->getType() === RepositoryModel::TYPE_ROOT) {
             $path = '.';
         }
         $this->getSymfonyStyle()->writeln(sprintf('<info>%s</info> [%s]', $path, $model->getBranch()));
     }
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
Beispiel #2
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $parallelProcess = new ParallelProcess($this->getSymfonyStyle());
     /** @var RepositoryModel[] $list */
     $list = array_reverse($repositories->getAll());
     $model = null;
     foreach ($list as $model) {
         $parallelProcess->add($model->getProvider()->buildCommand('fetch', []), $model->getAbsolutePath(), $this->isDryRun(), false);
     }
     $parallelProcess->run();
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
Beispiel #3
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $branch = $this->getInput()->getArgument('branch');
     /** @var RepositoryModel[] $list */
     if (!$this->getInput()->getOption('no-vendors')) {
         $list = array_reverse($repositories->getAll());
     } else {
         $list = [$repositories->getProjectModel()];
     }
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create(count($list));
     foreach ($list as $model) {
         $currentBranch = $model->getBranch();
         $progressBar->advance('Checkout of ' . ($model->getPath() ?: 'project repository'));
         if ($currentBranch == $branch) {
             continue;
         }
         $needCheckout = $model->getType() == RepositoryModel::TYPE_ROOT;
         $needCheckout = $needCheckout || $model->hasChanges();
         $needCheckout = $needCheckout || 'master' == $branch;
         $needCheckout = $needCheckout || $model->getProvider()->hasLocalBranch($branch);
         $needCheckout = $needCheckout || $model->getProvider()->hasRemoteBranch($branch);
         if ($model->hasCommits()) {
             $this->getSymfonyStyle()->newLine();
             $this->getSymfonyStyle()->warning(sprintf('Вы делаете checkout "%s" с закоммиченными но не запушенными правками', $model->getPackageName()));
         }
         if ($needCheckout) {
             $output = $model->getProvider()->run('fetch', [], $this->isDryRun(), true);
             if ($output) {
                 $this->getSymfonyStyle()->writeln($output);
             }
             $arguments = [];
             if (!$model->getProvider()->hasLocalBranch($branch) && !$model->getProvider()->hasRemoteBranch($branch)) {
                 $arguments[] = '-b';
             }
             $this->getSymfonyStyle()->newLine(2);
             $arguments[] = $branch;
             $model->getProvider()->run('checkout', $arguments, $this->isDryRun(), true);
             $this->getSymfonyStyle()->writeln(sprintf('%s: switched to [%s]', $model->getPath(), $branch));
         }
     }
     $progressBar->finish();
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }
Beispiel #4
0
 /**
  * @param RepositoryList $repositories
  */
 public function execute(RepositoryList $repositories)
 {
     $this->getLogger()->debug('Run plugin', [get_called_class()]);
     $progressBar = new ProgressBarHelper($this->getSymfonyStyle());
     $progressBar->create($repositories->count());
     $hasChanges = false;
     $projectBranch = $repositories->getProjectModel()->getBranch();
     $result = [];
     foreach ($repositories->getAll() as $model) {
         $progressBar->advance('Status of ' . ($model->getPath() ?: 'project repository'));
         $branch = $model->getBranch();
         $differentBranch = $this->isDifferentBranches($projectBranch, $branch);
         $path = $model->getType() === RepositoryModel::TYPE_ROOT ? 'project repository' : $model->getPath();
         /**
          * Check full state of repo
          * Also check branch of repo (if it is not according to project branch - show it)
          */
         $unpushedCommits = $model->getUnpushedCommits();
         $gitHasUnpushedCommits = $model->hasCommits();
         $gitHasChanges = $model->hasChanges();
         $modelHasChanges = $gitHasChanges || $gitHasUnpushedCommits || $differentBranch;
         $hasChanges = $hasChanges || $modelHasChanges;
         if ($modelHasChanges) {
             $result[$path] = ['path' => null, 'branch' => null, 'hasCommits' => null, 'hasChanges' => null, 'hasConflicts' => null, 'unpushedCommit' => null];
             $result[$path]['path'] = sprintf('<info>%s</info> ', $path);
             if ($projectBranch == $branch) {
                 $result[$path]['branch'] = sprintf('<question>[%s]</question>', $branch);
             } else {
                 if (self::MASTER_BRANCH == $projectBranch) {
                     if ($projectBranch != $branch) {
                         $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                     }
                 } else {
                     if (self::MASTER_BRANCH == $branch) {
                         if ($gitHasChanges) {
                             $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                         } else {
                             $result[$path]['branch'] = sprintf('<error>[%s]</error>', $branch);
                         }
                     } else {
                         if ($projectBranch != $branch) {
                             if ($gitHasChanges) {
                                 $result[$path]['branch'] = sprintf('<error>[%s -> %s]</error>', $branch, $projectBranch);
                             } else {
                                 $result[$path]['branch'] = sprintf('<error>[%s]</error>', $branch);
                             }
                         }
                     }
                 }
             }
             if ($gitHasUnpushedCommits) {
                 $result[$path]['hasCommits'] = ' <comment>(has unpushed commits)</comment>';
             }
             if ($model->hasConflicts()) {
                 $result[$path]['hasConflicts'] = ' <error>(has conflicts)</error>';
             }
             if ($gitHasChanges) {
                 $result[$path]['hasChanges'] = ltrim($model->getRawStatus());
             }
             if ($gitHasUnpushedCommits) {
                 $result[$path]['unpushedCommit'] .= "<comment>Unpushed commits:</comment>\n";
                 foreach ($unpushedCommits as $unpushedCommit) {
                     $result[$path]['unpushedCommit'] .= sprintf("<comment>%s</comment>\n", $unpushedCommit);
                 }
             }
         }
     }
     $progressBar->finish();
     if (!$hasChanges) {
         $this->getSymfonyStyle()->writeln('<comment>no changes</comment>');
     } else {
         $this->displayStatus($result);
     }
     $this->getLogger()->debug('End plugin', [get_called_class()]);
 }