Unverified Commit bc4bd7bd authored by Zachary Anderson's avatar Zachary Anderson Committed by GitHub

[flutter_tools] Don't try to run pub before the version command (#51436)

parent 22c80777
......@@ -17,11 +17,17 @@ import '../version.dart';
class VersionCommand extends FlutterCommand {
VersionCommand() : super() {
usesPubOption(hide: true);
argParser.addFlag('force',
abbr: 'f',
help: 'Force switch to older Flutter versions that do not include a version command',
);
// Don't use usesPubOption here. That will cause the version command to
// require a pubspec.yaml file, which it doesn't need.
argParser.addFlag('pub',
defaultsTo: true,
hide: true,
help: 'Whether to run "flutter pub get" after switching versions.',
);
}
@override
......@@ -138,7 +144,7 @@ class VersionCommand extends FlutterCommand {
globals.printStatus(flutterVersion.toString());
final String projectRoot = findProjectRoot();
if (projectRoot != null && shouldRunPub) {
if (projectRoot != null && boolArg('pub')) {
globals.printStatus('');
await pub.get(
context: PubContext.pubUpgrade,
......
......@@ -170,6 +170,17 @@ void main() {
ProcessManager: () => MockProcessManager(failGitTag: true),
Stdio: () => mockStdio,
});
testUsingContext('Does not run pub when outside a project', () async {
final VersionCommand command = VersionCommand();
await createTestCommandRunner(command).run(<String>[
'version',
]);
expect(testLogger.statusText, equals('v10.0.0\r\nv20.0.0\n'));
}, overrides: <Type, Generator>{
ProcessManager: () => MockProcessManager(),
Stdio: () => mockStdio,
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment