diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index e259373bd..392b35d28 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -85,7 +85,7 @@ EOT // creating requirements request $request = new Request($pool); if ($update) { - $output->writeln('Updating dependencies.'); + $output->writeln('Updating dependencies'); $installedPackages = $installedRepo->getPackages(); $links = $this->collectLinks($input, $composer->getPackage()); @@ -100,7 +100,11 @@ EOT $request->install($link->getTarget(), $link->getConstraint()); } } elseif ($composer->getLocker()->isLocked()) { - $output->writeln('Installing from lockfile. (Run "composer update" to add or update packages)'); + $output->writeln('Installing from lock file'); + + if (!$composer->getLocker()->isFresh()) { + $output->writeln('Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies'); + } foreach ($composer->getLocker()->getLockedPackages() as $package) { $constraint = new VersionConstraint('=', $package->getVersion()); @@ -150,6 +154,9 @@ EOT } // execute operations + if (!$operations) { + $output->writeln('Nothing to install/update'); + } foreach ($operations as $operation) { if ($verbose) { $output->writeln((string) $operation); @@ -162,7 +169,7 @@ EOT if (!$dryRun) { if ($update || !$composer->getLocker()->isLocked()) { $composer->getLocker()->lockPackages($localRepo->getPackages()); - $output->writeln('Locked'); + $output->writeln('Writing lock file'); } $localRepo->write(); @@ -171,8 +178,6 @@ EOT $generator = new AutoloadGenerator; $generator->dump($localRepo, $composer->getPackage(), $installationManager, $installationManager->getVendorPath().'/.composer'); } - - $output->writeln('Done'); } private function collectLinks(InputInterface $input, PackageInterface $package) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 35af5dd79..3ba2b9b0d 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -49,6 +49,7 @@ class Application extends BaseApplication { if (null === $output) { $styles['highlight'] = new OutputFormatterStyle('red'); + $styles['warning'] = new OutputFormatterStyle('black', 'yellow'); $formatter = new OutputFormatter(null, $styles); $output = new ConsoleOutput(ConsoleOutput::VERBOSITY_NORMAL, null, $formatter); } @@ -152,7 +153,7 @@ class Application extends BaseApplication // init locker $lockFile = substr($composerFile, -5) === '.json' ? substr($composerFile, 0, -4).'lock' : $composerFile . '.lock'; - $locker = new Package\Locker(new JsonFile($lockFile), $rm); + $locker = new Package\Locker(new JsonFile($lockFile), $rm, md5_file($composerFile)); // initialize composer $composer = new Composer(); diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index cf067487c..0c375b8b5 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -24,17 +24,20 @@ class Locker { private $lockFile; private $repositoryManager; + private $hash; /** * Initializes packages locker. * * @param JsonFile $lockFile lockfile loader * @param RepositoryManager $repositoryManager repository manager instance + * @param string $hash unique hash of the current composer configuration */ - public function __construct(JsonFile $lockFile, RepositoryManager $repositoryManager) + public function __construct(JsonFile $lockFile, RepositoryManager $repositoryManager, $hash) { $this->lockFile = $lockFile; $this->repositoryManager = $repositoryManager; + $this->hash = $hash; } /** @@ -47,6 +50,13 @@ class Locker return $this->lockFile->exists(); } + public function isFresh() + { + $lock = $this->lockFile->read(); + + return $this->hash === $lock['hash']; + } + /** * Searches and returns an array of locked packages, retrieved from registered repositories. * @@ -60,7 +70,7 @@ class Locker $lockList = $this->lockFile->read(); $packages = array(); - foreach ($lockList as $info) { + foreach ($lockList['packages'] as $info) { $package = $this->repositoryManager->getLocalRepository()->findPackage($info['package'], $info['version']); if (!$package) { @@ -87,7 +97,9 @@ class Locker */ public function lockPackages(array $packages) { - $hash = array(); + $lock = array( + 'hash' => $this->hash, + ); foreach ($packages as $package) { $name = $package->getPrettyName(); $version = $package->getPrettyVersion(); @@ -98,9 +110,9 @@ class Locker )); } - $hash[] = array('package' => $name, 'version' => $version); + $lock['packages'][] = array('package' => $name, 'version' => $version); } - $this->lockFile->write($hash); + $this->lockFile->write($lock); } } diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index 1993e8cd5..884a1e69e 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -19,7 +19,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase public function testIsLocked() { $json = $this->createJsonFileMock(); - $locker = new Locker($json, $this->createRepositoryManagerMock()); + $locker = new Locker($json, $this->createRepositoryManagerMock(), 'md5'); $json ->expects($this->once()) @@ -34,7 +34,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $json = $this->createJsonFileMock(); $repo = $this->createRepositoryManagerMock(); - $locker = new Locker($json, $repo); + $locker = new Locker($json, $repo, 'md5'); $json ->expects($this->once()) @@ -51,7 +51,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $json = $this->createJsonFileMock(); $repo = $this->createRepositoryManagerMock(); - $locker = new Locker($json, $repo); + $locker = new Locker($json, $repo, 'md5'); $json ->expects($this->once()) @@ -61,8 +61,10 @@ class LockerTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('read') ->will($this->returnValue(array( - array('package' => 'pkg1', 'version' => '1.0.0-beta'), - array('package' => 'pkg2', 'version' => '0.1.10') + 'packages' => array( + array('package' => 'pkg1', 'version' => '1.0.0-beta'), + array('package' => 'pkg2', 'version' => '0.1.10') + ) ))); $package1 = $this->createPackageMock(); @@ -82,7 +84,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $json = $this->createJsonFileMock(); $repo = $this->createRepositoryManagerMock(); - $locker = new Locker($json, $repo); + $locker = new Locker($json, $repo, 'md5'); $json ->expects($this->once()) @@ -92,8 +94,10 @@ class LockerTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('read') ->will($this->returnValue(array( - array('package' => 'pkg1', 'version' => '1.0.0-beta'), - array('package' => 'pkg2', 'version' => '0.1.10') + 'packages' => array( + array('package' => 'pkg1', 'version' => '1.0.0-beta'), + array('package' => 'pkg2', 'version' => '0.1.10') + ) ))); $package1 = $this->createPackageMock(); @@ -115,7 +119,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $json = $this->createJsonFileMock(); $repo = $this->createRepositoryManagerMock(); - $locker = new Locker($json, $repo); + $locker = new Locker($json, $repo, 'md5'); $package1 = $this->createPackageMock(); $package2 = $this->createPackageMock(); @@ -142,8 +146,11 @@ class LockerTest extends \PHPUnit_Framework_TestCase ->expects($this->once()) ->method('write') ->with(array( - array('package' => 'pkg1', 'version' => '1.0.0-beta'), - array('package' => 'pkg2', 'version' => '0.1.10') + 'hash' => 'md5', + 'packages' => array( + array('package' => 'pkg1', 'version' => '1.0.0-beta'), + array('package' => 'pkg2', 'version' => '0.1.10') + ), )); $locker->lockPackages(array($package1, $package2)); @@ -154,7 +161,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $json = $this->createJsonFileMock(); $repo = $this->createRepositoryManagerMock(); - $locker = new Locker($json, $repo); + $locker = new Locker($json, $repo, 'md5'); $package1 = $this->createPackageMock(); $package1