From e36f2ea618642f803faa2d2e5c8484ce5591b211 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 16 Oct 2014 22:13:17 -0300 Subject: [PATCH 1/2] Added branch-alias for dev-master to --version|-V output when current version is actually a revision (a non release/git tag). This replies the work done in #3352 respecting other uses of ```Composer::VERSION``` constant. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | Doc PR | none --- src/Composer/Compiler.php | 10 ++++++++++ src/Composer/Composer.php | 1 + src/Composer/Console/Application.php | 10 ++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 41c30d6d1..20989cf94 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -12,6 +12,7 @@ namespace Composer; +use Composer\Json\JsonFile; use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Process; @@ -24,6 +25,7 @@ use Symfony\Component\Process\Process; class Compiler { private $version; + private $branchAliasVersion = ''; private $versionDate; /** @@ -48,6 +50,13 @@ class Compiler if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.'); } + $localConfig = __DIR__.'/../../composer.json'; + $file = new JsonFile($localConfig); + $localConfig = $file->read(); + + if (isset($localConfig['extra']['branch-alias']['dev-master'])) { + $this->branchAliasVersion = $localConfig['extra']['branch-alias']['dev-master']; + } $date = new \DateTime(trim($process->getOutput())); $date->setTimezone(new \DateTimeZone('UTC')); $this->versionDate = $date->format('Y-m-d H:i:s'); @@ -138,6 +147,7 @@ class Compiler if ($path === 'src/Composer/Composer.php') { $content = str_replace('@package_version@', $this->version, $content); + $content = str_replace('@package_branch_alias_version@', $this->branchAliasVersion, $content); $content = str_replace('@release_date@', $this->versionDate, $content); } diff --git a/src/Composer/Composer.php b/src/Composer/Composer.php index 6731ea9a4..c874a0796 100644 --- a/src/Composer/Composer.php +++ b/src/Composer/Composer.php @@ -29,6 +29,7 @@ use Composer\Autoload\AutoloadGenerator; class Composer { const VERSION = '@package_version@'; + const BRANCH_ALIAS_VERSION = '@package_branch_alias_version@'; const RELEASE_DATE = '@release_date@'; /** diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 7148a9a11..fa866c247 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -265,6 +265,16 @@ class Application extends BaseApplication */ public function getLongVersion() { + if (Composer::BRANCH_ALIAS_VERSION) { + return sprintf( + '%s version %s (%s) %s', + $this->getName(), + Composer::BRANCH_ALIAS_VERSION, + $this->getVersion(), + Composer::RELEASE_DATE + ); + } + return parent::getLongVersion() . ' ' . Composer::RELEASE_DATE; } From 5a473439ed28bdf7ce397d607fa99cb2df9d80c3 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Fri, 17 Oct 2014 15:07:26 -0300 Subject: [PATCH 2/2] Updated $branchAliasVersion set based on @Seldaek's suggestion. --- src/Composer/Compiler.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index 20989cf94..b1b3725c6 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -50,13 +50,7 @@ class Compiler if ($process->run() != 0) { throw new \RuntimeException('Can\'t run git log. You must ensure to run compile from composer git repository clone and that git binary is available.'); } - $localConfig = __DIR__.'/../../composer.json'; - $file = new JsonFile($localConfig); - $localConfig = $file->read(); - if (isset($localConfig['extra']['branch-alias']['dev-master'])) { - $this->branchAliasVersion = $localConfig['extra']['branch-alias']['dev-master']; - } $date = new \DateTime(trim($process->getOutput())); $date->setTimezone(new \DateTimeZone('UTC')); $this->versionDate = $date->format('Y-m-d H:i:s'); @@ -64,6 +58,14 @@ class Compiler $process = new Process('git describe --tags HEAD'); if ($process->run() == 0) { $this->version = trim($process->getOutput()); + } else { + // get branch-alias defined in composer.json for dev-master (if any) + $localConfig = __DIR__.'/../../composer.json'; + $file = new JsonFile($localConfig); + $localConfig = $file->read(); + if (isset($localConfig['extra']['branch-alias']['dev-master'])) { + $this->branchAliasVersion = $localConfig['extra']['branch-alias']['dev-master']; + } } $phar = new \Phar($pharFile, 0, 'composer.phar');