Unverified Commit d4995336 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] Suppress git output in flutter channel (#128475)

Fixes https://github.com/flutter/flutter/issues/128025
parent a0bfde9b
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import '../base/common.dart'; import '../base/common.dart';
import '../base/process.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart' as globals; import '../globals.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
...@@ -160,36 +161,35 @@ class ChannelCommand extends FlutterCommand { ...@@ -160,36 +161,35 @@ class ChannelCommand extends FlutterCommand {
static Future<void> _checkout(String branchName) async { static Future<void> _checkout(String branchName) async {
// Get latest refs from upstream. // Get latest refs from upstream.
int result = await globals.processUtils.stream( RunResult runResult = await globals.processUtils.run(
<String>['git', 'fetch'], <String>['git', 'fetch'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
); );
if (result == 0) { if (runResult.processResult.exitCode == 0) {
result = await globals.processUtils.stream( runResult = await globals.processUtils.run(
<String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'], <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
); );
if (result == 0) { if (runResult.processResult.exitCode == 0) {
// branch already exists, try just switching to it // branch already exists, try just switching to it
result = await globals.processUtils.stream( runResult = await globals.processUtils.run(
<String>['git', 'checkout', branchName, '--'], <String>['git', 'checkout', branchName, '--'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
); );
} else { } else {
// branch does not exist, we have to create it // branch does not exist, we have to create it
result = await globals.processUtils.stream( runResult = await globals.processUtils.run(
<String>['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'], <String>['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'],
workingDirectory: Cache.flutterRoot, workingDirectory: Cache.flutterRoot,
prefix: 'git: ',
); );
} }
} }
if (result != 0) { if (runResult.processResult.exitCode != 0) {
throwToolExit('Switching channels failed with error code $result.', exitCode: result); throwToolExit(
'Switching channels failed\n$runResult.',
exitCode: runResult.processResult.exitCode,
);
} else { } else {
// Remove the version check stamp, since it could contain out-of-date // Remove the version check stamp, since it could contain out-of-date
// information that pertains to the previous channel. // information that pertains to the previous channel.
......
...@@ -276,7 +276,7 @@ void main() { ...@@ -276,7 +276,7 @@ void main() {
command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/stable'], command: <String>['git', 'show-ref', '--verify', '--quiet', 'refs/heads/stable'],
), ),
FakeCommand( FakeCommand(
command: <String>['git', 'checkout', 'stable', '--'] command: <String>['git', 'checkout', 'stable', '--'],
), ),
FakeCommand( FakeCommand(
command: <String>['bin/flutter', '--no-color', '--no-version-check', 'precache'], command: <String>['bin/flutter', '--no-color', '--no-version-check', 'precache'],
......
...@@ -33,6 +33,7 @@ class FakeCommand { ...@@ -33,6 +33,7 @@ class FakeCommand {
this.stdin, this.stdin,
this.exception, this.exception,
this.outputFollowsExit = false, this.outputFollowsExit = false,
this.processStartMode,
}); });
/// The exact commands that must be matched for this [FakeCommand] to be /// The exact commands that must be matched for this [FakeCommand] to be
...@@ -102,14 +103,20 @@ class FakeCommand { ...@@ -102,14 +103,20 @@ class FakeCommand {
/// [Future] on [io.Process] completes. /// [Future] on [io.Process] completes.
final bool outputFollowsExit; final bool outputFollowsExit;
final io.ProcessStartMode? processStartMode;
void _matches( void _matches(
List<String> command, List<String> command,
String? workingDirectory, String? workingDirectory,
Map<String, String>? environment, Map<String, String>? environment,
Encoding? encoding, Encoding? encoding,
io.ProcessStartMode? mode,
) { ) {
final List<dynamic> matchers = this.command.map((Pattern x) => x is String ? x : matches(x)).toList(); final List<dynamic> matchers = this.command.map((Pattern x) => x is String ? x : matches(x)).toList();
expect(command, matchers); expect(command, matchers);
if (processStartMode != null) {
expect(mode, processStartMode);
}
if (this.workingDirectory != null) { if (this.workingDirectory != null) {
expect(workingDirectory, this.workingDirectory); expect(workingDirectory, this.workingDirectory);
} }
...@@ -267,18 +274,26 @@ abstract class FakeProcessManager implements ProcessManager { ...@@ -267,18 +274,26 @@ abstract class FakeProcessManager implements ProcessManager {
String? workingDirectory, String? workingDirectory,
Map<String, String>? environment, Map<String, String>? environment,
Encoding? encoding, Encoding? encoding,
io.ProcessStartMode? mode,
); );
int _pid = 9999; int _pid = 9999;
FakeProcess _runCommand( FakeProcess _runCommand(
List<String> command, List<String> command, {
String? workingDirectory, String? workingDirectory,
Map<String, String>? environment, Map<String, String>? environment,
Encoding? encoding, Encoding? encoding,
) { io.ProcessStartMode? mode,
}) {
_pid += 1; _pid += 1;
final FakeCommand fakeCommand = findCommand(command, workingDirectory, environment, encoding); final FakeCommand fakeCommand = findCommand(
command,
workingDirectory,
environment,
encoding,
mode,
);
if (fakeCommand.exception != null) { if (fakeCommand.exception != null) {
assert(fakeCommand.exception is Exception || fakeCommand.exception is Error); assert(fakeCommand.exception is Exception || fakeCommand.exception is Error);
throw fakeCommand.exception!; // ignore: only_throw_errors throw fakeCommand.exception!; // ignore: only_throw_errors
...@@ -305,9 +320,15 @@ abstract class FakeProcessManager implements ProcessManager { ...@@ -305,9 +320,15 @@ abstract class FakeProcessManager implements ProcessManager {
Map<String, String>? environment, Map<String, String>? environment,
bool includeParentEnvironment = true, // ignored bool includeParentEnvironment = true, // ignored
bool runInShell = false, // ignored bool runInShell = false, // ignored
io.ProcessStartMode mode = io.ProcessStartMode.normal, // ignored io.ProcessStartMode mode = io.ProcessStartMode.normal,
}) { }) {
final FakeProcess process = _runCommand(command.cast<String>(), workingDirectory, environment, io.systemEncoding); final FakeProcess process = _runCommand(
command.cast<String>(),
workingDirectory: workingDirectory,
environment: environment,
encoding: io.systemEncoding,
mode: mode,
);
if (process._completer != null) { if (process._completer != null) {
_fakeRunningProcesses[process.pid] = process; _fakeRunningProcesses[process.pid] = process;
process.exitCode.whenComplete(() { process.exitCode.whenComplete(() {
...@@ -327,7 +348,12 @@ abstract class FakeProcessManager implements ProcessManager { ...@@ -327,7 +348,12 @@ abstract class FakeProcessManager implements ProcessManager {
Encoding? stdoutEncoding = io.systemEncoding, Encoding? stdoutEncoding = io.systemEncoding,
Encoding? stderrEncoding = io.systemEncoding, Encoding? stderrEncoding = io.systemEncoding,
}) async { }) async {
final FakeProcess process = _runCommand(command.cast<String>(), workingDirectory, environment, stdoutEncoding); final FakeProcess process = _runCommand(
command.cast<String>(),
workingDirectory: workingDirectory,
environment: environment,
encoding: stdoutEncoding,
);
await process.exitCode; await process.exitCode;
return io.ProcessResult( return io.ProcessResult(
process.pid, process.pid,
...@@ -347,7 +373,12 @@ abstract class FakeProcessManager implements ProcessManager { ...@@ -347,7 +373,12 @@ abstract class FakeProcessManager implements ProcessManager {
Encoding? stdoutEncoding = io.systemEncoding, Encoding? stdoutEncoding = io.systemEncoding,
Encoding? stderrEncoding = io.systemEncoding, Encoding? stderrEncoding = io.systemEncoding,
}) { }) {
final FakeProcess process = _runCommand(command.cast<String>(), workingDirectory, environment, stdoutEncoding); final FakeProcess process = _runCommand(
command.cast<String>(),
workingDirectory: workingDirectory,
environment: environment,
encoding: stdoutEncoding,
);
return io.ProcessResult( return io.ProcessResult(
process.pid, process.pid,
process._exitCode, process._exitCode,
...@@ -385,12 +416,14 @@ class _FakeAnyProcessManager extends FakeProcessManager { ...@@ -385,12 +416,14 @@ class _FakeAnyProcessManager extends FakeProcessManager {
String? workingDirectory, String? workingDirectory,
Map<String, String>? environment, Map<String, String>? environment,
Encoding? encoding, Encoding? encoding,
io.ProcessStartMode? mode,
) { ) {
return FakeCommand( return FakeCommand(
command: command, command: command,
workingDirectory: workingDirectory, workingDirectory: workingDirectory,
environment: environment, environment: environment,
encoding: encoding, encoding: encoding,
processStartMode: mode,
); );
} }
...@@ -415,12 +448,13 @@ class _SequenceProcessManager extends FakeProcessManager { ...@@ -415,12 +448,13 @@ class _SequenceProcessManager extends FakeProcessManager {
String? workingDirectory, String? workingDirectory,
Map<String, String>? environment, Map<String, String>? environment,
Encoding? encoding, Encoding? encoding,
io.ProcessStartMode? mode,
) { ) {
expect(_commands, isNotEmpty, expect(_commands, isNotEmpty,
reason: 'ProcessManager was told to execute $command (in $workingDirectory) ' reason: 'ProcessManager was told to execute $command (in $workingDirectory) '
'but the FakeProcessManager.list expected no more processes.' 'but the FakeProcessManager.list expected no more processes.'
); );
_commands.first._matches(command, workingDirectory, environment, encoding); _commands.first._matches(command, workingDirectory, environment, encoding, mode);
return _commands.removeAt(0); return _commands.removeAt(0);
} }
......
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