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>
|
|
|
|
*/
|
2012-01-22 20:14:56 +00:00
|
|
|
class GitDownloader extends VcsDownloader
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2011-09-25 10:39:08 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-01-22 20:14:56 +00:00
|
|
|
public function doDownload(PackageInterface $package, $path)
|
2011-09-25 10:39:08 +00:00
|
|
|
{
|
2011-09-28 22:48:17 +00:00
|
|
|
$url = escapeshellarg($package->getSourceUrl());
|
|
|
|
$ref = escapeshellarg($package->getSourceReference());
|
2012-01-22 20:14:56 +00:00
|
|
|
$path = escapeshellarg($path);
|
|
|
|
$this->io->write(" Cloning ".$package->getSourceReference());
|
|
|
|
$this->process->execute(sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref), $ignoredOutput);
|
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}
|
|
|
|
*/
|
2012-01-22 20:14:56 +00:00
|
|
|
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2012-01-22 20:14:56 +00:00
|
|
|
$ref = escapeshellarg($target->getSourceReference());
|
|
|
|
$path = escapeshellarg($path);
|
|
|
|
$this->io->write(" Checking out ".$target->getSourceReference());
|
|
|
|
$this->process->execute(sprintf('cd %s && git fetch && git checkout %2$s && git reset --hard %2$s', $path, $ref), $ignoredOutput);
|
2011-04-17 22:14:44 +00:00
|
|
|
}
|
|
|
|
|
2011-09-25 10:39:08 +00:00
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2012-01-22 20:14:56 +00:00
|
|
|
protected function enforceCleanDirectory($path)
|
2011-04-17 22:14:44 +00:00
|
|
|
{
|
2012-01-22 20:14:56 +00:00
|
|
|
$this->process->execute(sprintf('cd %s && git status --porcelain', escapeshellarg($path)), $output);
|
2012-01-22 19:08:20 +00:00
|
|
|
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
|
|
|
}
|