Skip to content

Commit

Permalink
up: add new method hasBranch() in Repo
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 3, 2022
1 parent 418fba0 commit 2b3f268
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Info/BranchInfos.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function hasRemoteBranch(string $name, string|array $remotes = ''): bool
}

/**
* @param string $name
* @param string $name name without remote.
* @param string|array $from keywords {@see FROM_LOCAL} or remote names
*
* @return BranchInfo|null
Expand All @@ -229,7 +229,7 @@ public function getBranch(string $name, string|array $from = self::FROM_LOCAL):
return $this->localBranches[$name] ?? null;
}

if ($from === self::FROM_ALL) {
if (!$from || $from === self::FROM_ALL) {
return $this->localBranches[$name] ?? $this->getRemoteBranch($name);
}

Expand Down
23 changes: 16 additions & 7 deletions src/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,20 +332,29 @@ public function getBranchInfos(bool $refresh = false): BranchInfos
}

/**
* @param string $name
* @param string $name name without remote.
* @param string $remote
*
* @return bool
*/
public function hasBranch(string $name, string $remote = ''): bool
{
$bis = $this->getBranchInfos();
$from = $remote ?: BranchInfos::FROM_LOCAL;

return $bis->hasBranch($name, $from);
}

/**
* @param string $name name without remote.
* @param string $remote
*
* @return BranchInfo
*/
public function getBranchInfo(string $name, string $remote = ''): BranchInfo
{
$bis = $this->getBranchInfos();

$from = BranchInfos::FROM_LOCAL;
if ($remote) {
$from = BranchInfos::FROM_REMOTE;
$name = $remote . '/' . $name;
}
$from = $remote ?: BranchInfos::FROM_LOCAL;

return $bis->getBranch($name, $from);
}
Expand Down

0 comments on commit 2b3f268

Please sign in to comment.