|
|
@ -58,18 +58,20 @@ class VersionGuesser
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @param array $packageConfig
|
|
|
|
* @param array $packageConfig
|
|
|
|
* @param string $path Path to guess into
|
|
|
|
* @param string $path Path to guess into
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return array versionData, 'version' and 'commit' keys
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function guessVersion(array $packageConfig, $path)
|
|
|
|
public function guessVersion(array $packageConfig, $path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (function_exists('proc_open')) {
|
|
|
|
if (function_exists('proc_open')) {
|
|
|
|
$version = $this->guessGitVersion($packageConfig, $path);
|
|
|
|
$versionData = $this->guessGitVersion($packageConfig, $path);
|
|
|
|
if (null !== $version) {
|
|
|
|
if (null !== $versionData) {
|
|
|
|
return $version;
|
|
|
|
return $versionData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$version = $this->guessHgVersion($packageConfig, $path);
|
|
|
|
$versionData = $this->guessHgVersion($packageConfig, $path);
|
|
|
|
if (null !== $version) {
|
|
|
|
if (null !== $versionData) {
|
|
|
|
return $version;
|
|
|
|
return $versionData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->guessSvnVersion($packageConfig, $path);
|
|
|
|
return $this->guessSvnVersion($packageConfig, $path);
|
|
|
@ -79,24 +81,19 @@ class VersionGuesser
|
|
|
|
private function guessGitVersion(array $packageConfig, $path)
|
|
|
|
private function guessGitVersion(array $packageConfig, $path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
GitUtil::cleanEnv();
|
|
|
|
GitUtil::cleanEnv();
|
|
|
|
|
|
|
|
$version = null;
|
|
|
|
// try to fetch current version from git tags
|
|
|
|
$commit = null;
|
|
|
|
if (0 === $this->process->execute('git describe --exact-match --tags', $output, $path)) {
|
|
|
|
$version = $this->versionFromGitTags($path);
|
|
|
|
try {
|
|
|
|
|
|
|
|
return $this->versionParser->normalize(trim($output));
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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)) {
|
|
|
|
$branches = array();
|
|
|
|
$branches = array();
|
|
|
|
$isFeatureBranch = false;
|
|
|
|
$isFeatureBranch = false;
|
|
|
|
$version = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
@ -109,6 +106,11 @@ class VersionGuesser
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ($match[2]) {
|
|
|
|
|
|
|
|
$commit = $match[2];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
|
|
|
|
if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) {
|
|
|
|
if (preg_match('{^(?:\* )? *(\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
|
|
|
|
if (preg_match('{^(?:\* )? *(\S+) *([a-f0-9]+) .*$}', $branch, $match)) {
|
|
|
|
$branches[] = $match[1];
|
|
|
|
$branches[] = $match[1];
|
|
|
@ -116,15 +118,26 @@ class VersionGuesser
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!$isFeatureBranch) {
|
|
|
|
if ($isFeatureBranch) {
|
|
|
|
return $version;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try to find the best (nearest) version branch to assume this feature's version
|
|
|
|
// try to find the best (nearest) version branch to assume this feature's version
|
|
|
|
$version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
|
|
|
|
$version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $version;
|
|
|
|
return array('version' => $version, 'commit' => $commit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function versionFromGitTags($path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// try to fetch current version from git tags
|
|
|
|
|
|
|
|
if (0 === $this->process->execute('git describe --exact-match --tags', $output, $path)) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
return $this->versionParser->normalize(trim($output));
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function guessHgVersion(array $packageConfig, $path)
|
|
|
|
private function guessHgVersion(array $packageConfig, $path)
|
|
|
@ -150,7 +163,7 @@ class VersionGuesser
|
|
|
|
// try to find the best (nearest) version branch to assume this feature's version
|
|
|
|
// try to find the best (nearest) version branch to assume this feature's version
|
|
|
|
$version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path);
|
|
|
|
$version = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path);
|
|
|
|
|
|
|
|
|
|
|
|
return $version;
|
|
|
|
return array('version' => $version, 'commit' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -218,11 +231,13 @@ class VersionGuesser
|
|
|
|
$version = 'dev-' . $matches[3];
|
|
|
|
$version = 'dev-' . $matches[3];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $version;
|
|
|
|
return array('version' => $version, 'commit' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $this->versionParser->normalize(trim($matches[1]));
|
|
|
|
$version = $this->versionParser->normalize(trim($matches[1]));
|
|
|
|
|
|
|
|
return array('version' => $version, 'commit' => '');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|