Skip to content

Commit

Permalink
fix: fix branch info line parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jun 27, 2022
1 parent fcc182f commit a686db8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/GitUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static function parseRemoteUrl(string $url): array
/**
* '/(?<current>\*| ) (?<name>[^\s]+) +((?:->) (?<alias>[^\s]+)|(?<hash>[0-9a-z]{7}) (?<message>.*))/'
*/
public const PATTERN_BR_LINE = '/(?<current>\*| ) (?<name>[^\s]+) +((?:->) (?<alias>[^\s]+)|(?<hash>[0-9a-z]{4,41}) (?<message>.*))/';
public const PATTERN_BR_LINE = '/(?<current>\*| ) (?<name>\S+) +((?:->) (?<alias>\S+)|(?<hash>[0-9a-z]{4,41}) (?<message>.*))/';

/**
* @param string $line
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/Info/BranchInfos.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a686db8

Please sign in to comment.