From ade9f6a9f0bb585109a078c9a2294d1c7cadb4c9 Mon Sep 17 00:00:00 2001 From: Anurag Roy <44899587+RoyARG02@users.noreply.github.com> Date: Fri, 30 Jul 2021 10:30:44 +0530 Subject: [PATCH] [flutter_tools] Improve toolexit error messages for `flutter upgrade` (#86351) --- .../lib/src/commands/upgrade.dart | 20 +++++++++++-------- .../permeable/upgrade_test.dart | 17 ++++++++++------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/upgrade.dart b/packages/flutter_tools/lib/src/commands/upgrade.dart index 811248517c..eebcc29520 100644 --- a/packages/flutter_tools/lib/src/commands/upgrade.dart +++ b/packages/flutter_tools/lib/src/commands/upgrade.dart @@ -17,6 +17,9 @@ import '../globals_null_migrated.dart' as globals; import '../runner/flutter_command.dart'; import '../version.dart'; +// The official docs to install Flutter. +const String _flutterInstallDocs = 'https://flutter.dev/docs/get-started/install'; + class UpgradeCommand extends FlutterCommand { UpgradeCommand({ @required bool verboseHelp, @@ -224,7 +227,7 @@ class UpgradeCommandRunner { /// Returns the remote HEAD flutter version. /// - /// Exits tool if there is no upstream. + /// Exits tool if HEAD isn't pointing to a branch, or there is no upstream. Future fetchLatestVersion() async { String revision; try { @@ -245,16 +248,17 @@ class UpgradeCommandRunner { final String errorString = e.toString(); if (errorString.contains('fatal: HEAD does not point to a branch')) { throwToolExit( - 'You are not currently on a release branch. Use git to ' - "check out an official branch ('stable', 'beta', 'dev', or 'master') " - 'and retry, for example:\n' - ' git checkout stable' + 'Unable to upgrade Flutter: Your Flutter checkout is currently not ' + 'on a release branch.\n' + 'Use "flutter channel" to switch to an official channel, and retry. ' + 'Alternatively, re-install Flutter by going to $_flutterInstallDocs.' ); } else if (errorString.contains('fatal: no upstream configured for branch')) { throwToolExit( - 'Unable to upgrade Flutter: no origin repository configured. ' - "Run 'git remote add origin " - "https://github.com/flutter/flutter' in $workingDirectory"); + 'Unable to upgrade Flutter: The current Flutter branch/channel is ' + 'not tracking any remote repository.\n' + 'Re-install Flutter by going to $_flutterInstallDocs.' + ); } else { throwToolExit(errorString); } 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 d6ec1c116f..a3c93ae4a3 100644 --- a/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart +++ b/packages/flutter_tools/test/commands.shard/permeable/upgrade_test.dart @@ -199,8 +199,12 @@ void main() { ]); await expectLater( - () async => realCommandRunner.fetchLatestVersion(), - throwsToolExit(message: 'You are not currently on a release branch.'), + () async => realCommandRunner.fetchLatestVersion(), + throwsToolExit(message: 'Unable to upgrade Flutter: Your Flutter checkout ' + 'is currently not on a release branch.\n' + 'Use "flutter channel" to switch to an official channel, and retry. ' + 'Alternatively, re-install Flutter by going to https://flutter.dev/docs/get-started/install.' + ), ); expect(processManager, hasNoRemainingExpectations); }, overrides: { @@ -208,7 +212,7 @@ void main() { Platform: () => fakePlatform, }); - testUsingContext('fetchRemoteRevision throws toolExit if no upstream configured', () async { + testUsingContext('fetchLatestVersion throws toolExit if no upstream configured', () async { processManager.addCommands(const [ FakeCommand(command: [ 'git', 'fetch', '--tags' @@ -224,9 +228,10 @@ void main() { ]); await expectLater( - () async => realCommandRunner.fetchLatestVersion(), - throwsToolExit( - message: 'Unable to upgrade Flutter: no origin repository configured.', + () async => realCommandRunner.fetchLatestVersion(), + throwsToolExit(message: 'Unable to upgrade Flutter: The current Flutter ' + 'branch/channel is not tracking any remote repository.\n' + 'Re-install Flutter by going to https://flutter.dev/docs/get-started/install.' ), ); expect(processManager, hasNoRemainingExpectations);