2011-04-17 22:14:44 +00:00
|
|
|
<?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;
|
2012-01-18 07:56:35 +00:00
|
|
|
use Composer\Util\ProcessExecutor;
|
2011-04-17 22:14:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*/
|
2011-09-15 19:58:00 +00:00
|
|
|
class GitDownloader implements DownloaderInterface
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2012-01-18 07:56:35 +00:00
|
|
|
protected $process;
|
|
|
|
|
|
|
|
public function __construct(ProcessExecutor $process = null)
|
|
|
|
{
|
|
|
|
$this->process = $process ?: new ProcessExecutor;
|
|
|
|
}
|
|
|
|
|
2011-09-25 10:39:08 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2011-09-29 01:11:51 +00:00
|
|
|
public function getInstallationSource()
|
2011-09-25 10:39:08 +00:00
|
|
|
{
|
2011-09-29 01:11:51 +00:00
|
|
|
return 'source';
|
2011-09-28 22:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2011-09-29 01:11:51 +00:00
|
|
|
public function download(PackageInterface $package, $path)
|
2011-09-28 22:48:17 +00:00
|
|
|
{
|
|
|
|
if (!$package->getSourceReference()) {
|
|
|
|
throw new \InvalidArgumentException('The given package is missing reference information');
|
|
|
|
}
|
|
|
|
|
|
|
|
$url = escapeshellarg($package->getSourceUrl());
|
|
|
|
$ref = escapeshellarg($package->getSourceReference());
|
2012-01-18 07:56:35 +00:00
|
|
|
$this->process->execute(sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref));
|
2011-09-28 22:48:17 +00:00
|
|
|
}
|
2011-09-25 10:39:08 +00:00
|
|
|
|
2011-09-28 22:48:17 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2011-09-29 01:11:51 +00:00
|
|
|
public function update(PackageInterface $initial, PackageInterface $target, $path)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2011-09-28 22:48:17 +00:00
|
|
|
if (!$target->getSourceReference()) {
|
|
|
|
throw new \InvalidArgumentException('The given package is missing reference information');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->enforceCleanDirectory($path);
|
2012-01-18 07:56:35 +00:00
|
|
|
$this->process->execute(sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $target->getSourceReference()));
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 10:39:08 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2011-09-28 22:48:17 +00:00
|
|
|
public function remove(PackageInterface $package, $path)
|
|
|
|
{
|
|
|
|
$this->enforceCleanDirectory($path);
|
|
|
|
$fs = new Util\Filesystem();
|
2011-12-03 14:39:06 +00:00
|
|
|
$fs->removeDirectory($path);
|
2011-09-28 22:48:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private function enforceCleanDirectory($path)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2012-01-22 19:08:20 +00:00
|
|
|
$this->process->execute(sprintf('cd %s && git status --porcelain', $path), $output);
|
|
|
|
if (trim($output)) {
|
2011-09-28 22:48:17 +00:00
|
|
|
throw new \RuntimeException('Source directory has uncommitted changes');
|
|
|
|
}
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
2011-09-17 13:12:45 +00:00
|
|
|
}
|