From bcd8a73e8c788232359c8d79ded7a7ca10ca3c4d Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Tue, 22 Sep 2020 18:49:53 +0200 Subject: [PATCH 01/11] Fix support for running diagnose without openssl The diagnose command already warns when openssl is not available. But the command was failing later when displaying the Openssl version. --- src/Composer/Command/DiagnoseCommand.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index b7739ff18..94f7eaad1 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -172,7 +172,9 @@ EOT $io->write(sprintf('PHP binary path: %s', PHP_BINARY)); } - $io->write(sprintf('OpenSSL version: %s', OPENSSL_VERSION_TEXT)); + if (defined('OPENSSL_VERSION_TEXT') { + $io->write(sprintf('OpenSSL version: %s', OPENSSL_VERSION_TEXT)); + } return $this->exitCode; } From d6b39b4c55e206b1e500238c8bddbdc703743094 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 24 Sep 2020 11:35:38 +0200 Subject: [PATCH 02/11] Fix syntax error & improve handling --- src/Composer/Command/DiagnoseCommand.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Composer/Command/DiagnoseCommand.php b/src/Composer/Command/DiagnoseCommand.php index 94f7eaad1..30f82be62 100644 --- a/src/Composer/Command/DiagnoseCommand.php +++ b/src/Composer/Command/DiagnoseCommand.php @@ -172,9 +172,7 @@ EOT $io->write(sprintf('PHP binary path: %s', PHP_BINARY)); } - if (defined('OPENSSL_VERSION_TEXT') { - $io->write(sprintf('OpenSSL version: %s', OPENSSL_VERSION_TEXT)); - } + $io->write('OpenSSL version: ' . (defined('OPENSSL_VERSION_TEXT') ? ''.OPENSSL_VERSION_TEXT.'' : 'missing')); return $this->exitCode; } From bfb4abfb56a1e71990d6860dfea34e77a6e14340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Fri, 2 Oct 2020 10:11:47 +0200 Subject: [PATCH 03/11] Fixed description of StatusCommand: It do list all changes in vendor, not only for "source" ones I tested it, and even with "dist" packages, the status command is able to find modified vendor (And that's amazing, thanks) --- src/Composer/Command/StatusCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/StatusCommand.php b/src/Composer/Command/StatusCommand.php index 6d836d2bf..6e07ed5d9 100644 --- a/src/Composer/Command/StatusCommand.php +++ b/src/Composer/Command/StatusCommand.php @@ -43,7 +43,7 @@ class StatusCommand extends BaseCommand { $this ->setName('status') - ->setDescription('Shows a list of locally modified packages, for packages installed from source.') + ->setDescription('Shows a list of locally modified packages.') ->setDefinition(array( new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Show modified files for each directory that contains changes.'), )) From ad643d9957cc573908bc30bb144e5f91245816c3 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 7 Oct 2020 14:17:49 +0200 Subject: [PATCH 04/11] VersionGuesser: Analyze remote origin and upstream branches too --- .../Package/Version/VersionGuesser.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index fb1ee712b..fd8dd7a91 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -118,7 +118,7 @@ class VersionGuesser $isDetached = false; // 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 -a --no-color --no-abbrev -v', $output, $path)) { $branches = array(); $isFeatureBranch = false; @@ -141,8 +141,8 @@ class VersionGuesser } } - if ($branch && !preg_match('{^ *[^/]+/HEAD }', $branch)) { - if (preg_match('{^(?:\* )? *(\S+) *([a-f0-9]+) .*$}', $branch, $match)) { + if ($branch && !preg_match('{^ *.+/HEAD }', $branch)) { + if (preg_match('{^(?:\* )? *((?:remotes/(?:origin|upstream)/)[^\s/]+) *([a-f0-9]+) .*$}', $branch, $match)) { $branches[] = $match[1]; } } @@ -245,13 +245,14 @@ class VersionGuesser } foreach ($branches as $candidate) { + $candidateVersion = preg_replace('{^remotes/\S+/}', '', $candidate); // return directly, if branch is configured to be non-feature branch - if ($candidate === $branch && preg_match('{^(' . $nonFeatureBranches . ')$}', $candidate)) { + if ($candidate === $branch && preg_match('{^(' . $nonFeatureBranches . ')$}', $candidateVersion)) { break; } // do not compare against itself or other feature branches - if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . '|master|trunk|default|develop|\d+\..+)$}', $candidate, $match)) { + if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . '|master|trunk|default|develop|\d+\..+)$}', $candidateVersion, $match)) { continue; } @@ -262,8 +263,11 @@ class VersionGuesser if (strlen($output) < $length) { $length = strlen($output); - $version = $this->versionParser->normalizeBranch($candidate); - $prettyVersion = 'dev-' . $match[1]; + $version = $this->versionParser->normalizeBranch($candidateVersion); + $prettyVersion = 'dev-' . $candidateVersion; + if ($length === 0) { + break; + } } } } From db2f09a36167622a5d868d6000ac1e88cba0afcb Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 7 Oct 2020 14:25:55 +0200 Subject: [PATCH 05/11] VersionGuesser: Update tests to match new git command generated --- .../Package/Version/VersionGuesserTest.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 5d8d4f5eb..5347d1487 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -48,7 +48,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at($step)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); return 128; }) @@ -116,7 +116,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash, $anotherCommitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* master $commitHash Commit message\n(no branch) $anotherCommitHash Commit message\n"; return 0; @@ -153,7 +153,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash, $anotherCommitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = " arbitrary $commitHash Commit message\n* current $anotherCommitHash Another message\n"; return 0; @@ -200,7 +200,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash, $anotherCommitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = " latest-testing $commitHash Commit message\n* current $anotherCommitHash Another message\n"; return 0; @@ -247,7 +247,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash, $anotherCommitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* latest-testing $commitHash Commit message\n current $anotherCommitHash Another message\n master $anotherCommitHash Another message\n"; return 0; @@ -282,7 +282,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* (no branch) $commitHash Commit message\n"; return 0; @@ -313,7 +313,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* (HEAD detached at FETCH_HEAD) $commitHash Commit message\n"; return 0; @@ -343,7 +343,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self, $commitHash) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* (HEAD detached at 03a15d220) $commitHash Commit message\n"; return 0; @@ -372,7 +372,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* (HEAD detached at v2.0.5-alpha2) 433b98d4218c181bae01865901aac045585e8a1a Commit message\n"; return 0; @@ -413,7 +413,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* (HEAD detached at 1.0.0) c006f0c12bbbf197b5c071ffb1c0e9812bb14a4d Commit message\n"; return 0; @@ -455,7 +455,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* foo 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n"; return 0; @@ -485,7 +485,7 @@ class VersionGuesserTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* 1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n"; return 0; From b3c465d55a78d645f1063b82f46fbf4aa2566a0f Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 7 Oct 2020 15:10:20 +0200 Subject: [PATCH 06/11] VersionGuesser: local branches still need to be considered --- src/Composer/Package/Version/VersionGuesser.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index fd8dd7a91..072a53dfa 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -142,7 +142,7 @@ class VersionGuesser } if ($branch && !preg_match('{^ *.+/HEAD }', $branch)) { - if (preg_match('{^(?:\* )? *((?:remotes/(?:origin|upstream)/)[^\s/]+) *([a-f0-9]+) .*$}', $branch, $match)) { + if (preg_match('{^(?:\* )? *((?:remotes/(?:origin|upstream)/)?[^\s/]+) *([a-f0-9]+) .*$}', $branch, $match)) { $branches[] = $match[1]; } } From 92722a9a4cd4e71db8027437d7f0ee3dc97b5420 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 7 Oct 2020 15:11:08 +0200 Subject: [PATCH 07/11] VersionGuesser: Fix root package loader test which relies on git cmd in guesser --- tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php index a94539279..858e95231 100644 --- a/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/RootPackageLoaderTest.php @@ -137,7 +137,7 @@ class RootPackageLoaderTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n"; return 0; @@ -187,7 +187,7 @@ class RootPackageLoaderTest extends TestCase ->expects($this->at(0)) ->method('execute') ->willReturnCallback(function ($command, &$output) use ($self) { - $self->assertEquals('git branch --no-color --no-abbrev -v', $command); + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); $output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n"; return 0; From 89afb823b636f31e1f9e78f7f49b9056d6a78c3a Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Wed, 7 Oct 2020 15:21:04 +0200 Subject: [PATCH 08/11] VersionGuesser: Add test for remote version guess --- .../Package/Version/VersionGuesserTest.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 5347d1487..337438fc0 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -500,4 +500,46 @@ class VersionGuesserTest extends TestCase $this->assertEquals("1.5.x-dev", $versionData['pretty_version']); $this->assertEquals("1.5.9999999.9999999-dev", $versionData['version']); } + + public function testRemoteBranchesAreSelected() + { + $executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') + ->setMethods(array('execute')) + ->disableArgumentCloning() + ->disableOriginalConstructor() + ->getMock() + ; + + $self = $this; + + $executor + ->expects($this->at(0)) + ->method('execute') + ->willReturnCallback(function ($command, &$output) use ($self) { + $self->assertEquals('git branch -a --no-color --no-abbrev -v', $command); + $output = "* feature-branch 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n". + "remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n"; + + return 0; + }) + ; + + $executor + ->expects($this->at(1)) + ->method('execute') + ->willReturnCallback(function ($command, &$output, $path) use ($self) { + $self->assertEquals('git rev-list remotes/origin/1.5..feature-branch', $command); + $output = "\n"; + + return 0; + }) + ; + + $config = new Config; + $config->merge(array('repositories' => array('packagist' => false))); + $guesser = new VersionGuesser($config, $executor, new VersionParser()); + $versionData = $guesser->guessVersion(array('version' => 'self.version'), 'dummy/path'); + $this->assertEquals("1.5.x-dev", $versionData['pretty_version']); + $this->assertEquals("1.5.9999999.9999999-dev", $versionData['version']); + } } From f9913205ddac6bbf356aa2f6d9dbab56bc583037 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 8 Oct 2020 11:04:39 +0200 Subject: [PATCH 09/11] Fix VcsRepositoryTest --- tests/Composer/Test/Repository/VcsRepositoryTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Composer/Test/Repository/VcsRepositoryTest.php b/tests/Composer/Test/Repository/VcsRepositoryTest.php index 0cab2f8bb..72fd36a7b 100644 --- a/tests/Composer/Test/Repository/VcsRepositoryTest.php +++ b/tests/Composer/Test/Repository/VcsRepositoryTest.php @@ -42,8 +42,8 @@ class VcsRepositoryTest extends TestCase return; } - if (!@mkdir(self::$gitRepo) || !@chdir(self::$gitRepo)) { - $this->skipped = 'Could not create and move into the temp git repo '.self::$gitRepo; + if (!@chdir(self::$gitRepo)) { + $this->skipped = 'Could not move into the temp git repo '.self::$gitRepo; return; } From 791bbc80a4e9192a59a37d1282ff5032c4e52692 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 8 Oct 2020 14:26:04 +0200 Subject: [PATCH 10/11] Backport some fixes from 2.0, and fix sorting to sort remote branches after local ones, refs #9270 --- .../Package/Version/VersionGuesser.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 072a53dfa..a71c915ad 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -244,12 +244,27 @@ class VersionGuesser $nonFeatureBranches = implode('|', $packageConfig['non-feature-branches']); } + // return directly, if branch is configured to be non-feature branch + if (preg_match('{^(' . $nonFeatureBranches . ')$}', $branch) && in_array($branch, $branches, true)) { + return array('version' => $version, 'pretty_version' => $prettyVersion); + } + + // sort local branches first then remote ones + // and sort numeric branches below named ones, to make sure if the branch has the same distance from main and 1.10 and 1.9 for example, main is picked + // and sort using natural sort so that 1.10 will appear before 1.9 + usort($branches, function ($a, $b) { + $aRemote = 0 === strpos($a, 'remotes/'); + $bRemote = 0 === strpos($b, 'remotes/'); + + if ($aRemote !== $bRemote) { + return $aRemote ? 1 : -1; + } + + return strnatcasecmp($b, $a); + }); + foreach ($branches as $candidate) { $candidateVersion = preg_replace('{^remotes/\S+/}', '', $candidate); - // return directly, if branch is configured to be non-feature branch - if ($candidate === $branch && preg_match('{^(' . $nonFeatureBranches . ')$}', $candidateVersion)) { - break; - } // do not compare against itself or other feature branches if ($candidate === $branch || !preg_match('{^(' . $nonFeatureBranches . '|master|trunk|default|develop|\d+\..+)$}', $candidateVersion, $match)) { From 2c6a9aba32098059551ea303e401758d58eff8d9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 8 Oct 2020 14:29:20 +0200 Subject: [PATCH 11/11] Update to latest semver --- composer.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.lock b/composer.lock index 12a005e8d..e484b7229 100644 --- a/composer.lock +++ b/composer.lock @@ -83,16 +83,16 @@ }, { "name": "composer/semver", - "version": "1.7.0", + "version": "1.7.1", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "114f819054a2ea7db03287f5efb757e2af6e4079" + "reference": "38276325bd896f90dfcfe30029aa5db40df387a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/114f819054a2ea7db03287f5efb757e2af6e4079", - "reference": "114f819054a2ea7db03287f5efb757e2af6e4079", + "url": "https://api.github.com/repos/composer/semver/zipball/38276325bd896f90dfcfe30029aa5db40df387a7", + "reference": "38276325bd896f90dfcfe30029aa5db40df387a7", "shasum": "" }, "require": { @@ -154,7 +154,7 @@ "type": "tidelift" } ], - "time": "2020-09-09T09:34:06+00:00" + "time": "2020-09-27T13:13:07+00:00" }, { "name": "composer/spdx-licenses",