1
0
Fork 0

Fix Git branch parsing for detached HEAD on a commit

Current versions of Git output the commit hash as detached HEAD instead
of FETCH_HEAD. The VersionGuesser should be able to handle commit hashes
as well as FETCH_HEAD to detect the correct branch of a commit.
pull/6312/head
Nicole Cordes 2017-03-31 15:02:50 +02:00
parent a5aa33d1a2
commit 313e6b914d
2 changed files with 2 additions and 2 deletions

View File

@ -98,7 +98,7 @@ class VersionGuesser
// find current branch and collect all branch names
foreach ($this->process->splitLines($output) as $branch) {
if ($branch && preg_match('{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at FETCH_HEAD\)|\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
if ($branch && preg_match('{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at \S+\)|\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ' || substr($match[1], 0, 17) === '(HEAD detached at') {
$version = 'dev-' . $match[2];
$prettyVersion = $version;

View File

@ -176,7 +176,7 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self, $commitHash) {
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
$output = "* (HEAD detached at FETCH_HEAD) $commitHash Commit message\n";
$output = "* (HEAD detached at " . substr($commitHash, 0, 9) . ") $commitHash Commit message\n";
return 0;
})