1
0
Fork 0

Merge pull request #3699 from trivago/non_feature_branches

added non-feature-branches
pull/3662/merge
Jordi Boggiano 2015-02-14 15:44:45 +00:00
commit 53925295c3
4 changed files with 127 additions and 1 deletions

View File

@ -878,4 +878,36 @@ The example will include `/dir/foo/bar/file`, `/foo/bar/baz`, `/file.php`,
Optional.
← [Command-line interface](03-cli.md) | [Repositories](05-repositories.md) →
### non-feature-branches
A list of regex patterns of branch names that are non-numeric (e.g. "latest" or something), that will NOT be handled as feature branches. This is an array of string.
If you have non-numeric branch names, for example like "latest", "current", "latest-stable"
or something, that do not look like a version number, then composer handles such branches
as feature branches. This means it searches for parent branches, that look like a version
or ends at special branches (like master) and the root package version number becomes the
version of the parent branch or at least master or something.
To handle non-numeric named branches as versions instead of searching for a parent branch
with a valid version or special branch name like master, you can set patterns for branch
names, that should be handled as dev version branches.
This is really helpful when you have dependencies using "self.version", so that not dev-master,
but the same branch is installed (in the example: latest-testing).
An example:
If you have a testing branch, that is heavily maintained during a testing phase and is
deployed to your staging environment, normally "composer show -s" will give you `versions : * dev-master`.
If you configure latest-.* as a pattern for non-feature-branches like this:
{
"non-feature-branches": ["latest-.*"]
}
Then "composer show -s" will give you `versions : * dev-latest-testing`.
Optional.
← [Command-line interface](03-cli.md) | [Repositories](05-repositories.md) →

View File

@ -409,6 +409,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"
}
}
}
}

View File

@ -277,7 +277,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;

View File

@ -155,4 +155,80 @@ class RootPackageLoaderTest extends \PHPUnit_Framework_TestCase
'zux/complex' => BasePackage::STABILITY_DEV,
), $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());
}
}