HgDownloader.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $this->io->write(" Cloning ".$package->getSourceReference());
  26. $command = sprintf('hg clone %s %s', $url, escapeshellarg($path));
  27. if (0 !== $this->process->execute($command, $ignoredOutput)) {
  28. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  29. }
  30. $command = sprintf('hg up %s', $ref);
  31. if (0 !== $this->process->execute($command, $ignoredOutput, $path)) {
  32. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  33. }
  34. }
  35. /**
  36. * {@inheritDoc}
  37. */
  38. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
  39. {
  40. $url = escapeshellarg($target->getSourceUrl());
  41. $ref = escapeshellarg($target->getSourceReference());
  42. $this->io->write(" Updating to ".$target->getSourceReference());
  43. if (!is_dir($path.'/.hg')) {
  44. throw new \RuntimeException('The .hg directory is missing from '.$path.', see http://getcomposer.org/commit-deps for more information');
  45. }
  46. $command = sprintf('hg pull %s && hg up %s', $url, $ref);
  47. if (0 !== $this->process->execute($command, $ignoredOutput, $path)) {
  48. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  49. }
  50. }
  51. /**
  52. * {@inheritDoc}
  53. */
  54. public function getLocalChanges(PackageInterface $package, $path)
  55. {
  56. if (!is_dir($path.'/.hg')) {
  57. return;
  58. }
  59. $this->process->execute('hg st', $output, $path);
  60. return trim($output) ?: null;
  61. }
  62. /**
  63. * {@inheritDoc}
  64. */
  65. protected function getCommitLogs($fromReference, $toReference, $path)
  66. {
  67. $command = sprintf('hg log -r %s:%s --style compact', $fromReference, $toReference);
  68. if (0 !== $this->process->execute($command, $output, $path)) {
  69. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  70. }
  71. return $output;
  72. }
  73. }