Merge remote-tracking branch 'bozerkins/force-to-reinstall-package-when-missing-vcs-metadata'

main
Jordi Boggiano 9 years ago
commit e4ede0c582

@ -250,11 +250,18 @@ class DownloadManager
if ($initialType === $targetType) { if ($initialType === $targetType) {
$target->setInstallationSource($installationSource); $target->setInstallationSource($installationSource);
$downloader->update($initial, $target, $targetDir); try {
} else { $downloader->update($initial, $target, $targetDir);
$downloader->remove($initial, $targetDir); return;
$this->download($target, $targetDir, 'source' === $installationSource); } catch (\RuntimeException $ex) {
if (!$this->io->isInteractive() ||
!$this->io->askConfirmation(' Updating failed. Would you like to try reinstalling instead [<comment>yes</comment>]? ', true)) {
throw $ex;
}
}
} }
$downloader->remove($initial, $targetDir);
$this->download($target, $targetDir, 'source' === $installationSource);
} }
/** /**

@ -73,8 +73,7 @@ class GitDownloader extends VcsDownloader
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); if (!$this->hasMetadataRepository($path)) {
if (!is_dir($path.'/.git')) {
throw new \RuntimeException('The .git directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information'); throw new \RuntimeException('The .git directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
} }
@ -101,8 +100,7 @@ class GitDownloader extends VcsDownloader
public function getLocalChanges(PackageInterface $package, $path) public function getLocalChanges(PackageInterface $package, $path)
{ {
GitUtil::cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); if (!$this->hasMetadataRepository($path)) {
if (!is_dir($path.'/.git')) {
return; return;
} }
@ -372,4 +370,17 @@ class GitDownloader extends VcsDownloader
return $path; return $path;
} }
/**
* Checks if VCS metadata repository has been initialized
* repository example: .git|.svn|.hg
*
* @param string $path
* @return bool
*/
protected function hasMetadataRepository($path)
{
$path = $this->normalizePath($path);
return is_dir($path.'/.git');
}
} }

@ -47,7 +47,7 @@ class HgDownloader extends VcsDownloader
$ref = ProcessExecutor::escape($target->getSourceReference()); $ref = ProcessExecutor::escape($target->getSourceReference());
$this->io->writeError(" Updating to ".$target->getSourceReference()); $this->io->writeError(" Updating to ".$target->getSourceReference());
if (!is_dir($path.'/.hg')) { if (!$this->hasMetadataRepository($path)) {
throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information'); throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
} }
@ -84,4 +84,16 @@ class HgDownloader extends VcsDownloader
return $output; return $output;
} }
/**
* Checks if VCS metadata repository has been initialized
* repository example: .git|.svn|.hg
*
* @param string $path
* @return bool
*/
protected function hasMetadataRepository($path)
{
return is_dir($path . '/.hg');
}
} }

@ -104,4 +104,16 @@ class PerforceDownloader extends VcsDownloader
{ {
$this->perforce = $perforce; $this->perforce = $perforce;
} }
/**
* Checks if VCS metadata repository has been initialized
* repository example: .git|.svn|.hg
*
* @param string $path
* @return bool
*/
protected function hasMetadataRepository($path)
{
return true;
}
} }

@ -52,7 +52,7 @@ class SvnDownloader extends VcsDownloader
SvnUtil::cleanEnv(); SvnUtil::cleanEnv();
$ref = $target->getSourceReference(); $ref = $target->getSourceReference();
if (!is_dir($path.'/.svn')) { if (!$this->hasMetadataRepository($path)) {
throw new \RuntimeException('The .svn directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information'); throw new \RuntimeException('The .svn directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
} }
@ -72,7 +72,7 @@ class SvnDownloader extends VcsDownloader
*/ */
public function getLocalChanges(PackageInterface $package, $path) public function getLocalChanges(PackageInterface $package, $path)
{ {
if (!is_dir($path.'/.svn')) { if (!$this->hasMetadataRepository($path)) {
return; return;
} }
@ -188,4 +188,16 @@ class SvnDownloader extends VcsDownloader
throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput()); throw new \RuntimeException("Could not reset changes\n\n:".$this->process->getErrorOutput());
} }
} }
/**
* Checks if VCS metadata repository has been initialized
* repository example: .git|.svn|.hg
*
* @param string $path
* @return bool
*/
protected function hasMetadataRepository($path)
{
return is_dir($path.'/.svn');
}
} }

@ -111,6 +111,8 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
$this->cleanChanges($initial, $path, true); $this->cleanChanges($initial, $path, true);
$urls = $target->getSourceUrls(); $urls = $target->getSourceUrls();
$exception = null;
while ($url = array_shift($urls)) { while ($url = array_shift($urls)) {
try { try {
if (Filesystem::isLocalPath($url)) { if (Filesystem::isLocalPath($url)) {
@ -118,24 +120,20 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
} }
$this->doUpdate($initial, $target, $path, $url); $this->doUpdate($initial, $target, $path, $url);
break; break;
} catch (\Exception $e) { } catch (\Exception $exception) {
if ($this->io->isDebug()) { if ($this->io->isDebug()) {
$this->io->writeError('Failed: ['.get_class($e).'] '.$e->getMessage()); $this->io->writeError('Failed: ['.get_class($exception).'] '.$exception->getMessage());
} elseif (count($urls)) { } elseif (count($urls)) {
$this->io->writeError(' Failed, trying the next URL'); $this->io->writeError(' Failed, trying the next URL');
} else {
// in case of failed update, try to reapply the changes before aborting
$this->reapplyChanges($path);
throw $e;
} }
} }
} }
$this->reapplyChanges($path); $this->reapplyChanges($path);
// print the commit logs if in verbose mode // print the commit logs if in verbose mode and VCS metadata is present
if ($this->io->isVerbose()) { // because in case of missing metadata code would trigger another exception
if ($this->io->isVerbose() && $this->hasMetadataRepository($path)) {
$message = 'Pulling in changes:'; $message = 'Pulling in changes:';
$logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path); $logs = $this->getCommitLogs($initial->getSourceReference(), $target->getSourceReference(), $path);
@ -157,6 +155,10 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
} }
} }
if (!$urls && $exception) {
throw $exception;
}
$this->io->writeError(''); $this->io->writeError('');
} }
@ -236,4 +238,13 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @return string * @return string
*/ */
abstract protected function getCommitLogs($fromReference, $toReference, $path); abstract protected function getCommitLogs($fromReference, $toReference, $path);
/**
* Checks if VCS metadata repository has been initialized
* repository example: .git|.svn|.hg
*
* @param string $path
* @return bool
*/
abstract protected function hasMetadataRepository($path);
} }

Loading…
Cancel
Save