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,7 +92,6 @@ 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;
@ -104,7 +102,6 @@ class VersionGuesser
$version = 'dev-' . $match[1]; $version = 'dev-' . $match[1];
} }
} }
}
if ($match[2]) { if ($match[2]) {
$commit = $match[2]; $commit = $match[2];
@ -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