1
0
Fork 0

Merge pull request from GHSA-v9qv-c7wm-wgmf

pull/12013/head
Jordi Boggiano 2024-06-10 14:56:13 +02:00 committed by GitHub
parent fa3b9582c3
commit 6bd43dff85
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 10 deletions

View File

@ -173,7 +173,7 @@ class VersionGuesser
$featurePrettyVersion = $prettyVersion; $featurePrettyVersion = $prettyVersion;
// try to find the best (nearest) version branch to assume this feature's version // 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']; $version = $result['version'];
$prettyVersion = $result['pretty_version']; $prettyVersion = $result['pretty_version'];
} }
@ -248,7 +248,7 @@ class VersionGuesser
$branches = array_map('strval', array_keys($driver->getBranches())); $branches = array_map('strval', array_keys($driver->getBranches()));
// try to find the best (nearest) version branch to assume this feature's version // 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['commit'] = '';
$result['feature_version'] = $version; $result['feature_version'] = $version;
$result['feature_pretty_version'] = $version; $result['feature_pretty_version'] = $version;
@ -261,13 +261,12 @@ class VersionGuesser
/** /**
* @param array<string, mixed> $packageConfig * @param array<string, mixed> $packageConfig
* @param string[] $branches * @param list<string> $branches
* * @param list<string> $scmCmdline
* @phpstan-param non-empty-string $scmCmdline
* *
* @return array{version: string|null, pretty_version: string|null} * @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; $prettyVersion = $version;
@ -309,7 +308,9 @@ class VersionGuesser
continue; 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 { $promises[] = $this->process->executeAsync($cmdLine, $path)->then(function (Process $process) use (&$length, &$version, &$prettyVersion, $candidateVersion, &$promises): void {
if (!$process->isSuccessful()) { if (!$process->isSuccessful()) {
return; return;

View File

@ -117,7 +117,7 @@ class VersionGuesserTest extends TestCase
'stdout' => " arbitrary $commitHash Commit message\n* feature $anotherCommitHash Another message\n", '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", 'stdout' => "$anotherCommitHash\n",
], ],
], true); ], true);
@ -147,7 +147,7 @@ class VersionGuesserTest extends TestCase
'stdout' => " latest-testing $commitHash Commit message\n* feature $anotherCommitHash Another message\n", '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", 'stdout' => "$anotherCommitHash\n",
], ],
], true); ], true);
@ -352,7 +352,7 @@ class VersionGuesserTest extends TestCase
"remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n", "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", 'stdout' => "\n",
], ],
], true); ], true);