From 5ed5f1314b39335c2d43d1ad55fe204a5f191ba8 Mon Sep 17 00:00:00 2001 From: Mark Achee Date: Mon, 1 Oct 2012 12:56:41 -0500 Subject: [PATCH] Capture user/pass from 'git remote' when updating non github repo --- src/Composer/Downloader/GitDownloader.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index dc6e4b173..5cd89bdf5 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -49,12 +49,14 @@ class GitDownloader extends VcsDownloader $this->io->write(" Checking out ".$ref); $command = 'cd %s && git remote set-url composer %s && git fetch composer && git fetch --tags composer'; - // capture username/password from github URL if there is one + // capture username/password from URL if there is one $this->process->execute(sprintf('cd %s && git remote -v', escapeshellarg($path)), $output); - if (preg_match('{^composer\s+https://(.+):(.+)@github.com/}im', $output, $match)) { - $this->io->setAuthorization('github.com', $match[1], $match[2]); + if (preg_match('{^(?:composer|origin)\s+https?://(.+):(.+)@([^/]+)/}im', $output, $match)) { + $this->io->setAuthorization($match[3], urldecode($match[1]), urldecode($match[2])); } + // 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($path), escapeshellarg($url), escapeshellarg($ref)); }; @@ -201,7 +203,7 @@ class GitDownloader extends VcsDownloader } while (--$retries); } elseif ( $this->io->isInteractive() && - preg_match('{(https?://)([^/]+/)(.*)$}i', $url, $match) && + preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match) && strpos($this->process->getErrorOutput(), 'fatal: Authentication failed') !== false ) { if ($saved = $this->io->hasAuthorization($match[2])) {