mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Include git output into error message from channel command (#28658)
This commit is contained in:
parent
be083da9c6
commit
604e9dc683
@ -35,7 +35,10 @@ class ChannelCommand extends FlutterCommand {
|
||||
Future<FlutterCommandResult> runCommand() async {
|
||||
switch (argResults.rest.length) {
|
||||
case 0:
|
||||
await _listChannels(showAll: argResults['all']);
|
||||
await _listChannels(
|
||||
showAll: argResults['all'],
|
||||
verbose: globalResults['verbose']
|
||||
);
|
||||
return null;
|
||||
case 1:
|
||||
await _switchChannel(argResults.rest[0]);
|
||||
@ -45,11 +48,12 @@ class ChannelCommand extends FlutterCommand {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _listChannels({ bool showAll }) async {
|
||||
Future<void> _listChannels({ bool showAll, bool verbose }) async {
|
||||
// Beware: currentBranch could contain PII. See getBranchName().
|
||||
final String currentChannel = FlutterVersion.instance.channel;
|
||||
final String currentBranch = FlutterVersion.instance.getBranchName();
|
||||
final Set<String> seenChannels = Set<String>();
|
||||
final List<String> rawOutput = <String>[];
|
||||
|
||||
showAll = showAll || currentChannel != currentBranch;
|
||||
|
||||
@ -58,6 +62,8 @@ class ChannelCommand extends FlutterCommand {
|
||||
<String>['git', 'branch', '-r'],
|
||||
workingDirectory: Cache.flutterRoot,
|
||||
mapFunction: (String line) {
|
||||
if (verbose)
|
||||
rawOutput.add(line);
|
||||
final List<String> split = line.split('/');
|
||||
if (split.length < 2)
|
||||
return null;
|
||||
@ -74,8 +80,10 @@ class ChannelCommand extends FlutterCommand {
|
||||
return null;
|
||||
},
|
||||
);
|
||||
if (result != 0)
|
||||
throwToolExit('List channels failed: $result', exitCode: result);
|
||||
if (result != 0) {
|
||||
final String details = verbose ? '\n${rawOutput.join('\n')}' : '';
|
||||
throwToolExit('List channels failed: $result$details', exitCode: result);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _switchChannel(String branchName) {
|
||||
|
@ -41,15 +41,23 @@ void main() {
|
||||
Cache.disableLocking();
|
||||
});
|
||||
|
||||
testUsingContext('list', () async {
|
||||
Future<void> simpleChannelTest(List<String> args) async {
|
||||
final ChannelCommand command = ChannelCommand();
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
await runner.run(<String>['channel']);
|
||||
await runner.run(args);
|
||||
expect(testLogger.errorText, hasLength(0));
|
||||
// The bots may return an empty list of channels (network hiccup?)
|
||||
// and when run locally the list of branches might be different
|
||||
// so we check for the header text rather than any specific channel name.
|
||||
expect(testLogger.statusText, contains('Flutter channels:'));
|
||||
}
|
||||
|
||||
testUsingContext('list', () async {
|
||||
await simpleChannelTest(<String>['channel']);
|
||||
});
|
||||
|
||||
testUsingContext('verbose list', () async {
|
||||
await simpleChannelTest(<String>['channel', '-v']);
|
||||
});
|
||||
|
||||
testUsingContext('removes duplicates', () async {
|
||||
|
Loading…
Reference in New Issue
Block a user