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;
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<FlutterVersion> 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);
}
......
......@@ -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: <Type, Generator>{
......@@ -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>[
FakeCommand(command: <String>[
'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);
......
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