
## How we determine the channel name Historically, we used the current branch's upstream to figure out the current channel name. I have no idea why. I traced it back to https://github.com/flutter/flutter/pull/446/files where @abarth implement this and I reviewed that PR and left no comment on it at the time. I think this is confusing. You can be on a branch and it tells you that your channel is different. That seems weird. This PR changes the logic to uses the current branch as the channel name. ## How we display channels The main reason this PR exists is to add channel descriptions to the `flutter channel` list: ``` ianh@burmese:~/dev/flutter/packages/flutter_tools$ flutter channel Flutter channels: master (tip of tree, for contributors) main (tip of tree, follows master channel) beta (updated monthly, recommended for experienced users) stable (updated quarterly, for new users and for production app releases) * foo_bar Currently not on an official channel. ianh@burmese:~/dev/flutter/packages/flutter_tools$ ``` ## Other changes I made a few other changes while I was at it: * If you're not on an official channel, we used to imply `--show-all`, but now we don't, we just show the official channels plus yours. This avoids flooding the screen in the case the user is on a weird channel and just wants to know what channel they're on. * I made the tool more consistent about how it handles unofficial branches. Now it's always `[user branch]`. * I slightly adjusted how unknown versions are rendered so it's clearer the version is unknown rather than just having the word "Unknown" floating in the output without context. * Simplified some of the code. * Made some of the tests more strict (checking all output rather than just some aspects of it). * Changed the MockFlutterVersion to implement the FlutterVersion API more strictly. * I made sure we escape the output to `.metadata` to avoid potential injection bugs (previously we just inlined the version and channel name verbatim with no escaping, which is super sketchy). * Tweaked the help text for the `downgrade` command to be clearer. * Removed some misleading text in some error messages. * Made the `.metadata` generator consistent with the template file. * Removed some obsolete code to do with the `dev` branch. ## Reviewer notes I'm worried that there are implications to some of these changes that I am not aware of, so please don't assume I know what I'm doing when reviewing this code. :-)
126 lines
4.2 KiB
Dart
126 lines
4.2 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter_tools/src/base/file_system.dart';
|
|
import 'package:flutter_tools/src/base/io.dart';
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
|
import 'package:flutter_tools/src/base/process.dart';
|
|
import 'package:flutter_tools/src/base/terminal.dart';
|
|
|
|
import '../src/common.dart';
|
|
import 'test_utils.dart';
|
|
|
|
const String _kInitialVersion = '3.0.0';
|
|
const String _kBranch = 'beta';
|
|
|
|
final Stdio stdio = Stdio();
|
|
final ProcessUtils processUtils = ProcessUtils(processManager: processManager, logger: StdoutLogger(
|
|
terminal: AnsiTerminal(
|
|
platform: platform,
|
|
stdio: stdio,
|
|
),
|
|
stdio: stdio,
|
|
outputPreferences: OutputPreferences.test(wrapText: true),
|
|
));
|
|
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', platform.isWindows ? 'flutter.bat' : 'flutter');
|
|
|
|
/// A test for flutter upgrade & downgrade that checks out a parallel flutter repo.
|
|
void main() {
|
|
late Directory parentDirectory;
|
|
|
|
setUp(() {
|
|
parentDirectory = fileSystem.systemTempDirectory
|
|
.createTempSync('flutter_tools.');
|
|
parentDirectory.createSync(recursive: true);
|
|
});
|
|
|
|
tearDown(() {
|
|
tryToDelete(parentDirectory);
|
|
});
|
|
|
|
testWithoutContext('Can upgrade and downgrade a Flutter checkout', () async {
|
|
final Directory testDirectory = parentDirectory.childDirectory('flutter');
|
|
testDirectory.createSync(recursive: true);
|
|
|
|
int exitCode = 0;
|
|
|
|
// Enable longpaths for windows integration test.
|
|
await processManager.run(<String>[
|
|
'git', 'config', '--system', 'core.longpaths', 'true',
|
|
]);
|
|
|
|
printOnFailure('Step 1 - clone the $_kBranch of flutter into the test directory');
|
|
exitCode = await processUtils.stream(<String>[
|
|
'git',
|
|
'clone',
|
|
'https://github.com/flutter/flutter.git',
|
|
], workingDirectory: parentDirectory.path, trace: true);
|
|
expect(exitCode, 0);
|
|
|
|
printOnFailure('Step 2 - switch to the $_kBranch');
|
|
exitCode = await processUtils.stream(<String>[
|
|
'git',
|
|
'checkout',
|
|
'--track',
|
|
'-b',
|
|
_kBranch,
|
|
'origin/$_kBranch',
|
|
], workingDirectory: testDirectory.path, trace: true);
|
|
expect(exitCode, 0);
|
|
|
|
printOnFailure('Step 3 - revert back to $_kInitialVersion');
|
|
exitCode = await processUtils.stream(<String>[
|
|
'git',
|
|
'reset',
|
|
'--hard',
|
|
_kInitialVersion,
|
|
], workingDirectory: testDirectory.path, trace: true);
|
|
expect(exitCode, 0);
|
|
|
|
printOnFailure('Step 4 - upgrade to the newest $_kBranch');
|
|
// This should update the persistent tool state with the sha for HEAD
|
|
// This is probably a source of flakes as it mutates system-global state.
|
|
exitCode = await processUtils.stream(<String>[
|
|
flutterBin,
|
|
'upgrade',
|
|
'--verbose',
|
|
'--working-directory=${testDirectory.path}',
|
|
], workingDirectory: testDirectory.path, trace: true);
|
|
expect(exitCode, 0);
|
|
|
|
printOnFailure('Step 5 - verify that the version is different');
|
|
final RunResult versionResult = await processUtils.run(<String>[
|
|
'git',
|
|
'describe',
|
|
'--match',
|
|
'*.*.*',
|
|
'--long',
|
|
'--tags',
|
|
], workingDirectory: testDirectory.path);
|
|
expect(versionResult.stdout, isNot(contains(_kInitialVersion)));
|
|
printOnFailure('current version is ${versionResult.stdout.trim()}\ninitial was $_kInitialVersion');
|
|
|
|
printOnFailure('Step 6 - downgrade back to the initial version');
|
|
exitCode = await processUtils.stream(<String>[
|
|
flutterBin,
|
|
'downgrade',
|
|
'--no-prompt',
|
|
'--working-directory=${testDirectory.path}',
|
|
], workingDirectory: testDirectory.path, trace: true);
|
|
expect(exitCode, 0);
|
|
|
|
printOnFailure('Step 7 - verify downgraded version matches original version');
|
|
final RunResult oldVersionResult = await processUtils.run(<String>[
|
|
'git',
|
|
'describe',
|
|
'--match',
|
|
'*.*.*',
|
|
'--long',
|
|
'--tags',
|
|
], workingDirectory: testDirectory.path);
|
|
expect(oldVersionResult.stdout, contains(_kInitialVersion));
|
|
printOnFailure('current version is ${oldVersionResult.stdout.trim()}\ninitial was $_kInitialVersion');
|
|
});
|
|
}
|