Make Git::cleanEnv static

main
Jordi Boggiano 10 years ago
parent e23665be59
commit e0886b94a2

@ -28,7 +28,7 @@ class GitDownloader extends VcsDownloader
*/ */
public function doDownload(PackageInterface $package, $path, $url) public function doDownload(PackageInterface $package, $path, $url)
{ {
$this->cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
$ref = $package->getSourceReference(); $ref = $package->getSourceReference();
@ -56,7 +56,7 @@ class GitDownloader extends VcsDownloader
*/ */
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url)
{ {
$this->cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!is_dir($path.'/.git')) { if (!is_dir($path.'/.git')) {
throw new \RuntimeException('The .git directory is missing from '.$path.', see http://getcomposer.org/commit-deps for more information'); throw new \RuntimeException('The .git directory is missing from '.$path.', see http://getcomposer.org/commit-deps for more information');
@ -90,7 +90,7 @@ class GitDownloader extends VcsDownloader
*/ */
public function getLocalChanges(PackageInterface $package, $path) public function getLocalChanges(PackageInterface $package, $path)
{ {
$this->cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!is_dir($path.'/.git')) { if (!is_dir($path.'/.git')) {
return; return;
@ -109,7 +109,7 @@ class GitDownloader extends VcsDownloader
*/ */
protected function cleanChanges(PackageInterface $package, $path, $update) protected function cleanChanges(PackageInterface $package, $path, $update)
{ {
$this->cleanEnv(); GitUtil::cleanEnv();
$path = $this->normalizePath($path); $path = $this->normalizePath($path);
if (!$changes = $this->getLocalChanges($package, $path)) { if (!$changes = $this->getLocalChanges($package, $path)) {
return; return;
@ -467,12 +467,6 @@ class GitDownloader extends VcsDownloader
$this->hasStashedChanges = true; $this->hasStashedChanges = true;
} }
protected function cleanEnv()
{
$util = new GitUtil;
$util->cleanEnv();
}
protected function normalizePath($path) protected function normalizePath($path)
{ {
if (defined('PHP_WINDOWS_VERSION_MAJOR') && strlen($path) > 0) { if (defined('PHP_WINDOWS_VERSION_MAJOR') && strlen($path) > 0) {

@ -191,8 +191,7 @@ class RootPackageLoader extends ArrayLoader
private function guessGitVersion(array $config) private function guessGitVersion(array $config)
{ {
$util = new GitUtil; GitUtil::cleanEnv();
$util->cleanEnv();
// try to fetch current version from git tags // try to fetch current version from git tags
if (0 === $this->process->execute('git describe --exact-match --tags', $output)) { if (0 === $this->process->execute('git describe --exact-match --tags', $output)) {

@ -327,8 +327,7 @@ class Locker
$sourceRef = $package->getSourceReference() ?: $package->getDistReference(); $sourceRef = $package->getSourceReference() ?: $package->getDistReference();
switch ($sourceType) { switch ($sourceType) {
case 'git': case 'git':
$util = new GitUtil; GitUtil::cleanEnv();
$util->cleanEnv();
if (0 === $this->process->execute('git log -n1 --pretty=%ct '.escapeshellarg($sourceRef), $output, $path) && preg_match('{^\s*\d+\s*$}', $output)) { if (0 === $this->process->execute('git log -n1 --pretty=%ct '.escapeshellarg($sourceRef), $output, $path) && preg_match('{^\s*\d+\s*$}', $output)) {
$datetime = new \DateTime('@'.trim($output), new \DateTimeZone('UTC')); $datetime = new \DateTime('@'.trim($output), new \DateTimeZone('UTC'));

@ -42,8 +42,7 @@ 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) . '/';
$util = new GitUtil; GitUtil::cleanEnv();
$util->cleanEnv();
$fs = new Filesystem(); $fs = new Filesystem();
$fs->ensureDirectoryExists(dirname($this->repoDir)); $fs->ensureDirectoryExists(dirname($this->repoDir));

@ -17,7 +17,7 @@ namespace Composer\Util;
*/ */
class Git class Git
{ {
public function cleanEnv() public static function cleanEnv()
{ {
if (ini_get('safe_mode') && false === strpos(ini_get('safe_mode_allowed_env_vars'), 'GIT_ASKPASS')) { 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'); 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');

Loading…
Cancel
Save