diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index 2b2b19706..72fc799a7 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -173,7 +173,7 @@ class VersionGuesser $featurePrettyVersion = $prettyVersion; // 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']; $prettyVersion = $result['pretty_version']; } @@ -248,7 +248,7 @@ class VersionGuesser $branches = array_map('strval', array_keys($driver->getBranches())); // 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['feature_version'] = $version; $result['feature_pretty_version'] = $version; @@ -261,13 +261,12 @@ class VersionGuesser /** * @param array $packageConfig - * @param string[] $branches - * - * @phpstan-param non-empty-string $scmCmdline + * @param list $branches + * @param list $scmCmdline * * @return array{version: string|null, pretty_version: string|null} */ - private function guessFeatureVersion(array $packageConfig, ?string $version, array $branches, string $scmCmdline, string $path): array + private function guessFeatureVersion(array $packageConfig, ?string $version, array $branches, array $scmCmdline, string $path): array { $prettyVersion = $version; @@ -309,7 +308,9 @@ class VersionGuesser continue; } - $cmdLine = str_replace(['%candidate%', '%branch%'], [$candidate, $branch], $scmCmdline); + $cmdLine = array_map(static function (string $component) use ($candidate, $branch) { + return str_replace(['%candidate%', '%branch%'], [$candidate, $branch], $component); + }, $scmCmdline); $promises[] = $this->process->executeAsync($cmdLine, $path)->then(function (Process $process) use (&$length, &$version, &$prettyVersion, $candidateVersion, &$promises): void { if (!$process->isSuccessful()) { return; diff --git a/tests/Composer/Test/Package/Version/VersionGuesserTest.php b/tests/Composer/Test/Package/Version/VersionGuesserTest.php index 676ef2420..c6e01251b 100644 --- a/tests/Composer/Test/Package/Version/VersionGuesserTest.php +++ b/tests/Composer/Test/Package/Version/VersionGuesserTest.php @@ -117,7 +117,7 @@ class VersionGuesserTest extends TestCase 'stdout' => " arbitrary $commitHash Commit message\n* feature $anotherCommitHash Another message\n", ], [ - 'cmd' => 'git rev-list arbitrary..feature', + 'cmd' => ['git', 'rev-list', 'arbitrary..feature'], 'stdout' => "$anotherCommitHash\n", ], ], true); @@ -147,7 +147,7 @@ class VersionGuesserTest extends TestCase 'stdout' => " latest-testing $commitHash Commit message\n* feature $anotherCommitHash Another message\n", ], [ - 'cmd' => 'git rev-list latest-testing..feature', + 'cmd' => ['git', 'rev-list', 'latest-testing..feature'], 'stdout' => "$anotherCommitHash\n", ], ], true); @@ -352,7 +352,7 @@ class VersionGuesserTest extends TestCase "remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n", ], [ - 'cmd' => 'git rev-list remotes/origin/1.5..feature-branch', + 'cmd' => ['git', 'rev-list', 'remotes/origin/1.5..feature-branch'], 'stdout' => "\n", ], ], true);