From 4d522e40fbd770aff93aec75145cf77a5ef27293 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 22 Sep 2014 16:05:43 +0100 Subject: [PATCH] Load auth when updating a git repo mirror, fixes #3243 --- src/Composer/Repository/Vcs/GitDriver.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index f37be1e9a..20cfa93fc 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -56,16 +56,22 @@ class GitDriver extends VcsDriver throw new \InvalidArgumentException('The source URL '.$this->url.' is invalid, ssh URLs should have a port number after ":".'."\n".'Use ssh://git@example.com:22/path or just git@example.com:path if you do not want to provide a password or custom port.'); } + $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs); + // update the repo if it is a valid git repository if (is_dir($this->repoDir) && 0 === $this->process->execute('git rev-parse --git-dir', $output, $this->repoDir) && trim($output) === '.') { - if (0 !== $this->process->execute('git remote update --prune origin', $output, $this->repoDir)) { - $this->io->write('Failed to update '.$this->url.', package information from this repository may be outdated ('.$this->process->getErrorOutput().')'); + try { + $commandCallable = function ($url) { + return sprintf('git remote set-url origin %s && git remote update --prune origin', escapeshellarg($url)); + }; + $gitUtil->runCommand($commandCallable, $this->url, $this->repoDir); + } catch (\Exception $e) { + $this->io->write('Failed to update '.$this->url.', package information from this repository may be outdated ('.$e->getMessage().')'); } } else { // clean up directory and do a fresh clone into it $fs->removeDirectory($this->repoDir); - $gitUtil = new GitUtil($this->io, $this->config, $this->process, $fs); $repoDir = $this->repoDir; $commandCallable = function ($url) use ($repoDir) { return sprintf('git clone --mirror %s %s', escapeshellarg($url), escapeshellarg($repoDir));