From cfc632b019bf9f567bdef6ccc433644140457ffd Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Fri, 11 Jul 2014 12:31:51 +0100 Subject: [PATCH] Determine auth URLs more intelligently --- src/Composer/Util/Git.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Composer/Util/Git.php b/src/Composer/Util/Git.php index 296aa548f..053261b7b 100644 --- a/src/Composer/Util/Git.php +++ b/src/Composer/Util/Git.php @@ -106,13 +106,26 @@ class Git preg_match('{(https?://)([^/]+)(.*)$}i', $url, $match) && strpos($this->process->getErrorOutput(), 'fatal: Authentication failed') !== false ) { + if (strpos($match[2], '@')) { + list($authParts, $match[2]) = explode('@', $match[2], 2); + } + // TODO this should use an auth manager class that prompts and stores in the config if ($this->io->hasAuthentication($match[2])) { $auth = $this->io->getAuthentication($match[2]); } else { + $defaultUsername = null; + if (isset($authParts) && $authParts) { + if (strpos($authParts, ':')) { + list($defaultUsername,) = explode(':', $authParts); + } else { + $defaultUsername = $authParts; + } + } + $this->io->write($url.' requires Authentication'); $auth = array( - 'username' => $this->io->ask('Username: '), + 'username' => $this->io->ask('Username: ', $defaultUsername), 'password' => $this->io->askAndHideAnswer('Password: '), ); }