From a686db86b30ffacee83928e9f33634fe821f12d0 Mon Sep 17 00:00:00 2001 From: Inhere Date: Mon, 27 Jun 2022 21:05:23 +0800 Subject: [PATCH] fix: fix branch info line parse error --- src/GitUtil.php | 4 ++-- src/Info/BranchInfos.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/GitUtil.php b/src/GitUtil.php index 1c23a2f..39fee5f 100644 --- a/src/GitUtil.php +++ b/src/GitUtil.php @@ -128,7 +128,7 @@ public static function parseRemoteUrl(string $url): array /** * '/(?\*| ) (?[^\s]+) +((?:->) (?[^\s]+)|(?[0-9a-z]{7}) (?.*))/' */ - public const PATTERN_BR_LINE = '/(?\*| ) (?[^\s]+) +((?:->) (?[^\s]+)|(?[0-9a-z]{4,41}) (?.*))/'; + public const PATTERN_BR_LINE = '/(?\*| ) (?\S+) +((?:->) (?\S+)|(?[0-9a-z]{4,41}) (?.*))/'; /** * @param string $line @@ -146,11 +146,11 @@ public static function parseBranchLine(string $line, bool $verbose = true): arra 'alias' => '', ]; - $line = trim($line); if (!$verbose) { // eg: // * current_branch // another_branch + $line = trim($line); if (str_starts_with($line, '*')) { $branch['current'] = true; // clear starts diff --git a/src/Info/BranchInfos.php b/src/Info/BranchInfos.php index 6dea948..7b6d8ad 100644 --- a/src/Info/BranchInfos.php +++ b/src/Info/BranchInfos.php @@ -73,6 +73,9 @@ public static function fromStrings(array $lines, bool $parse = true): self return $parse ? $self->parse() : $self; } + /** + * @return $this + */ public function parse(): self { if ($this->parsed) {