1
0
Fork 0

Merge remote-tracking branch 'sascha-egerer/feature/changereport_interface'

pull/2138/merge
Jordi Boggiano 2013-07-31 23:07:22 +02:00
commit d96d9b3926
6 changed files with 59 additions and 33 deletions

View File

@ -15,6 +15,7 @@ namespace Composer\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Composer\Downloader\ChangeReportInterface;
use Composer\Downloader\VcsDownloader; use Composer\Downloader\VcsDownloader;
/** /**
@ -55,10 +56,10 @@ EOT
foreach ($installedRepo->getPackages() as $package) { foreach ($installedRepo->getPackages() as $package) {
$downloader = $dm->getDownloaderForInstalledPackage($package); $downloader = $dm->getDownloaderForInstalledPackage($package);
if ($downloader instanceof VcsDownloader) { if ($downloader instanceof ChangeReportInterface) {
$targetDir = $im->getInstallPath($package); $targetDir = $im->getInstallPath($package);
if ($changes = $downloader->getLocalChanges($targetDir)) { if ($changes = $downloader->getLocalChanges($targetDir, $package)) {
$errors[$targetDir] = $changes; $errors[$targetDir] = $changes;
} }
} }

View File

@ -0,0 +1,32 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Downloader;
use Composer\Package\PackageInterface;
/**
* ChangeReport interface.
*
* @author Sascha Egerer <sascha.egerer@dkd.de>
*/
interface ChangeReportInterface
{
/**
* Checks for changes to the local copy
*
* @param string $path package directory
* @param PackageInterface $package package instance
* @return string|null changes or null
*/
public function getLocalChanges($path, PackageInterface $package);
}

View File

@ -78,7 +78,7 @@ class GitDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getLocalChanges($path) public function getLocalChanges($path, PackageInterface $package)
{ {
$this->cleanEnv(); $this->cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
@ -97,11 +97,11 @@ class GitDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
protected function cleanChanges($path, $update) protected function cleanChanges($path, $update, $package)
{ {
$this->cleanEnv(); $this->cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!$changes = $this->getLocalChanges($path)) { if (!$changes = $this->getLocalChanges($path, $package)) {
return; return;
} }
@ -112,13 +112,13 @@ class GitDownloader extends VcsDownloader
} }
if ('stash' === $discardChanges) { if ('stash' === $discardChanges) {
if (!$update) { if (!$update) {
return parent::cleanChanges($path, $update); return parent::cleanChanges($path, $update, $package);
} }
return $this->stashChanges($path); return $this->stashChanges($path);
} }
return parent::cleanChanges($path, $update); return parent::cleanChanges($path, $update, $package);
} }
$changes = array_map(function ($elem) { $changes = array_map(function ($elem) {

View File

@ -59,7 +59,7 @@ class HgDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getLocalChanges($path) public function getLocalChanges($path, PackageInterface $package)
{ {
if (!is_dir($path.'/.hg')) { if (!is_dir($path.'/.hg')) {
return; return;

View File

@ -52,7 +52,7 @@ class SvnDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public function getLocalChanges($path) public function getLocalChanges($path, PackageInterface $package)
{ {
if (!is_dir($path.'/.svn')) { if (!is_dir($path.'/.svn')) {
return; return;
@ -90,9 +90,9 @@ class SvnDownloader extends VcsDownloader
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
protected function cleanChanges($path, $update) protected function cleanChanges($path, $update, $package)
{ {
if (!$changes = $this->getLocalChanges($path)) { if (!$changes = $this->getLocalChanges($path, $package)) {
return; return;
} }
@ -101,7 +101,7 @@ class SvnDownloader extends VcsDownloader
return $this->discardChanges($path); return $this->discardChanges($path);
} }
return parent::cleanChanges($path, $update); return parent::cleanChanges($path, $update, $package);
} }
$changes = array_map(function ($elem) { $changes = array_map(function ($elem) {

View File

@ -22,7 +22,7 @@ use Composer\Util\Filesystem;
/** /**
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
*/ */
abstract class VcsDownloader implements DownloaderInterface abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface
{ {
protected $io; protected $io;
protected $config; protected $config;
@ -86,7 +86,7 @@ abstract class VcsDownloader implements DownloaderInterface
$this->io->write(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)"); $this->io->write(" - Updating <info>" . $name . "</info> (<comment>" . $from . "</comment> => <comment>" . $to . "</comment>)");
$this->cleanChanges($path, true); $this->cleanChanges($path, true, $initial);
try { try {
$this->doUpdate($initial, $target, $path); $this->doUpdate($initial, $target, $path);
} catch (\Exception $e) { } catch (\Exception $e) {
@ -126,7 +126,7 @@ abstract class VcsDownloader implements DownloaderInterface
public function remove(PackageInterface $package, $path) public function remove(PackageInterface $package, $path)
{ {
$this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); $this->io->write(" - Removing <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)");
$this->cleanChanges($path, false); $this->cleanChanges($path, false, $package);
if (!$this->filesystem->removeDirectory($path)) { if (!$this->filesystem->removeDirectory($path)) {
// retry after a bit on windows since it tends to be touchy with mass removals // retry after a bit on windows since it tends to be touchy with mass removals
if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) { if (!defined('PHP_WINDOWS_VERSION_BUILD') || (usleep(250) && !$this->filesystem->removeDirectory($path))) {
@ -144,18 +144,19 @@ abstract class VcsDownloader implements DownloaderInterface
return $this; return $this;
} }
/** /**
* Prompt the user to check if changes should be stashed/removed or the operation aborted * Prompt the user to check if changes should be stashed/removed or the operation aborted
* *
* @param string $path * @param string $path
* @param bool $update if true (update) the changes can be stashed and reapplied after an update, * @param bool $update if true (update) the changes can be stashed and reapplied after an update,
* if false (remove) the changes should be assumed to be lost if the operation is not aborted * if false (remove) the changes should be assumed to be lost if the operation is not aborted
* @throws \RuntimeException in case the operation must be aborted * @param PackageInterface $package
*/ * @throws \RuntimeException in case the operation must be aborted
protected function cleanChanges($path, $update) */
protected function cleanChanges($path, $update, $package)
{ {
// the default implementation just fails if there are any changes, override in child classes to provide stash-ability // the default implementation just fails if there are any changes, override in child classes to provide stash-ability
if (null !== $this->getLocalChanges($path)) { if (null !== $this->getLocalChanges($path, $package)) {
throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.'); throw new \RuntimeException('Source directory ' . $path . ' has uncommitted changes.');
} }
} }
@ -187,14 +188,6 @@ abstract class VcsDownloader implements DownloaderInterface
*/ */
abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path); abstract protected function doUpdate(PackageInterface $initial, PackageInterface $target, $path);
/**
* Checks for changes to the local copy
*
* @param string $path package directory
* @return string|null changes or null
*/
abstract public function getLocalChanges($path);
/** /**
* Fetches the commit logs between two commits * Fetches the commit logs between two commits
* *