From b38db7361189acff3384ddba9d4f2afba610fb78 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 27 May 2013 19:54:46 +0200 Subject: [PATCH] Clean up rogue git env vars in case this is running in a git hook, refs #1832 --- src/Composer/Downloader/GitDownloader.php | 18 ++++++++++++++---- src/Composer/Repository/Vcs/GitDriver.php | 9 +++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/Composer/Downloader/GitDownloader.php b/src/Composer/Downloader/GitDownloader.php index 1686beebb..2eb40bb1b 100644 --- a/src/Composer/Downloader/GitDownloader.php +++ b/src/Composer/Downloader/GitDownloader.php @@ -27,12 +27,12 @@ class GitDownloader extends VcsDownloader */ public function doDownload(PackageInterface $package, $path) { + $this->cleanEnv(); + $ref = $package->getSourceReference(); $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)); }; @@ -48,6 +48,8 @@ class GitDownloader extends VcsDownloader */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { + $this->cleanEnv(); + $ref = $target->getSourceReference(); $this->io->write(" Checking out ".$ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; @@ -58,8 +60,6 @@ class GitDownloader extends VcsDownloader $this->io->setAuthentication($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 ($command) { return sprintf($command, escapeshellarg($url)); }; @@ -416,4 +416,14 @@ class GitDownloader extends VcsDownloader $this->hasStashedChanges = true; } + + protected function cleanEnv() + { + // clean up rogue git env vars in case this is running in a git hook + putenv('GIT_DIR'); + putenv('GIT_WORK_TREE'); + + // added in git 1.7.1, prevents prompting the user for username/password + putenv('GIT_ASKPASS=echo'); + } } diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index ee7489be9..5c3095dce 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -38,6 +38,13 @@ class GitDriver extends VcsDriver } else { $this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/'; + // clean up rogue git env vars in case this is running in a git hook + putenv('GIT_DIR'); + putenv('GIT_WORK_TREE'); + + // added in git 1.7.1, prevents prompting the user for username/password + putenv('GIT_ASKPASS=echo'); + $fs = new Filesystem(); $fs->ensureDirectoryExists(dirname($this->repoDir)); @@ -58,8 +65,6 @@ class GitDriver extends VcsDriver // clean up directory and do a fresh clone into it $fs->removeDirectory($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();