PHPGit
PHPGit copied to clipboard
Branch command assumes all short hashes are 7 characters
The regular expression for parsing lines of output from the git branch command assumes that all short hashes will be exactly 7 characters, but this is not always the case.
The specific line is at src/PHPGit/Command/BranchCommand.php:67:
preg_match('/(?<current>\*| ) (?<name>[^\s]+) +((?:->) (?<alias>[^\s]+)|(?<hash>[0-9a-z]{7}) (?<title>.*))/', $line, $matches);
Suggest changing the hash capturing group to (?<hash>[0-9a-z]{7,40})
to handle all possible cases.
Additionally, the result of preg_match
should probably be checked to see if it succeeded, and either continue the loop or throw an exception?