1
0
Fork 0

Merge pull request #6595 from dzuelke/cwdup_composer_fix

Fix 1.5.0 ancestor dir composer.json search not using COMPOSER env var
pull/6598/head
Jordi Boggiano 2017-08-08 18:29:31 +02:00 committed by GitHub
commit 4ea017d1ce
2 changed files with 8 additions and 4 deletions

View File

@ -146,10 +146,14 @@ EOT
// passed in a file to use // passed in a file to use
$configFile = $input->getOption('global') $configFile = $input->getOption('global')
? ($this->config->get('home') . '/config.json') ? ($this->config->get('home') . '/config.json')
: ($input->getOption('file') ?: trim(getenv('COMPOSER')) ?: 'composer.json'); : ($input->getOption('file') ?: Factory::getComposerFile());
// Create global composer.json if this was invoked using `composer global config` // Create global composer.json if this was invoked using `composer global config`
if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) { if (
($configFile === 'composer.json' || $configFile === './composer.json')
&& !file_exists($configFile)
&& realpath(getcwd()) === realpath($this->config->get('home'))
) {
file_put_contents($configFile, "{\n}\n"); file_put_contents($configFile, "{\n}\n");
} }

View File

@ -127,13 +127,13 @@ class Application extends BaseApplication
} }
// prompt user for dir change if no composer.json is present in current dir // prompt user for dir change if no composer.json is present in current dir
if ($io->isInteractive() && !in_array($commandName, array('init', 'about', 'help', 'diagnose', 'self-update', 'global'), true) && !file_exists('./composer.json')) { if ($io->isInteractive() && !in_array($commandName, array('init', 'about', 'help', 'diagnose', 'self-update', 'global'), true) && !file_exists(Factory::getComposerFile())) {
$dir = dirname(getcwd()); $dir = dirname(getcwd());
$home = realpath(getenv('HOME') ?: getenv('USERPROFILE') ?: '/'); $home = realpath(getenv('HOME') ?: getenv('USERPROFILE') ?: '/');
// abort when we reach the home dir or top of the filesystem // abort when we reach the home dir or top of the filesystem
while (dirname($dir) !== $dir && $dir !== $home) { while (dirname($dir) !== $dir && $dir !== $home) {
if (file_exists($dir.'/composer.json')) { if (file_exists($dir.'/'.Factory::getComposerFile())) {
if ($io->askConfirmation('<info>No composer.json in current directory, do you want to use the one at '.$dir.'?</info> [<comment>Y,n</comment>]? ', true)) { if ($io->askConfirmation('<info>No composer.json in current directory, do you want to use the one at '.$dir.'?</info> [<comment>Y,n</comment>]? ', true)) {
$oldWorkingDir = getcwd(); $oldWorkingDir = getcwd();
chdir($dir); chdir($dir);