Reverse order of version guessing for git, fixes #4673

main
Jordi Boggiano 8 years ago
parent bad80878bc
commit 5b65221523

@ -81,9 +81,8 @@ class VersionGuesser
private function guessGitVersion(array $packageConfig, $path)
{
GitUtil::cleanEnv();
$version = null;
$commit = null;
$version = $this->versionFromGitTags($path);
$version = null;
// try to fetch current version from git branch
if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output, $path)) {
@ -93,16 +92,14 @@ 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 (!$version) {
if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
$version = 'dev-' . $match[2];
$isFeatureBranch = true;
} else {
$version = $this->versionParser->normalizeBranch($match[1]);
$isFeatureBranch = 0 === strpos($version, 'dev-');
if ('9999999-dev' === $version) {
$version = 'dev-' . $match[1];
}
if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') {
$version = 'dev-' . $match[2];
$isFeatureBranch = true;
} else {
$version = $this->versionParser->normalizeBranch($match[1]);
$isFeatureBranch = 0 === strpos($version, 'dev-');
if ('9999999-dev' === $version) {
$version = 'dev-' . $match[1];
}
}
@ -124,6 +121,10 @@ class VersionGuesser
}
}
if (!$version) {
$version = $this->versionFromGitTags($path);
}
return array('version' => $version, 'commit' => $commit);
}

Loading…
Cancel
Save