From abc9d60fcc7a53b9baa633fc7f61de5d3355df9e Mon Sep 17 00:00:00 2001 From: rkerner Date: Mon, 2 Feb 2015 14:36:50 +0100 Subject: [PATCH 1/6] added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches --- res/composer-schema.json | 7 ++ .../Package/Loader/RootPackageLoader.php | 11 +++ .../Package/Loader/RootPackageLoaderTest.php | 76 +++++++++++++++++++ 3 files changed, 94 insertions(+) diff --git a/res/composer-schema.json b/res/composer-schema.json index 905199247..3f3f595cd 100644 --- a/res/composer-schema.json +++ b/res/composer-schema.json @@ -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" + } } } } diff --git a/src/Composer/Package/Loader/RootPackageLoader.php b/src/Composer/Package/Loader/RootPackageLoader.php index a067fa6a8..face114af 100644 --- a/src/Composer/Package/Loader/RootPackageLoader.php +++ b/src/Composer/Package/Loader/RootPackageLoader.php @@ -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; diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index 1a6a3bf78..d3bab647f 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -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()); + } } From a8b8a2e143a44dd9b0f6e40d1dfd3367f0ea1623 Mon Sep 17 00:00:00 2001 From: rkerner Date: Wed, 11 Feb 2015 15:57:33 +0100 Subject: [PATCH 2/6] * added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches * added documentation to doc/04-schema.md --- doc/04-schema.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/doc/04-schema.md b/doc/04-schema.md index 96641e8fe..a7be21766 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -786,3 +786,32 @@ 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. + +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. \ No newline at end of file From 62636cdd64b9e1653e617605fec90c9f8f1d0a2c Mon Sep 17 00:00:00 2001 From: rkerner Date: Wed, 11 Feb 2015 15:59:26 +0100 Subject: [PATCH 3/6] * added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches * added documentation to doc/04-schema.md * fixed indentation --- doc/04-schema.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index a7be21766..6c0a42116 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -802,16 +802,16 @@ with a valid version or special branch name like master, you can set patterns fo names, that should be handled as dev version branches. 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 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: +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". +Then "composer show -s" will give you "versions : * dev-latest-testing". Optional. \ No newline at end of file From 86c7dfcd94aedbc9037465d2ce526f3b5e558583 Mon Sep 17 00:00:00 2001 From: rkerner Date: Wed, 11 Feb 2015 16:00:43 +0100 Subject: [PATCH 4/6] * added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches * added documentation to doc/04-schema.md * fixed indentation --- doc/04-schema.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index 6c0a42116..0fd8fd6ed 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -785,8 +785,6 @@ 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. @@ -814,4 +812,6 @@ If you configure latest-.* as a pattern for non-feature-branches like this: Then "composer show -s" will give you "versions : * dev-latest-testing". -Optional. \ No newline at end of file +Optional. + +← [Command-line interface](03-cli.md) | [Repositories](05-repositories.md) → \ No newline at end of file From 40b498c96e5208df324d31088ac35dba78c258dc Mon Sep 17 00:00:00 2001 From: rkerner Date: Wed, 11 Feb 2015 16:01:41 +0100 Subject: [PATCH 5/6] * added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches * added documentation to doc/04-schema.md * fixed indentation and styling --- doc/04-schema.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/04-schema.md b/doc/04-schema.md index 0fd8fd6ed..b0b904687 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -801,7 +801,7 @@ names, that should be handled as dev version branches. 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". +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: @@ -809,8 +809,7 @@ 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". - +Then "composer show -s" will give you `versions : * dev-latest-testing`. Optional. From 38d546da453762c37ee19e6ee9f4f59ce4af5b74 Mon Sep 17 00:00:00 2001 From: rkerner Date: Wed, 11 Feb 2015 16:03:17 +0100 Subject: [PATCH 6/6] * added non-feature-branches to handle non-numeric branches matching configured patterns not been handled as feature branches * added documentation to doc/04-schema.md * fixed indentation and styling --- doc/04-schema.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/04-schema.md b/doc/04-schema.md index b0b904687..dc68f6963 100644 --- a/doc/04-schema.md +++ b/doc/04-schema.md @@ -799,7 +799,11 @@ To handle non-numeric named branches as versions instead of searching for a pare 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`.