1
0
Fork 0

Attempt at fixing support for git 2.11, refs #5942

pull/5954/head
Jordi Boggiano 2016-12-07 00:59:38 +01:00
parent 1dcb2b5758
commit e54c7478ee
2 changed files with 34 additions and 2 deletions

View File

@ -97,8 +97,8 @@ 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+\)|\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
if ($branch && preg_match('{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\(HEAD detached at FETCH_HEAD\)|\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;
$isFeatureBranch = true;

View File

@ -91,6 +91,38 @@ class VersionGuesserTest extends \PHPUnit_Framework_TestCase
$this->assertEquals("dev-$commitHash", $versionData['version']);
}
public function testDetachedHeadBecomesDevHashGit2()
{
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute'))
->disableArgumentCloning()
->disableOriginalConstructor()
->getMock()
;
$self = $this;
$executor
->expects($this->at(0))
->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";
return 0;
})
;
$config = new Config;
$config->merge(array('repositories' => array('packagist' => false)));
$guesser = new VersionGuesser($config, $executor, new VersionParser());
$versionData = $guesser->guessVersion(array(), 'dummy/path');
$this->assertEquals("dev-$commitHash", $versionData['version']);
}
public function testTagBecomesVersion()
{
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')