Unverified Commit ade9f6a9 authored by Anurag Roy's avatar Anurag Roy Committed by GitHub

[flutter_tools] Improve toolexit error messages for `flutter upgrade` (#86351)

parent ed6c9323
...@@ -17,6 +17,9 @@ import '../globals_null_migrated.dart' as globals; ...@@ -17,6 +17,9 @@ import '../globals_null_migrated.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../version.dart'; import '../version.dart';
// The official docs to install Flutter.
const String _flutterInstallDocs = 'https://flutter.dev/docs/get-started/install';
class UpgradeCommand extends FlutterCommand { class UpgradeCommand extends FlutterCommand {
UpgradeCommand({ UpgradeCommand({
@required bool verboseHelp, @required bool verboseHelp,
...@@ -224,7 +227,7 @@ class UpgradeCommandRunner { ...@@ -224,7 +227,7 @@ class UpgradeCommandRunner {
/// Returns the remote HEAD flutter version. /// 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<FlutterVersion> fetchLatestVersion() async { Future<FlutterVersion> fetchLatestVersion() async {
String revision; String revision;
try { try {
...@@ -245,16 +248,17 @@ class UpgradeCommandRunner { ...@@ -245,16 +248,17 @@ class UpgradeCommandRunner {
final String errorString = e.toString(); final String errorString = e.toString();
if (errorString.contains('fatal: HEAD does not point to a branch')) { if (errorString.contains('fatal: HEAD does not point to a branch')) {
throwToolExit( throwToolExit(
'You are not currently on a release branch. Use git to ' 'Unable to upgrade Flutter: Your Flutter checkout is currently not '
"check out an official branch ('stable', 'beta', 'dev', or 'master') " 'on a release branch.\n'
'and retry, for example:\n' 'Use "flutter channel" to switch to an official channel, and retry. '
' git checkout stable' 'Alternatively, re-install Flutter by going to $_flutterInstallDocs.'
); );
} else if (errorString.contains('fatal: no upstream configured for branch')) { } else if (errorString.contains('fatal: no upstream configured for branch')) {
throwToolExit( throwToolExit(
'Unable to upgrade Flutter: no origin repository configured. ' 'Unable to upgrade Flutter: The current Flutter branch/channel is '
"Run 'git remote add origin " 'not tracking any remote repository.\n'
"https://github.com/flutter/flutter' in $workingDirectory"); 'Re-install Flutter by going to $_flutterInstallDocs.'
);
} else { } else {
throwToolExit(errorString); throwToolExit(errorString);
} }
......
...@@ -200,7 +200,11 @@ void main() { ...@@ -200,7 +200,11 @@ void main() {
await expectLater( await expectLater(
() async => realCommandRunner.fetchLatestVersion(), () async => realCommandRunner.fetchLatestVersion(),
throwsToolExit(message: 'You are not currently on a release branch.'), 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); expect(processManager, hasNoRemainingExpectations);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -208,7 +212,7 @@ void main() { ...@@ -208,7 +212,7 @@ void main() {
Platform: () => fakePlatform, Platform: () => fakePlatform,
}); });
testUsingContext('fetchRemoteRevision throws toolExit if no upstream configured', () async { testUsingContext('fetchLatestVersion throws toolExit if no upstream configured', () async {
processManager.addCommands(const <FakeCommand>[ processManager.addCommands(const <FakeCommand>[
FakeCommand(command: <String>[ FakeCommand(command: <String>[
'git', 'fetch', '--tags' 'git', 'fetch', '--tags'
...@@ -225,8 +229,9 @@ void main() { ...@@ -225,8 +229,9 @@ void main() {
await expectLater( await expectLater(
() async => realCommandRunner.fetchLatestVersion(), () async => realCommandRunner.fetchLatestVersion(),
throwsToolExit( throwsToolExit(message: 'Unable to upgrade Flutter: The current Flutter '
message: 'Unable to upgrade Flutter: no origin repository configured.', '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); expect(processManager, hasNoRemainingExpectations);
......
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