Merge branch '1.9'

main
Jordi Boggiano 5 years ago
commit 78217e2313
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -59,7 +59,7 @@ class VersionGuesser
* @param array $packageConfig * @param array $packageConfig
* @param string $path Path to guess into * @param string $path Path to guess into
* *
* @return null|array versionData, 'version', 'pretty_version' and 'commit' keys * @return null|array versionData, 'version', 'pretty_version' and 'commit' keys, if the version is a feature branch, 'feature_version' and 'feature_pretty_version' keys may also be returned
*/ */
public function guessVersion(array $packageConfig, $path) public function guessVersion(array $packageConfig, $path)
{ {
@ -88,10 +88,18 @@ class VersionGuesser
private function postprocess(array $versionData) private function postprocess(array $versionData)
{ {
if (!empty($versionData['feature_version']) && $versionData['feature_version'] === $versionData['version'] && $versionData['feature_pretty_version'] === $versionData['feature_pretty_version']) {
unset($versionData['feature_version'], $versionData['feature_pretty_version']);
}
if ('-dev' === substr($versionData['version'], -4) && preg_match('{\.9{7}}', $versionData['version'])) { if ('-dev' === substr($versionData['version'], -4) && preg_match('{\.9{7}}', $versionData['version'])) {
$versionData['pretty_version'] = preg_replace('{(\.9{7})+}', '.x', $versionData['version']); $versionData['pretty_version'] = preg_replace('{(\.9{7})+}', '.x', $versionData['version']);
} }
if (!empty($versionData['feature_version']) && '-dev' === substr($versionData['feature_version'], -4) && preg_match('{\.9{7}}', $versionData['feature_version'])) {
$versionData['feature_pretty_version'] = preg_replace('{(\.9{7})+}', '.x', $versionData['feature_version']);
}
return $versionData; return $versionData;
} }
@ -101,6 +109,8 @@ class VersionGuesser
$commit = null; $commit = null;
$version = null; $version = null;
$prettyVersion = null; $prettyVersion = null;
$featureVersion = null;
$featurePrettyVersion = null;
$isDetached = false; $isDetached = false;
// try to fetch current version from git branch // try to fetch current version from git branch
@ -135,6 +145,8 @@ class VersionGuesser
} }
if ($isFeatureBranch) { if ($isFeatureBranch) {
$featureVersion = $version;
$featurePrettyVersion = $prettyVersion;
// 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
$result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path); $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'git rev-list %candidate%..%branch%', $path);
$version = $result['version']; $version = $result['version'];
@ -147,6 +159,8 @@ class VersionGuesser
if ($result) { if ($result) {
$version = $result['version']; $version = $result['version'];
$prettyVersion = $result['pretty_version']; $prettyVersion = $result['pretty_version'];
$featureVersion = null;
$featurePrettyVersion = null;
} }
} }
@ -157,6 +171,10 @@ class VersionGuesser
} }
} }
if ($featureVersion) {
return array('version' => $version, 'commit' => $commit, 'pretty_version' => $prettyVersion, 'feature_version' => $featureVersion, 'feature_pretty_version' => $featurePrettyVersion);
}
return array('version' => $version, 'commit' => $commit, 'pretty_version' => $prettyVersion); return array('version' => $version, 'commit' => $commit, 'pretty_version' => $prettyVersion);
} }
@ -198,6 +216,8 @@ 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
$result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path); $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path);
$result['commit'] = ''; $result['commit'] = '';
$result['feature_version'] = $version;
$result['feature_pretty_version'] = $version;
return $result; return $result;
} }

@ -159,19 +159,26 @@ class PathRepository extends ArrayRepository implements ConfigurableRepositoryIn
} }
} }
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
}
if (!isset($package['version'])) { if (!isset($package['version'])) {
$versionData = $this->versionGuesser->guessVersion($package, $path); $versionData = $this->versionGuesser->guessVersion($package, $path);
if (is_array($versionData) && $versionData['pretty_version']) { if (is_array($versionData) && $versionData['pretty_version']) {
// if there is a feature branch detected, we add a second packages with the feature branch version
if (!empty($versionData['feature_pretty_version'])) {
$package['version'] = $versionData['feature_pretty_version'];
$this->addPackage($this->loader->load($package));
}
$package['version'] = $versionData['pretty_version']; $package['version'] = $versionData['pretty_version'];
} else { } else {
$package['version'] = 'dev-master'; $package['version'] = 'dev-master';
} }
} }
$output = '';
if (is_dir($path . DIRECTORY_SEPARATOR . '.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
}
$package = $this->loader->load($package); $package = $this->loader->load($package);
$this->addPackage($package); $this->addPackage($package);
} }

@ -126,13 +126,15 @@ class VersionGuesserTest extends TestCase
$this->assertEquals("9999999-dev", $versionArray['version']); $this->assertEquals("9999999-dev", $versionArray['version']);
$this->assertEquals("dev-master", $versionArray['pretty_version']); $this->assertEquals("dev-master", $versionArray['pretty_version']);
$this->assertArrayNotHasKey('feature_version', $versionArray);
$this->assertArrayNotHasKey('feature_pretty_version', $versionArray);
$this->assertEquals($commitHash, $versionArray['commit']); $this->assertEquals($commitHash, $versionArray['commit']);
} }
public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNaming() public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNaming()
{ {
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$anotherCommitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute')) ->setMethods(array('execute'))
@ -172,12 +174,14 @@ class VersionGuesserTest extends TestCase
$this->assertEquals("dev-arbitrary", $versionArray['version']); $this->assertEquals("dev-arbitrary", $versionArray['version']);
$this->assertEquals($anotherCommitHash, $versionArray['commit']); $this->assertEquals($anotherCommitHash, $versionArray['commit']);
$this->assertEquals("dev-current", $versionArray['feature_version']);
$this->assertEquals("dev-current", $versionArray['feature_pretty_version']);
} }
public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNamingRegex() public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNamingRegex()
{ {
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$anotherCommitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute')) ->setMethods(array('execute'))
@ -217,12 +221,14 @@ class VersionGuesserTest extends TestCase
$this->assertEquals("dev-latest-testing", $versionArray['version']); $this->assertEquals("dev-latest-testing", $versionArray['version']);
$this->assertEquals($anotherCommitHash, $versionArray['commit']); $this->assertEquals($anotherCommitHash, $versionArray['commit']);
$this->assertEquals("dev-current", $versionArray['feature_version']);
$this->assertEquals("dev-current", $versionArray['feature_pretty_version']);
} }
public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNamingWhenOnNonFeatureBranch() public function testGuessVersionReadsAndRespectsNonFeatureBranchesConfigurationForArbitraryNamingWhenOnNonFeatureBranch()
{ {
$commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $commitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea';
$anotherCommitHash = '03a15d220da53c52eddd5f32ffca64a7b3801bea'; $anotherCommitHash = '13a15d220da53c52eddd5f32ffca64a7b3801bea';
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute')) ->setMethods(array('execute'))
@ -251,6 +257,8 @@ class VersionGuesserTest extends TestCase
$this->assertEquals("dev-latest-testing", $versionArray['version']); $this->assertEquals("dev-latest-testing", $versionArray['version']);
$this->assertEquals($commitHash, $versionArray['commit']); $this->assertEquals($commitHash, $versionArray['commit']);
$this->assertArrayNotHasKey('feature_version', $versionArray);
$this->assertArrayNotHasKey('feature_pretty_version', $versionArray);
} }
public function testDetachedHeadBecomesDevHash() public function testDetachedHeadBecomesDevHash()

Loading…
Cancel
Save