HgDownloader.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Downloader;
  12. use Composer\Package\PackageInterface;
  13. /**
  14. * @author Per Bernhardt <plb@webfactory.de>
  15. */
  16. class HgDownloader extends VcsDownloader
  17. {
  18. /**
  19. * {@inheritDoc}
  20. */
  21. public function doDownload(PackageInterface $package, $path)
  22. {
  23. $url = escapeshellarg($package->getSourceUrl());
  24. $ref = escapeshellarg($package->getSourceReference());
  25. $path = escapeshellarg($path);
  26. $this->io->write(" Cloning ".$package->getSourceReference());
  27. $command = sprintf('hg clone %s %s && cd %2$s && hg up %s', $url, $path, $ref);
  28. if (0 !== $this->process->execute($command, $ignoredOutput)) {
  29. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  30. }
  31. }
  32. /**
  33. * {@inheritDoc}
  34. */
  35. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
  36. {
  37. $url = escapeshellarg($target->getSourceUrl());
  38. $ref = escapeshellarg($target->getSourceReference());
  39. $path = escapeshellarg($path);
  40. $this->io->write(" Updating to ".$target->getSourceReference());
  41. $command = sprintf('cd %s && hg pull %s && hg up %s', $path, $url, $ref);
  42. if (0 !== $this->process->execute($command, $ignoredOutput)) {
  43. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  44. }
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function getLocalChanges($path)
  50. {
  51. $this->process->execute(sprintf('cd %s && hg st', escapeshellarg($path)), $output);
  52. return trim($output) ?: null;
  53. }
  54. /**
  55. * {@inheritDoc}
  56. */
  57. protected function getCommitLogs($fromReference, $toReference, $path)
  58. {
  59. $command = sprintf('cd %s && hg log -r %s:%s --style compact', escapeshellarg($path), $fromReference, $toReference);
  60. if (0 !== $this->process->execute($command, $output)) {
  61. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  62. }
  63. return $output;
  64. }
  65. }