Browse Source

Revert previous change, use GIT_ASKPASS env var instead

Jordi Boggiano 12 years ago
parent
commit
656feda837

+ 3 - 1
src/Composer/Downloader/GitDownloader.php

@@ -25,9 +25,11 @@ class GitDownloader extends VcsDownloader
     public function doDownload(PackageInterface $package, $path)
     {
         $ref = $package->getSourceReference();
-        $command = 'git clone -c core.askpass=echo %s %s && cd %2$s && git remote add composer %1$s && git fetch composer';
+        $command = 'git clone %s %s && cd %2$s && git remote add composer %1$s && git fetch composer';
         $this->io->write("    Cloning ".$ref);
 
+        // added in git 1.7.1, prevents prompting the user
+        putenv('GIT_ASKPASS=echo');
         $commandCallable = function($url) use ($ref, $path, $command) {
             return sprintf($command, escapeshellarg($url), escapeshellarg($path), escapeshellarg($ref));
         };

+ 3 - 1
src/Composer/Repository/Vcs/GitDriver.php

@@ -48,7 +48,9 @@ class GitDriver extends VcsDriver
                 $fs = new Filesystem();
                 $fs->removeDirectory($this->repoDir);
 
-                $command = sprintf('git clone -c core.askpass=echo --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
+                // added in git 1.7.1, prevents prompting the user
+                putenv('GIT_ASKPASS=echo');
+                $command = sprintf('git clone --mirror %s %s', escapeshellarg($this->url), escapeshellarg($this->repoDir));
                 if (0 !== $this->process->execute($command, $output)) {
                     $output = $this->process->getErrorOutput();
 

+ 1 - 0
src/Composer/Repository/Vcs/GitHubDriver.php

@@ -276,6 +276,7 @@ class GitHubDriver extends VcsDriver
 
                             return;
                         } catch (\RuntimeException $e) {
+                            $this->gitDriver = null;
                             if (!$this->io->isInteractive()) {
                                 $this->io->write('<error>Failed to clone the '.$this->generateSshUrl().' repository, try running in interactive mode so that you can enter your username and password</error>');
                                 throw $e;

+ 6 - 1
tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php

@@ -48,6 +48,11 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
             ->setConstructorArgs(array($io))
             ->getMock();
 
+        $process = $this->getMock('Composer\Util\ProcessExecutor');
+        $process->expects($this->any())
+            ->method('execute')
+            ->will($this->returnValue(1));
+
         $remoteFilesystem->expects($this->at(0))
             ->method('getContents')
             ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
@@ -72,7 +77,7 @@ class GitHubDriverTest extends \PHPUnit_Framework_TestCase
             ->with($this->equalTo('github.com'), $this->equalTo($repoApiUrl), $this->equalTo(false))
             ->will($this->returnValue('{"master_branch": "test_master"}'));
 
-        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, null, $remoteFilesystem);
+        $gitHubDriver = new GitHubDriver($repoUrl, $io, $this->config, $process, $remoteFilesystem);
         $gitHubDriver->initialize();
         $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));