Unverified Commit 604e9dc6 authored by Alexander Markov's avatar Alexander Markov Committed by GitHub

Include git output into error message from channel command (#28658)

parent be083da9
...@@ -35,7 +35,10 @@ class ChannelCommand extends FlutterCommand { ...@@ -35,7 +35,10 @@ class ChannelCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async { Future<FlutterCommandResult> runCommand() async {
switch (argResults.rest.length) { switch (argResults.rest.length) {
case 0: case 0:
await _listChannels(showAll: argResults['all']); await _listChannels(
showAll: argResults['all'],
verbose: globalResults['verbose']
);
return null; return null;
case 1: case 1:
await _switchChannel(argResults.rest[0]); await _switchChannel(argResults.rest[0]);
...@@ -45,11 +48,12 @@ class ChannelCommand extends FlutterCommand { ...@@ -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(). // Beware: currentBranch could contain PII. See getBranchName().
final String currentChannel = FlutterVersion.instance.channel; final String currentChannel = FlutterVersion.instance.channel;
final String currentBranch = FlutterVersion.instance.getBranchName(); final String currentBranch = FlutterVersion.instance.getBranchName();
final Set<String> seenChannels = Set<String>(); final Set<String> seenChannels = Set<String>();
final List<String> rawOutput = <String>[];
showAll = showAll || currentChannel != currentBranch; showAll = showAll || currentChannel != currentBranch;
...@@ -58,6 +62,8 @@ class ChannelCommand extends FlutterCommand { ...@@ -58,6 +62,8 @@ class ChannelCommand extends FlutterCommand {
<String>['git', 'branch', '-r'], <String>['git', 'branch', '-r'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
mapFunction: (String line) { mapFunction: (String line) {
if (verbose)
rawOutput.add(line);
final List<String> split = line.split('/'); final List<String> split = line.split('/');
if (split.length < 2) if (split.length < 2)
return null; return null;
...@@ -74,8 +80,10 @@ class ChannelCommand extends FlutterCommand { ...@@ -74,8 +80,10 @@ class ChannelCommand extends FlutterCommand {
return null; return null;
}, },
); );
if (result != 0) if (result != 0) {
throwToolExit('List channels failed: $result', exitCode: result); final String details = verbose ? '\n${rawOutput.join('\n')}' : '';
throwToolExit('List channels failed: $result$details', exitCode: result);
}
} }
Future<void> _switchChannel(String branchName) { Future<void> _switchChannel(String branchName) {
......
...@@ -41,15 +41,23 @@ void main() { ...@@ -41,15 +41,23 @@ void main() {
Cache.disableLocking(); Cache.disableLocking();
}); });
testUsingContext('list', () async { Future<void> simpleChannelTest(List<String> args) async {
final ChannelCommand command = ChannelCommand(); final ChannelCommand command = ChannelCommand();
final CommandRunner<void> runner = createTestCommandRunner(command); final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['channel']); await runner.run(args);
expect(testLogger.errorText, hasLength(0)); expect(testLogger.errorText, hasLength(0));
// The bots may return an empty list of channels (network hiccup?) // The bots may return an empty list of channels (network hiccup?)
// and when run locally the list of branches might be different // and when run locally the list of branches might be different
// so we check for the header text rather than any specific channel name. // so we check for the header text rather than any specific channel name.
expect(testLogger.statusText, contains('Flutter channels:')); 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 { testUsingContext('removes duplicates', () async {
......
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