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