SvnDownloader.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. use Composer\Util\Svn as SvnUtil;
  14. /**
  15. * @author Ben Bieker <mail@ben-bieker.de>
  16. * @author Till Klampaeckel <till@php.net>
  17. */
  18. class SvnDownloader extends VcsDownloader
  19. {
  20. /**
  21. * {@inheritDoc}
  22. */
  23. public function doDownload(PackageInterface $package, $path)
  24. {
  25. $url = $package->getSourceUrl();
  26. $ref = $package->getSourceReference();
  27. $this->io->write(" Checking out ".$package->getSourceReference());
  28. $this->execute($url, "svn co", sprintf("%s/%s", $url, $ref), null, $path);
  29. }
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function doUpdate(PackageInterface $initial, PackageInterface $target, $path)
  34. {
  35. $url = $target->getSourceUrl();
  36. $ref = $target->getSourceReference();
  37. $this->io->write(" Checking out " . $ref);
  38. $this->execute($url, "svn switch", sprintf("%s/%s", $url, $ref), $path);
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getLocalChanges($path)
  44. {
  45. $this->process->execute('svn status --ignore-externals', $output, $path);
  46. return preg_match('{^ *[^X ] +}m', $output) ? $output : null;
  47. }
  48. /**
  49. * Execute an SVN command and try to fix up the process with credentials
  50. * if necessary.
  51. *
  52. * @param string $baseUrl Base URL of the repository
  53. * @param string $command SVN command to run
  54. * @param string $url SVN url
  55. * @param string $cwd Working directory
  56. * @param string $path Target for a checkout
  57. *
  58. * @return string
  59. */
  60. protected function execute($baseUrl, $command, $url, $cwd = null, $path = null)
  61. {
  62. $util = new SvnUtil($baseUrl, $this->io);
  63. try {
  64. return $util->execute($command, $url, $cwd, $path, $this->io->isVerbose());
  65. } catch (\RuntimeException $e) {
  66. throw new \RuntimeException(
  67. 'Package could not be downloaded, '.$e->getMessage()
  68. );
  69. }
  70. }
  71. /**
  72. * {@inheritDoc}
  73. */
  74. protected function getCommitLogs($fromReference, $toReference, $path)
  75. {
  76. $command = sprintf('cd %s && svn log -r%s:%s --incremental', escapeshellarg($path), $fromReference, $toReference);
  77. if (0 !== $this->process->execute($command, $output)) {
  78. throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
  79. }
  80. return $output;
  81. }
  82. }