added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches
parent
7adc41d02c
commit
abc9d60fcc
|
@ -367,6 +367,13 @@
|
|||
"format": "uri"
|
||||
}
|
||||
}
|
||||
},
|
||||
"non-feature-branches": {
|
||||
"type": ["array"],
|
||||
"description": "A set of string or regex patterns for non-numeric branch names that will not be handles as feature branches.",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,7 +272,18 @@ class RootPackageLoader extends ArrayLoader
|
|||
) {
|
||||
$branch = preg_replace('{^dev-}', '', $version);
|
||||
$length = PHP_INT_MAX;
|
||||
|
||||
$nonFeatureBranches = '';
|
||||
if(!empty($config['non-feature-branches'])) {
|
||||
$nonFeatureBranches = implode('|', $config['non-feature-branches']);
|
||||
}
|
||||
|
||||
foreach ($branches as $candidate) {
|
||||
// return directly, if branch is configured to be non-feature branch
|
||||
if($candidate === $branch && preg_match('{^(' . $nonFeatureBranches . ')$}', $candidate)) {
|
||||
return $version;
|
||||
}
|
||||
|
||||
// do not compare against other feature branches
|
||||
if ($candidate === $branch || !preg_match('{^(master|trunk|default|develop|\d+\..+)$}', $candidate, $match)) {
|
||||
continue;
|
||||
|
|
|
@ -153,4 +153,80 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
|
|||
'qux/quux' => BasePackage::STABILITY_RC,
|
||||
), $package->getStabilityFlags());
|
||||
}
|
||||
|
||||
public function testFeatureBranchPrettyVersion()
|
||||
{
|
||||
if (!function_exists('proc_open')) {
|
||||
$this->markTestSkipped('proc_open() is not available');
|
||||
}
|
||||
|
||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$self = $this;
|
||||
|
||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
||||
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
|
||||
if (0 === strpos($command, 'git rev-list')) {
|
||||
$output = "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
||||
return 1; //0;
|
||||
}
|
||||
|
||||
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||
|
||||
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
$config = new Config;
|
||||
$config->merge(array('repositories' => array('packagist' => false)));
|
||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
||||
$package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
|
||||
|
||||
$this->assertEquals("dev-master", $package->getPrettyVersion());
|
||||
}
|
||||
|
||||
public function testNonFeatureBranchPrettyVersion()
|
||||
{
|
||||
if (!function_exists('proc_open')) {
|
||||
$this->markTestSkipped('proc_open() is not available');
|
||||
}
|
||||
|
||||
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$self = $this;
|
||||
|
||||
/* Can do away with this mock object when https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 is fixed */
|
||||
$processExecutor = new ProcessExecutorMock(function($command, &$output = null, $cwd = null) use ($self) {
|
||||
if (0 === strpos($command, 'git rev-list')) {
|
||||
$output = "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ('git branch --no-color --no-abbrev -v' !== $command) {
|
||||
return 1; //0;
|
||||
}
|
||||
|
||||
$self->assertEquals('git branch --no-color --no-abbrev -v', $command);
|
||||
|
||||
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
|
||||
|
||||
return 0;
|
||||
});
|
||||
|
||||
$config = new Config;
|
||||
$config->merge(array('repositories' => array('packagist' => false)));
|
||||
$loader = new RootPackageLoader($manager, $config, null, $processExecutor);
|
||||
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
|
||||
|
||||
$this->assertEquals("dev-latest-production", $package->getPrettyVersion());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue