/** * @covers \Bit3\GitPhp\GitRepository::branch * @covers \Bit3\GitPhp\Command\BranchCommandBuilder::getNames */ public function testListBranchesOnUninitializedRepository() { $this->setExpectedException('Bit3\\GitPhp\\GitException'); $this->uninitializedGitRepository->branch()->getNames(); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $exitCode = 0; $git = new GitRepository($this->input->getArgument('git-dir')); $branches = $git->branch()->listBranches()->getNames(); $composer = json_decode(file_get_contents($input->getArgument('git-dir') . '/composer.json'), true); if (!isset($composer['extra']['branch-alias'])) { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln('<info>No branch aliases found, skipping test.</info>'); } return 0; } foreach ($composer['extra']['branch-alias'] as $branch => $alias) { $simpleBranch = $this->simplifyBranch($branch); if (!in_array($simpleBranch, $branches)) { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln(sprintf('<info>Skipping non existing branch %s(%s)</info>', $branch, $alias)); } continue; } $tag = $this->getTagFromBranch($simpleBranch); // No tag yet, therefore definately before any version. if ($tag === null) { $output->writeln(sprintf('<comment>Branch alias %s(%s) has not been tagged yet.</comment>', $branch, $alias)); } elseif (!$this->validate($tag, $alias)) { $output->writeln(sprintf('<error>The branch alias %s(%s) is behind the latest branch tag %s!</error>', $branch, $alias, $tag)); $exitCode = 1; } else { if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { $output->writeln(sprintf('<info>Branch alias %s(%s) is ahead of the latest branch tag.</info>', $branch, $alias)); } } } return $exitCode; }