diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 4fd2881890..788d1f0e01 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -117,8 +117,13 @@ class UpgradeCommandRunner { } await resetChanges(gitTagVersion); await upgradeChannel(flutterVersion); - await attemptFastForward(); - await flutterUpgradeContinue(); + final bool alreadyUpToDate = await attemptFastForward(flutterVersion); + if (alreadyUpToDate) { + // If the upgrade was a no op, then do not continue with the second half. + printTrace('Flutter is already up to date on channel ${flutterVersion.channel}'); + } else { + await flutterUpgradeContinue(); + } } Future flutterUpgradeContinue() async { @@ -229,7 +234,10 @@ class UpgradeCommandRunner { /// /// If there haven't been any hot fixes or local changes, this is equivalent /// to a fast-forward. - Future attemptFastForward() async { + /// + /// If the fast forward lands us on the same channel and revision, then + /// returns true, otherwise returns false. + Future attemptFastForward(FlutterVersion oldFlutterVersion) async { final int code = await processUtils.stream( ['git', 'pull', '--ff'], workingDirectory: Cache.flutterRoot, @@ -238,6 +246,17 @@ class UpgradeCommandRunner { if (code != 0) { throwToolExit(null, exitCode: code); } + + // Check if the upgrade did anything. + bool alreadyUpToDate = false; + try { + final FlutterVersion newFlutterVersion = FlutterVersion(); + alreadyUpToDate = newFlutterVersion.channel == oldFlutterVersion.channel && + newFlutterVersion.frameworkRevision == oldFlutterVersion.frameworkRevision; + } catch (e) { + printTrace('Failed to determine FlutterVersion after upgrade fast-forward: $e'); + } + return alreadyUpToDate; } /// Update the engine repository and precache all artifacts. diff --git a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart index a5eefc5acc..c64cbcd042 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart @@ -121,6 +121,30 @@ void main() { Platform: () => fakePlatform, }); + testUsingContext('Doesn\'t continue on known tag, dev branch, no force, already up-to-date', () async { + fakeCommandRunner.alreadyUpToDate = true; + final Future result = fakeCommandRunner.runCommand( + false, + false, + gitTagVersion, + flutterVersion, + ); + expect(await result, null); + verifyNever(processManager.start( + [ + fs.path.join('bin', 'flutter'), + 'upgrade', + '--continue', + '--no-version-check', + ], + environment: anyNamed('environment'), + workingDirectory: anyNamed('workingDirectory'), + )); + }, overrides: { + ProcessManager: () => processManager, + Platform: () => fakePlatform, + }); + testUsingContext('verifyUpstreamConfigured', () async { when(processManager.run( ['git', 'rev-parse', '@{u}'], @@ -288,6 +312,8 @@ void main() { class FakeUpgradeCommandRunner extends UpgradeCommandRunner { bool willHaveUncomittedChanges = false; + bool alreadyUpToDate = false; + @override Future verifyUpstreamConfigured() async {} @@ -301,7 +327,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner { Future upgradeChannel(FlutterVersion flutterVersion) async {} @override - Future attemptFastForward() async {} + Future attemptFastForward(FlutterVersion flutterVersion) async => alreadyUpToDate; @override Future precacheArtifacts() async {}