From ae7c076a7c3359e174cb389d598a6af3179190f2 Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Tue, 8 Aug 2017 18:04:11 +0200 Subject: [PATCH 1/3] use Factory::getComposerFile in ConfigCommand --- src/Composer/Command/ConfigCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index 1761402ee..ca8d4491e 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -146,7 +146,7 @@ EOT // passed in a file to use $configFile = $input->getOption('global') ? ($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` if ($configFile === 'composer.json' && !file_exists($configFile) && realpath(getcwd()) === realpath($this->config->get('home'))) { From b0da7db3af74522881c5fa34858adc5768024e0b Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Tue, 8 Aug 2017 18:08:46 +0200 Subject: [PATCH 2/3] use COMPOSER env var if present for ancestor path search --- src/Composer/Console/Application.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 96ba7d900..081476d93 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -127,13 +127,13 @@ class Application extends BaseApplication } // 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()); $home = realpath(getenv('HOME') ?: getenv('USERPROFILE') ?: '/'); // abort when we reach the home dir or top of the filesystem while (dirname($dir) !== $dir && $dir !== $home) { - if (file_exists($dir.'/composer.json')) { + if (file_exists($dir.'/'.Factory::getComposerFile())) { if ($io->askConfirmation('No composer.json in current directory, do you want to use the one at '.$dir.'? [Y,n]? ', true)) { $oldWorkingDir = getcwd(); chdir($dir); From c1bbb750c437508e5d88addf117ccd70f86b65e9 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 8 Aug 2017 18:29:20 +0200 Subject: [PATCH 3/3] Fix composer global config handling --- src/Composer/Command/ConfigCommand.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/ConfigCommand.php b/src/Composer/Command/ConfigCommand.php index ca8d4491e..eb7a3ff1f 100644 --- a/src/Composer/Command/ConfigCommand.php +++ b/src/Composer/Command/ConfigCommand.php @@ -149,7 +149,11 @@ EOT : ($input->getOption('file') ?: Factory::getComposerFile()); // 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"); }