Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix git checkouts of custom branches, fixes #889

  • Loading branch information...
commit cbf27bb422b63de3c25a43aeb33768822a45f613 1 parent 5325aef
@Seldaek Seldaek authored
View
6 src/Composer/Downloader/GitDownloader.php
@@ -67,7 +67,8 @@ protected function updateToCommit($path, $reference, $branch, $date)
{
$template = 'git checkout %s && git reset --hard %1$s';
- $command = sprintf($template, escapeshellarg($reference));
+ $gitRef = preg_match('{^[a-f0-9]{40}$}', $reference) ? $reference : 'composer/'.$reference;
+ $command = sprintf($template, escapeshellarg($gitRef));
if (0 === $this->process->execute($command, $output, $path)) {
return;
}
@@ -104,7 +105,8 @@ protected function updateToCommit($path, $reference, $branch, $date)
}
// checkout the new recovered ref
- $command = sprintf($template, escapeshellarg($newReference));
+ $gitRef = preg_match('{^[a-f0-9]{40}$}', $reference) ? $reference : 'composer/'.$reference;
+ $command = sprintf($template, escapeshellarg($gitRef));
if (0 === $this->process->execute($command, $output, $path)) {
$this->io->write(' '.$reference.' is gone (history was rewritten?), recovered by checking out '.$newReference);
View
6 tests/Composer/Test/Downloader/GitDownloaderTest.php
@@ -58,7 +58,7 @@ public function testDownload()
$processExecutor->expects($this->at(1))
->method('execute')
- ->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
+ ->with($this->equalTo($this->getCmd("git checkout 'composer/ref' && git reset --hard 'composer/ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, $processExecutor);
@@ -102,7 +102,7 @@ public function testDownloadUsesVariousProtocolsAndSetsPushUrlForGithub()
$processExecutor->expects($this->at(6))
->method('execute')
- ->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
+ ->with($this->equalTo($this->getCmd("git checkout 'composer/ref' && git reset --hard 'composer/ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, $processExecutor);
@@ -174,7 +174,7 @@ public function testUpdate()
->will($this->returnValue(0));
$processExecutor->expects($this->at(3))
->method('execute')
- ->with($this->equalTo($this->getCmd("git checkout 'ref' && git reset --hard 'ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
+ ->with($this->equalTo($this->getCmd("git checkout 'composer/ref' && git reset --hard 'composer/ref'")), $this->equalTo(null), $this->equalTo('composerPath'))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, $processExecutor);
Please sign in to comment.
Something went wrong with that request. Please try again.