1
0
Fork 0

Merge pull request from GHSA-v9qv-c7wm-wgmf

2.2
Jordi Boggiano 2024-06-10 14:56:13 +02:00 committed by GitHub
parent ea0f2e7c2c
commit fc57b93603
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -176,7 +176,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, '%candidate%..%branch%');
$version = $result['version']; $version = $result['version'];
$prettyVersion = $result['pretty_version']; $prettyVersion = $result['pretty_version'];
} }
@ -254,7 +254,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, '"not ancestors(\'%candidate%\') and ancestors(\'%branch%\')"');
$result['commit'] = ''; $result['commit'] = '';
$result['feature_version'] = $version; $result['feature_version'] = $version;
$result['feature_pretty_version'] = $version; $result['feature_pretty_version'] = $version;
@ -271,12 +271,13 @@ class VersionGuesser
* @param string[] $branches * @param string[] $branches
* @param string $scmCmdline * @param string $scmCmdline
* @param string $path * @param string $path
* @param string $arg
* *
* @phpstan-param non-empty-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, $version, array $branches, $scmCmdline, $path) private function guessFeatureVersion(array $packageConfig, $version, array $branches, $scmCmdline, $path, $arg)
{ {
$prettyVersion = $version; $prettyVersion = $version;
@ -315,7 +316,7 @@ class VersionGuesser
continue; continue;
} }
$cmdLine = str_replace(array('%candidate%', '%branch%'), array($candidate, $branch), $scmCmdline); $cmdLine = str_replace($arg, str_replace(array('%candidate%', '%branch%'), array($candidate, $branch), $arg), $scmCmdline);
if (0 !== $this->process->execute($cmdLine, $output, $path)) { if (0 !== $this->process->execute($cmdLine, $output, $path)) {
continue; continue;
} }

View File

@ -121,7 +121,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",
), ),
array( array(
'cmd' => 'git rev-list arbitrary..feature', 'cmd' => 'git rev-list -- arbitrary..feature',
'stdout' => "$anotherCommitHash\n", 'stdout' => "$anotherCommitHash\n",
), ),
), true); ), true);
@ -151,7 +151,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",
), ),
array( array(
'cmd' => 'git rev-list latest-testing..feature', 'cmd' => 'git rev-list -- latest-testing..feature',
'stdout' => "$anotherCommitHash\n", 'stdout' => "$anotherCommitHash\n",
), ),
), true); ), true);
@ -364,7 +364,7 @@ class VersionGuesserTest extends TestCase
"remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n", "remotes/origin/1.5 03a15d220da53c52eddd5f32ffca64a7b3801bea Commit message\n",
), ),
array( array(
'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);