diff --git a/src/Info/BranchInfos.php b/src/Info/BranchInfos.php index edbbae0..41f57df 100644 --- a/src/Info/BranchInfos.php +++ b/src/Info/BranchInfos.php @@ -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 @@ -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); } diff --git a/src/Repo.php b/src/Repo.php index e3b7431..dff05a4 100644 --- a/src/Repo.php +++ b/src/Repo.php @@ -332,7 +332,21 @@ 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 @@ -340,12 +354,7 @@ public function getBranchInfos(bool $refresh = false): BranchInfos 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); }