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) private function guessGitVersion(array $packageConfig, $path)
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$version = null;
$commit = null; $commit = null;
$version = $this->versionFromGitTags($path); $version = null;
// try to fetch current version from git branch // try to fetch current version from git branch
if (0 === $this->process->execute('git branch --no-color --no-abbrev -v', $output, $path)) { 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 // find current branch and collect all branch names
foreach ($this->process->splitLines($output) as $branch) { foreach ($this->process->splitLines($output) as $branch) {
if ($branch && preg_match('{^(?:\* ) *(\(no branch\)|\(detached from \S+\)|\S+) *([a-f0-9]+) .*$}', $branch, $match)) { 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 ') {
if ($match[1] === '(no branch)' || substr($match[1], 0, 10) === '(detached ') { $version = 'dev-' . $match[2];
$version = 'dev-' . $match[2]; $isFeatureBranch = true;
$isFeatureBranch = true; } else {
} else { $version = $this->versionParser->normalizeBranch($match[1]);
$version = $this->versionParser->normalizeBranch($match[1]); $isFeatureBranch = 0 === strpos($version, 'dev-');
$isFeatureBranch = 0 === strpos($version, 'dev-'); if ('9999999-dev' === $version) {
if ('9999999-dev' === $version) { $version = 'dev-' . $match[1];
$version = 'dev-' . $match[1];
}
} }
} }
@ -124,6 +121,10 @@ class VersionGuesser
} }
} }
if (!$version) {
$version = $this->versionFromGitTags($path);
}
return array('version' => $version, 'commit' => $commit); return array('version' => $version, 'commit' => $commit);
} }

Loading…
Cancel
Save