1
0
Fork 0

Remove all possible cd calls, refs #1971

pull/1979/merge
Jordi Boggiano 2013-06-08 16:40:42 +02:00
parent 4fe074efdc
commit 8b8dc1fd70
3 changed files with 24 additions and 13 deletions

View File

@ -28,10 +28,14 @@ class HgDownloader extends VcsDownloader
$ref = escapeshellarg($package->getSourceReference()); $ref = escapeshellarg($package->getSourceReference());
$path = escapeshellarg($path); $path = escapeshellarg($path);
$this->io->write(" Cloning ".$package->getSourceReference()); $this->io->write(" Cloning ".$package->getSourceReference());
$command = sprintf('hg clone %s %s && cd %2$s && hg up %s', $url, $path, $ref); $command = sprintf('hg clone %s %s', $url, $path);
if (0 !== $this->process->execute($command, $ignoredOutput)) { if (0 !== $this->process->execute($command, $ignoredOutput)) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); 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());
}
} }
/** /**
@ -43,8 +47,8 @@ class HgDownloader extends VcsDownloader
$ref = escapeshellarg($target->getSourceReference()); $ref = escapeshellarg($target->getSourceReference());
$path = escapeshellarg($path); $path = escapeshellarg($path);
$this->io->write(" Updating to ".$target->getSourceReference()); $this->io->write(" Updating to ".$target->getSourceReference());
$command = sprintf('cd %s && hg pull %s && hg up %s', $path, $url, $ref); $command = sprintf('hg pull %s && hg up %s', $url, $ref);
if (0 !== $this->process->execute($command, $ignoredOutput)) { if (0 !== $this->process->execute($command, $ignoredOutput, $path)) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
} }
} }
@ -58,7 +62,7 @@ class HgDownloader extends VcsDownloader
return; return;
} }
$this->process->execute(sprintf('cd %s && hg st', escapeshellarg($path)), $output); $this->process->execute('hg st', $output, $path);
return trim($output) ?: null; return trim($output) ?: null;
} }
@ -68,9 +72,9 @@ class HgDownloader extends VcsDownloader
*/ */
protected function getCommitLogs($fromReference, $toReference, $path) protected function getCommitLogs($fromReference, $toReference, $path)
{ {
$command = sprintf('cd %s && hg log -r %s:%s --style compact', escapeshellarg($path), $fromReference, $toReference); $command = sprintf('hg log -r %s:%s --style compact', $fromReference, $toReference);
if (0 !== $this->process->execute($command, $output)) { if (0 !== $this->process->execute($command, $output, $path)) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
} }

View File

@ -144,9 +144,9 @@ class SvnDownloader extends VcsDownloader
$fromRevision = preg_replace('{.*@(\d+)$}', '$1', $fromReference); $fromRevision = preg_replace('{.*@(\d+)$}', '$1', $fromReference);
$toRevision = preg_replace('{.*@(\d+)$}', '$1', $toReference); $toRevision = preg_replace('{.*@(\d+)$}', '$1', $toReference);
$command = sprintf('cd %s && svn log -r%s:%s --incremental', escapeshellarg($path), $fromRevision, $toRevision); $command = sprintf('svn log -r%s:%s --incremental', $fromRevision, $toRevision);
if (0 !== $this->process->execute($command, $output)) { if (0 !== $this->process->execute($command, $output, $path)) {
throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput());
} }

View File

@ -42,7 +42,6 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
public function testDownload() public function testDownload()
{ {
$expectedGitCommand = $this->getCmd('hg clone \'https://mercurial.dev/l3l0/composer\' \'composerPath\' && cd \'composerPath\' && hg up \'ref\'');
$packageMock = $this->getMock('Composer\Package\PackageInterface'); $packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any()) $packageMock->expects($this->any())
->method('getSourceReference') ->method('getSourceReference')
@ -51,7 +50,15 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceUrl') ->method('getSourceUrl')
->will($this->returnValue('https://mercurial.dev/l3l0/composer')); ->will($this->returnValue('https://mercurial.dev/l3l0/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$processExecutor->expects($this->once())
$expectedGitCommand = $this->getCmd('hg clone \'https://mercurial.dev/l3l0/composer\' \'composerPath\'');
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0));
$expectedGitCommand = $this->getCmd('hg up \'ref\'');
$processExecutor->expects($this->at(1))
->method('execute') ->method('execute')
->with($this->equalTo($expectedGitCommand)) ->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0)); ->will($this->returnValue(0));
@ -77,8 +84,6 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
public function testUpdate() public function testUpdate()
{ {
$expectedUpdateCommand = $this->getCmd("cd 'composerPath' && hg pull 'https://github.com/l3l0/composer' && hg up 'ref'");
$packageMock = $this->getMock('Composer\Package\PackageInterface'); $packageMock = $this->getMock('Composer\Package\PackageInterface');
$packageMock->expects($this->any()) $packageMock->expects($this->any())
->method('getSourceReference') ->method('getSourceReference')
@ -87,9 +92,11 @@ class HgDownloaderTest extends \PHPUnit_Framework_TestCase
->method('getSourceUrl') ->method('getSourceUrl')
->will($this->returnValue('https://github.com/l3l0/composer')); ->will($this->returnValue('https://github.com/l3l0/composer'));
$processExecutor = $this->getMock('Composer\Util\ProcessExecutor'); $processExecutor = $this->getMock('Composer\Util\ProcessExecutor');
$expectedGitCommand = $this->getCmd("hg pull 'https://github.com/l3l0/composer' && hg up 'ref'");
$processExecutor->expects($this->at(0)) $processExecutor->expects($this->at(0))
->method('execute') ->method('execute')
->with($this->equalTo($expectedUpdateCommand)) ->with($this->equalTo($expectedGitCommand))
->will($this->returnValue(0)); ->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, null, $processExecutor); $downloader = $this->getDownloaderMock(null, null, $processExecutor);