use version parser in vcs downloader
parent
8d766c8eb2
commit
89d2f58c05
|
@ -23,7 +23,7 @@ use Composer\Config;
|
|||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface, VcsCapableDownloaderInterface
|
||||
class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface
|
||||
{
|
||||
private $hasStashedChanges = false;
|
||||
private $hasDiscardedChanges = false;
|
||||
|
@ -196,25 +196,6 @@ class GitDownloader extends VcsDownloader implements DvcsDownloaderInterface, Vc
|
|||
return $unpushedChanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVcsReference(PackageInterface $package, $path)
|
||||
{
|
||||
if (!$this->hasMetadataRepository($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GitUtil::cleanEnv();
|
||||
|
||||
$command = 'git log --pretty="%H" -n1 HEAD';
|
||||
if (0 !== $this->process->execute($command, $output, $path)) {
|
||||
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
|
||||
}
|
||||
|
||||
return trim($output) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -77,23 +77,6 @@ class HgDownloader extends VcsDownloader
|
|||
return trim($output) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVcsReference(PackageInterface $package, $path)
|
||||
{
|
||||
if (!$this->hasMetadataRepository($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$command = 'hg parent --template ' . escapeshellarg('{node}');
|
||||
if (0 !== $this->process->execute($command, $output, $path)) {
|
||||
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
|
||||
}
|
||||
|
||||
return trim($output) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
|
|
|
@ -81,24 +81,6 @@ class SvnDownloader extends VcsDownloader
|
|||
return preg_match('{^ *[^X ] +}m', $output) ? $output : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVcsReference(PackageInterface $package, $path)
|
||||
{
|
||||
if (!$this->hasMetadataRepository($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SvnUtil::cleanEnv();
|
||||
|
||||
if (0 !== $this->process->execute('svnversion', $output, $path)) {
|
||||
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
|
||||
}
|
||||
|
||||
return trim($output) ?: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute an SVN command and try to fix up the process with credentials
|
||||
* if necessary.
|
||||
|
|
|
@ -13,7 +13,10 @@
|
|||
namespace Composer\Downloader;
|
||||
|
||||
use Composer\Config;
|
||||
use Composer\Package\Dumper\ArrayDumper;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Version\VersionGuesser;
|
||||
use Composer\Package\Version\VersionParser;
|
||||
use Composer\Util\ProcessExecutor;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Util\Filesystem;
|
||||
|
@ -21,7 +24,7 @@ use Composer\Util\Filesystem;
|
|||
/**
|
||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||
*/
|
||||
abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface
|
||||
abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterface, VcsCapableDownloaderInterface
|
||||
{
|
||||
/** @var IOInterface */
|
||||
protected $io;
|
||||
|
@ -193,6 +196,21 @@ abstract class VcsDownloader implements DownloaderInterface, ChangeReportInterfa
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getVcsReference(PackageInterface $package, $path)
|
||||
{
|
||||
$parser = new VersionParser;
|
||||
$guesser = new VersionGuesser($this->config, $this->process, $parser);
|
||||
$dumper = new ArrayDumper;
|
||||
|
||||
$packageConfig = $dumper->dump($package);
|
||||
if ($packageVersion = $guesser->guessVersion($packageConfig, $path)) {
|
||||
return $packageVersion['commit'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user to check if changes should be stashed/removed or the operation aborted
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue