Detect safe_mode and output correct error, closes #2006
parent
db22befc76
commit
f79c4e4309
|
@ -14,6 +14,7 @@ namespace Composer\Downloader;
|
||||||
|
|
||||||
use Composer\Package\PackageInterface;
|
use Composer\Package\PackageInterface;
|
||||||
use Composer\Util\GitHub;
|
use Composer\Util\GitHub;
|
||||||
|
use Composer\Util\Git as GitUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
@ -433,12 +434,8 @@ class GitDownloader extends VcsDownloader
|
||||||
|
|
||||||
protected function cleanEnv()
|
protected function cleanEnv()
|
||||||
{
|
{
|
||||||
// clean up rogue git env vars in case this is running in a git hook
|
$util = new GitUtil;
|
||||||
putenv('GIT_DIR');
|
$util->cleanEnv();
|
||||||
putenv('GIT_WORK_TREE');
|
|
||||||
|
|
||||||
// added in git 1.7.1, prevents prompting the user for username/password
|
|
||||||
putenv('GIT_ASKPASS=echo');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function normalizePath($path)
|
protected function normalizePath($path)
|
||||||
|
|
|
@ -15,6 +15,7 @@ namespace Composer\Repository\Vcs;
|
||||||
use Composer\Json\JsonFile;
|
use Composer\Json\JsonFile;
|
||||||
use Composer\Util\ProcessExecutor;
|
use Composer\Util\ProcessExecutor;
|
||||||
use Composer\Util\Filesystem;
|
use Composer\Util\Filesystem;
|
||||||
|
use Composer\Util\Git as GitUtil;
|
||||||
use Composer\IO\IOInterface;
|
use Composer\IO\IOInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,12 +39,8 @@ class GitDriver extends VcsDriver
|
||||||
} else {
|
} else {
|
||||||
$this->repoDir = $this->config->get('cache-vcs-dir') . '/' . preg_replace('{[^a-z0-9.]}i', '-', $this->url) . '/';
|
$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
|
$util = new GitUtil;
|
||||||
putenv('GIT_DIR');
|
$util->cleanEnv();
|
||||||
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 = new Filesystem();
|
||||||
$fs->ensureDirectoryExists(dirname($this->repoDir));
|
$fs->ensureDirectoryExists(dirname($this->repoDir));
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Composer.
|
||||||
|
*
|
||||||
|
* (c) Nils Adermann <naderman@naderman.de>
|
||||||
|
* Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Composer\Util;
|
||||||
|
|
||||||
|
use Composer\IO\IOInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Jordi Boggiano <j.boggiano@seld.be>
|
||||||
|
*/
|
||||||
|
class Git
|
||||||
|
{
|
||||||
|
public function cleanEnv()
|
||||||
|
{
|
||||||
|
if (ini_get('safe_mode') && false === strpos(ini_get('safe_mode_allowed_env_vars', 'GIT_ASKPASS'))) {
|
||||||
|
throw new \RuntimeException('safe_mode is enabled and safe_mode_allowed_env_vars does not contain GIT_ASKPASS, can not set env var. You can disable safe_mode with "-dsafe_mode=0" when running composer');
|
||||||
|
}
|
||||||
|
|
||||||
|
// added in git 1.7.1, prevents prompting the user for username/password
|
||||||
|
putenv('GIT_ASKPASS=echo');
|
||||||
|
|
||||||
|
// clean up rogue git env vars in case this is running in a git hook
|
||||||
|
if (getenv('GIT_DIR')) {
|
||||||
|
putenv('GIT_DIR');
|
||||||
|
}
|
||||||
|
if (getenv('GIT_WORK_TREE')) {
|
||||||
|
putenv('GIT_WORK_TREE');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue