Changeset View
Changeset View
Standalone View
Standalone View
src/repository/api/ArcanistGitUpstreamPath.php
<?php | <?php | ||||
final class ArcanistGitUpstreamPath extends Phobject { | final class ArcanistGitUpstreamPath extends Phobject { | ||||
private $path = array(); | private $path = array(); | ||||
const TYPE_LOCAL = 'local'; | const TYPE_LOCAL = 'local'; | ||||
const TYPE_REMOTE = 'remote'; | const TYPE_REMOTE = 'remote'; | ||||
public function addUpstream($key, array $spec) { | public function addUpstream($key, array $spec) { | ||||
$this->path[$key] = $spec; | $this->path[$key] = $spec; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function removeUpstream($key) { | |||||
unset($this->path[$key]); | |||||
return $this; | |||||
} | |||||
public function getUpstream($key) { | public function getUpstream($key) { | ||||
return idx($this->path, $key); | return idx($this->path, $key); | ||||
} | } | ||||
public function getLength() { | public function getLength() { | ||||
return count($this->path); | return count($this->path); | ||||
} | } | ||||
/** | /** | ||||
* Test if this path eventually connects to a remote. | * Test if this path eventually connects to a remote. | ||||
* | * | ||||
* @return bool True if the path connects to a remote. | * @return bool True if the path connects to a remote. | ||||
*/ | */ | ||||
public function isConnectedToRemote() { | public function isConnectedToRemote() { | ||||
$last = last($this->path); | $last = last($this->path); | ||||
if (!$last) { | if (!$last) { | ||||
return false; | return false; | ||||
} | } | ||||
return ($last['type'] == self::TYPE_REMOTE); | return ($last['type'] == self::TYPE_REMOTE); | ||||
} | } | ||||
public function getLocalBranches() { | |||||
return array_keys($this->path); | |||||
} | |||||
public function getRemoteBranchName() { | public function getRemoteBranchName() { | ||||
if (!$this->isConnectedToRemote()) { | if (!$this->isConnectedToRemote()) { | ||||
return null; | return null; | ||||
} | } | ||||
return idx(last($this->path), 'name'); | return idx(last($this->path), 'name'); | ||||
} | } | ||||
Show All 36 Lines |