Beispiel #1
0
 /**
  * Get the branch properties from command
  *
  * @throws \InvalidArgumentException
  */
 private function createFromCommand()
 {
     $branchName = 'remotes/' . $this->getName();
     $command = BranchCommand::getInstance($this->getRepository())->listBranches(true);
     $outputLines = $this->repository->getCaller()->execute($command)->getOutputLines(true);
     foreach ($outputLines as $outputLine) {
         if (strpos($outputLine, '->') > 0) {
             continue;
         }
         $matches = static::getMatches($outputLine);
         if ($branchName === $matches[1]) {
             $this->parseOutputLine($outputLine);
             return;
         }
     }
     throw new InvalidBranchNameException(sprintf('The %s branch doesn\'t exists', $branchName));
 }
Beispiel #2
0
 /**
  * get the branches this commit is contained in
  *
  * @see BranchCommand::contains
  */
 public function getContainedIn()
 {
     $command = BranchCommand::getInstance($this->getRepository())->contains($this->getSha());
     return array_map('trim', (array) $this->getCaller()->execute($command)->getOutputLines(true));
 }
Beispiel #3
0
 /**
  * An array of Branch objects
  *
  * @param bool $namesOnly return an array of branch names as a string
  * @param bool $all       lists also remote branches
  *
  * @throws \RuntimeException
  * @throws \Symfony\Component\Process\Exception\InvalidArgumentException
  * @throws \Symfony\Component\Process\Exception\LogicException
  * @throws \InvalidArgumentException
  * @throws \Symfony\Component\Process\Exception\RuntimeException
  * @return array
  */
 public function getBranches($namesOnly = false, $all = false)
 {
     $branches = array();
     if ($namesOnly) {
         $outputLines = $this->caller->execute(BranchCommand::getInstance($this)->listBranches($all, true))->getOutputLines(true);
         $branches = array_map(function ($v) {
             return ltrim($v, '* ');
         }, $outputLines);
     } else {
         $outputLines = $this->caller->execute(BranchCommand::getInstance($this)->listBranches($all))->getOutputLines(true);
         foreach ($outputLines as $branchLine) {
             $branches[] = Branch::createFromOutputLine($this, $branchLine);
         }
     }
     return $branches;
 }
 /**
  * delete test
  *
  * @covers GitElephant\Command\BranchCommand::delete
  */
 public function testDelete()
 {
     $branch = new BranchCommand();
     $this->assertEquals("branch '-d' 'test-branch'", $branch->delete('test-branch'), 'list branch command without force');
     $this->assertEquals("branch '-D' 'test-branch'", $branch->delete('test-branch', true), 'list branch command with force');
 }