Unverified Commit d5671739 authored by Dave Shifflett's avatar Dave Shifflett Committed by GitHub

Do not run version check if generating shell completion and stdout isn't terminal (#79418)

parent d44ab58d
...@@ -253,11 +253,14 @@ class FlutterCommandRunner extends CommandRunner<void> { ...@@ -253,11 +253,14 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.flutterVersion.ensureVersionFile(); globals.flutterVersion.ensureVersionFile();
final bool machineFlag = topLevelResults['machine'] as bool; final bool machineFlag = topLevelResults['machine'] as bool;
final bool ci = await globals.botDetector.isRunningOnBot; final bool ci = await globals.botDetector.isRunningOnBot;
final bool redirectedCompletion = !globals.stdio.hasTerminal &&
(topLevelResults.command?.name ?? '').endsWith('-completion');
final bool isMachine = machineFlag || ci || redirectedCompletion;
final bool versionCheckFlag = topLevelResults['version-check'] as bool; final bool versionCheckFlag = topLevelResults['version-check'] as bool;
final bool explicitVersionCheckPassed = topLevelResults.wasParsed('version-check') && versionCheckFlag; final bool explicitVersionCheckPassed = topLevelResults.wasParsed('version-check') && versionCheckFlag;
if (topLevelResults.command?.name != 'upgrade' && if (topLevelResults.command?.name != 'upgrade' &&
(explicitVersionCheckPassed || (versionCheckFlag && !ci && !machineFlag))) { (explicitVersionCheckPassed || (versionCheckFlag && !isMachine))) {
await globals.flutterVersion.checkFlutterVersionFreshness(); await globals.flutterVersion.checkFlutterVersionFreshness();
} }
......
...@@ -108,6 +108,40 @@ void main() { ...@@ -108,6 +108,40 @@ void main() {
BotDetector: () => const FakeBotDetector(true), BotDetector: () => const FakeBotDetector(true),
}, initializeFlutterRoot: false); }, initializeFlutterRoot: false);
testUsingContext('checks that Flutter installation is up-to-date if shell completion to terminal', () async {
final FlutterCommand command = DummyFlutterCommand(name: 'bash-completion');
final FlutterCommandRunner runner = createTestCommandRunner(command) as FlutterCommandRunner;
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
await runner.run(<String>['bash-completion']);
expect(version.didCheckFlutterVersionFreshness, true);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
FlutterVersion: () => FakeFlutterVersion(),
BotDetector: () => const FakeBotDetector(false),
Stdio: () => FakeStdio(hasFakeTerminal: true),
});
testUsingContext('does not check that Flutter installation is up-to-date if redirecting shell completion', () async {
final FlutterCommand command = DummyFlutterCommand(name: 'bash-completion');
final FlutterCommandRunner runner = createTestCommandRunner(command) as FlutterCommandRunner;
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
await runner.run(<String>['bash-completion']);
expect(version.didCheckFlutterVersionFreshness, false);
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => platform,
FlutterVersion: () => FakeFlutterVersion(),
BotDetector: () => const FakeBotDetector(false),
Stdio: () => FakeStdio(hasFakeTerminal: false),
});
testUsingContext('Fetches tags when --version is used', () async { testUsingContext('Fetches tags when --version is used', () async {
final FlutterCommandRunner runner = createTestCommandRunner(DummyFlutterCommand()) as FlutterCommandRunner; final FlutterCommandRunner runner = createTestCommandRunner(DummyFlutterCommand()) as FlutterCommandRunner;
final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion; final FakeFlutterVersion version = globals.flutterVersion as FakeFlutterVersion;
......
...@@ -13,6 +13,7 @@ class DummyFlutterCommand extends FlutterCommand { ...@@ -13,6 +13,7 @@ class DummyFlutterCommand extends FlutterCommand {
DummyFlutterCommand({ DummyFlutterCommand({
this.shouldUpdateCache = false, this.shouldUpdateCache = false,
this.noUsagePath = false, this.noUsagePath = false,
this.name = 'dummy',
this.commandFunction, this.commandFunction,
}); });
...@@ -29,7 +30,7 @@ class DummyFlutterCommand extends FlutterCommand { ...@@ -29,7 +30,7 @@ class DummyFlutterCommand extends FlutterCommand {
Future<String> get usagePath => noUsagePath ? null : super.usagePath; Future<String> get usagePath => noUsagePath ? null : super.usagePath;
@override @override
String get name => 'dummy'; final String name;
@override @override
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
......
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