1
0
Fork 0

Add version release date to -V output, fixes #2267

pull/2268/head
Jordi Boggiano 2013-09-16 14:08:24 +02:00
parent 941498abbb
commit 5b96caf8ce
3 changed files with 19 additions and 0 deletions

View File

@ -24,6 +24,7 @@ use Symfony\Component\Process\Process;
class Compiler class Compiler
{ {
private $version; private $version;
private $versionDate;
/** /**
* Compiles composer into a single phar file * Compiles composer into a single phar file
@ -43,6 +44,14 @@ class Compiler
} }
$this->version = trim($process->getOutput()); $this->version = trim($process->getOutput());
$process = new Process('git log -n1 --pretty=%ci HEAD', __DIR__);
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.');
}
$date = new \DateTime(trim($process->getOutput()));
$date->setTimezone(new \DateTimeZone('UTC'));
$this->versionDate = $date->format('Y-m-d H:i:s');
$process = new Process('git describe --tags HEAD'); $process = new Process('git describe --tags HEAD');
if ($process->run() == 0) { if ($process->run() == 0) {
$this->version = trim($process->getOutput()); $this->version = trim($process->getOutput());
@ -127,6 +136,7 @@ class Compiler
} }
$content = str_replace('@package_version@', $this->version, $content); $content = str_replace('@package_version@', $this->version, $content);
$content = str_replace('@release_date@', $this->versionDate, $content);
$phar->addFromString($path, $content); $phar->addFromString($path, $content);
} }

View File

@ -29,6 +29,7 @@ use Composer\Autoload\AutoloadGenerator;
class Composer class Composer
{ {
const VERSION = '@package_version@'; const VERSION = '@package_version@';
const RELEASE_DATE = '@release_date@';
/** /**
* @var Package\RootPackageInterface * @var Package\RootPackageInterface

View File

@ -235,6 +235,14 @@ class Application extends BaseApplication
return $commands; return $commands;
} }
/**
* {@inheritDoc}
*/
public function getLongVersion()
{
return parent::getLongVersion() . ' ' . Composer::RELEASE_DATE;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */