Skip to content

Inconsistent output of composer --version since 2.3 #10683

@dzuelke

Description

@dzuelke

composer --version used to say "Composer version x.y…", but now no longer contains the "version " part for stable releases (but it's still there for dev snapshots):

% composer --version
Composer version 2.2.7 2022-02-25 11:12:27

% composer selfupdate --stable
Upgrading to version 2.3.2 (stable channel).

% composer --version          
Composer 2.3.2 2022-03-30 20:45:25

% composer selfupdate --snapshot
Upgrading to version 29513c15da7115874ea247fe281ccd48c768b2f5 (snapshot channel).

% composer --version            
Composer version 2.3-dev (2.3-dev+29513c15da7115874ea247fe281ccd48c768b2f5) 2022-03-31 15:26:35

The coloring is also different:

  • when "version " is there, "Composer" is printed green and the version number (with dev suffix) is printed yellow;
  • when "version " is missing, only the version number is printed green

This may (well... for me, it did) break code that greps out the version number.

The cause lies in

public function getLongVersion(): string
{
if (Composer::BRANCH_ALIAS_VERSION && Composer::BRANCH_ALIAS_VERSION !== '@package_branch_alias_version'.'@') {
return sprintf(
'<info>%s</info> version <comment>%s (%s)</comment> %s',
$this->getName(),
Composer::BRANCH_ALIAS_VERSION,
$this->getVersion(),
Composer::RELEASE_DATE
);
}
return parent::getLongVersion() . ' ' . Composer::RELEASE_DATE;
}
; the parent::getLongVersion() in Symfony 5.4 (or earlier) now doesn't contain "version" anymore:

2.8:
https://github.com/symfony/console/blob/cbcf4b5e233af15cd2bbd50dee1ccc9b7927dc12/Application.php#L304-L315

5.4:
https://github.com/symfony/console/blob/900275254f0a1a2afff1ab0e11abd5587a10e1d6/Application.php#L467-L478

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions