From ec2722f87967af665d2e92bb71bf1d536ae9a31f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 7 Aug 2017 10:36:02 +0200 Subject: [PATCH] Add ability to call composer from within subdirectories of a project, fixes #6426 --- src/Composer/Console/Application.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index d6b265f53..96ba7d900 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -126,6 +126,24 @@ 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')) { + $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 ($io->askConfirmation('No composer.json in current directory, do you want to use the one at '.$dir.'? [Y,n]? ', true)) { + $oldWorkingDir = getcwd(); + chdir($dir); + } + break; + } + $dir = dirname($dir); + } + } + if (!$this->disablePluginsByDefault && !$this->hasPluginCommands && 'global' !== $commandName) { try { foreach ($this->getPluginCommands() as $command) {