1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?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;
- /**
- * @author Per Bernhardt <plb@webfactory.de>
- */
- class HgDownloader extends VcsDownloader
- {
- /**
- * {@inheritDoc}
- */
- public function doDownload(PackageInterface $package, $path)
- {
- $url = escapeshellarg($package->getSourceUrl());
- $ref = escapeshellarg($package->getSourceReference());
- $this->io->write(" Cloning ".$package->getSourceReference());
- $command = sprintf('hg clone %s %s', $url, escapeshellarg($path));
- if (0 !== $this->process->execute($command, $ignoredOutput)) {
- throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
- }
- $command = sprintf('hg up %s', $ref);
- if (0 !== $this->process->execute($command, $ignoredOutput, $path)) {
- throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
- }
- }
- /**
- * {@inheritDoc}
- */
- public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
- {
- $url = escapeshellarg($target->getSourceUrl());
- $ref = escapeshellarg($target->getSourceReference());
- $this->io->write(" Updating to ".$target->getSourceReference());
- if (!is_dir($path.'/.hg')) {
- throw new \RuntimeException('The .hg directory is missing from '.$path.', see http://getcomposer.org/commit-deps for more information');
- }
- $command = sprintf('hg pull %s && hg up %s', $url, $ref);
- if (0 !== $this->process->execute($command, $ignoredOutput, $path)) {
- throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
- }
- }
- /**
- * {@inheritDoc}
- */
- public function getLocalChanges(PackageInterface $package, $path)
- {
- if (!is_dir($path.'/.hg')) {
- return;
- }
- $this->process->execute('hg st', $output, $path);
- return trim($output) ?: null;
- }
- /**
- * {@inheritDoc}
- */
- protected function getCommitLogs($fromReference, $toReference, $path)
- {
- $command = sprintf('hg log -r %s:%s --style compact', $fromReference, $toReference);
- if (0 !== $this->process->execute($command, $output, $path)) {
- throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
- }
- return $output;
- }
- }
|