[flutter_tools] re-use findProjectRoot on flutter command (#104850)

This commit is contained in:
Jesús S Guerrero
2022-06-03 15:23:10 -07:00
committed by GitHub
parent 7df7e8abad
commit 3da9eee2f0
3 changed files with 26 additions and 11 deletions

View File

@@ -12,6 +12,7 @@ import '../application_package.dart';
import '../base/common.dart';
import '../base/context.dart';
import '../base/io.dart' as io;
import '../base/os.dart';
import '../base/user_messages.dart';
import '../base/utils.dart';
import '../build_info.dart';
@@ -1475,16 +1476,12 @@ abstract class FlutterCommand extends Command<void> {
// If there is no pubspec in the current directory, look in the parent
// until one can be found.
bool changedDirectory = false;
while (!globals.fs.isFileSync('pubspec.yaml')) {
final Directory nextCurrent = globals.fs.currentDirectory.parent;
if (nextCurrent == null || nextCurrent.path == globals.fs.currentDirectory.path) {
throw ToolExit(userMessages.flutterNoPubspec);
}
globals.fs.currentDirectory = nextCurrent;
changedDirectory = true;
final String? path = findProjectRoot(globals.fs, globals.fs.currentDirectory.path);
if (path == null) {
throwToolExit(userMessages.flutterNoPubspec);
}
if (changedDirectory) {
if (path != globals.fs.currentDirectory.path) {
globals.fs.currentDirectory = path;
globals.printStatus('Changing current working directory to: ${globals.fs.currentDirectory.path}');
}
}