forked from firka/flutter
[flutter_tools] re-use findProjectRoot on flutter command (#104850)
This commit is contained in:
@@ -58,7 +58,6 @@ class PackagesCommand extends FlutterCommand {
|
||||
|
||||
class PackagesGetCommand extends FlutterCommand {
|
||||
PackagesGetCommand(this.name, this.upgrade) {
|
||||
requiresPubspecYaml();
|
||||
argParser.addFlag('offline',
|
||||
negatable: false,
|
||||
help: 'Use cached packages instead of accessing the network.',
|
||||
|
||||
@@ -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}');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user