Skip to content

Commit

Permalink
added the VersionControl_Git::getRemoteBranches() method (fixes #17283)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kousuke Ebihara committed Mar 31, 2010
1 parent a435415 commit 29b3b83
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions VersionControl/Git.php
Expand Up @@ -185,6 +185,36 @@ public function getBranches()
return $result;
}

/**
* Get an array of remote branch names
*
* @param string $name The name of remote repository
*
* @return array
*/
public function getRemoteBranches($name = 'origin')
{
$result = array();

$commandResult = $this->getCommand('branch')
->setOption('r')
->execute();
$commandResult = explode(PHP_EOL, rtrim($commandResult));

foreach ($commandResult as $v) {
$v = trim($v);

$prefix = $name.'/';
if (0 !== strpos($v, $prefix)) {
continue;
}

$result[] = substr($v, strlen($prefix));
}

return $result;
}

/**
* Get a current branch name
*
Expand Down
13 changes: 13 additions & 0 deletions test/VersionControl_GitTest.php
Expand Up @@ -106,6 +106,19 @@ public function testGetBranches()
$this->assertEquals($branches[7], 'master');
}

public function testGetRemoteBranches()
{
$instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');

$branches = $instance->getRemoteBranches();

$this->assertEquals(count($branches), 8);
$this->assertEquals($branches[0], 'branch1');
$this->assertEquals($branches[7], 'master');

$this->assertEquals(count($instance->getRemoteBranches('undefined-repository')), 0);
}

public function testGetCurrentBranch()
{
$instance = new VersionControl_Git('./fixtures/001_VersionControl_Git');
Expand Down
Binary file modified test/fixtures.tar.gz
Binary file not shown.

0 comments on commit 29b3b83

Please sign in to comment.