Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. VersionGuesser.php

function VersionGuesser::guessHgVersion

Parameters

array<string, mixed> $packageConfig:

Return value

array{version: string|null, commit: ''|null, pretty_version: string|null, feature_version?: string|null, feature_pretty_version?: string|null}|null

1 call to VersionGuesser::guessHgVersion()
VersionGuesser::guessVersion in vendor/composer/composer/src/Composer/Package/Version/VersionGuesser.php
@phpstan-return Version|null

File

vendor/composer/composer/src/Composer/Package/Version/VersionGuesser.php, line 237

Class

VersionGuesser
Try to guess the current version number based on different VCS configuration.

Namespace

Composer\Package\Version

Code

private function guessHgVersion(array $packageConfig, string $path) : ?array {
    // try to fetch current version from hg branch
    if (0 === $this->process
        ->execute([
        'hg',
        'branch',
    ], $output, $path)) {
        $branch = trim($output);
        $version = $this->versionParser
            ->normalizeBranch($branch);
        $isFeatureBranch = 0 === strpos($version, 'dev-');
        if (VersionParser::DEFAULT_BRANCH_ALIAS === $version) {
            return [
                'version' => $version,
                'commit' => null,
                'pretty_version' => 'dev-' . $branch,
            ];
        }
        if (!$isFeatureBranch) {
            return [
                'version' => $version,
                'commit' => null,
                'pretty_version' => $version,
            ];
        }
        // re-use the HgDriver to fetch branches (this properly includes bookmarks)
        $io = new NullIO();
        $driver = new HgDriver([
            'url' => $path,
        ], $io, $this->config, new HttpDownloader($io, $this->config), $this->process);
        $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['commit'] = '';
        $result['feature_version'] = $version;
        $result['feature_pretty_version'] = $version;
        return $result;
    }
    return null;
}
RSS feed
Powered by Drupal