Removed code duplication with abstract hasMetadataRepository method

which checks if vcs metadata is present in the package

Fixed a bug with -vvv mode. When .git folder is missing from package
in normal mode, -v mode, -vv mode the program throws the exception about missing .git folder
in -vvv mode an exception about inability to read logs
main
bogdan 9 years ago
parent 7117a5775f
commit a77e2fb093

@ -72,9 +72,8 @@ class GitDownloader extends VcsDownloader
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($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');
if (!$this->hasMetadataRepository($path)) {
throw new VcsMissingMetadataException('The .git directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
}
$ref = $target->getSourceReference();
@ -100,8 +99,7 @@ class GitDownloader extends VcsDownloader
public function getLocalChanges(PackageInterface $package, $path)
{
GitUtil::cleanEnv();
$path = $this->normalizePath($path);
if (!is_dir($path.'/.git')) {
if (!$this->hasMetadataRepository($path)) {
return;
}
@ -371,4 +369,17 @@ class GitDownloader extends VcsDownloader
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,8 +47,8 @@ class HgDownloader extends VcsDownloader
$ref = ProcessExecutor::escape($target->getSourceReference());
$this->io->writeError(" Updating to ".$target->getSourceReference());
if (!is_dir($path.'/.hg')) {
throw new \RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
if (!$this->hasMetadataRepository($path)) {
throw new VcsMissingMetadataException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
}
$command = sprintf('hg pull %s && hg up %s', $url, $ref);
@ -84,4 +84,16 @@ class HgDownloader extends VcsDownloader
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;
}
/**
* 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,8 +52,8 @@ class SvnDownloader extends VcsDownloader
SvnUtil::cleanEnv();
$ref = $target->getSourceReference();
if (!is_dir($path.'/.svn')) {
throw new \RuntimeException('The .svn directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
if (!$this->hasMetadataRepository($path)) {
throw new VcsMissingMetadataException('The .svn directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');
}
$flags = "";
@ -72,7 +72,7 @@ class SvnDownloader extends VcsDownloader
*/
public function getLocalChanges(PackageInterface $package, $path)
{
if (!is_dir($path.'/.svn')) {
if (!$this->hasMetadataRepository($path)) {
return;
}
@ -188,4 +188,16 @@ class SvnDownloader extends VcsDownloader
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);
$urls = $target->getSourceUrls();
$exception = null;
while ($url = array_shift($urls)) {
try {
if (Filesystem::isLocalPath($url)) {
@ -118,22 +120,24 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
}
$this->doUpdate($initial, $target, $path, $url);
break;
} catch (\Exception $e) {
} catch (\Exception $exception) {
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)) {
$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);
if (!$this->hasMetadataRepository($path) && !$urls && $exception) {
if (!$this->io->isDebug()) {
$this->io->write(' The VCS directory is missing from vendor package, see https://getcomposer.org/commit-deps for more information');
}
throw $exception;
}
// print the commit logs if in verbose mode
if ($this->io->isVerbose()) {
$message = 'Pulling in changes:';
@ -236,4 +240,13 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
* @return string
*/
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);
}

@ -0,0 +1,30 @@
<?php
/**
* Created by PhpStorm.
* User: bogdans
* Date: 2/4/16
* Time: 1:16 AM
*/
namespace Composer\Downloader;
/**
* Exception thrown when missing .git|.svn|.hg folders, which contain VSC metadata
*
* @author Bogdans Ozerkins <b.ozerkins@gmail.com>
*/
class VcsMissingMetadataException extends \RuntimeException
{
/**
* Construct the exception. Note: The message is NOT binary safe.
* @link http://php.net/manual/en/exception.construct.php
* @param string $message [optional] The Exception message to throw.
* @param int $code [optional] The Exception code.
* @param \Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
* @since 5.1.0
*/
public function __construct($message = '', $code = 0, \Exception $previous = null)
{
parent::__construct("Missing VSC metadata exception: \n".$message, $code, $previous);
}
}
Loading…
Cancel
Save