Unverified Commit 069dc9c7 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] catch ProcessException and throw ToolExit during upgrade (#55759)

parent 2aa90166
...@@ -137,7 +137,7 @@ class UpgradeCommandRunner { ...@@ -137,7 +137,7 @@ class UpgradeCommandRunner {
} }
recordState(flutterVersion); recordState(flutterVersion);
await upgradeChannel(flutterVersion); await upgradeChannel(flutterVersion);
await attemptReset(flutterVersion, upstreamRevision); await attemptReset(upstreamRevision);
if (!testFlow) { if (!testFlow) {
await flutterUpgradeContinue(); await flutterUpgradeContinue();
} }
...@@ -243,14 +243,15 @@ class UpgradeCommandRunner { ...@@ -243,14 +243,15 @@ class UpgradeCommandRunner {
/// This is a reset instead of fast forward because if we are on a release /// This is a reset instead of fast forward because if we are on a release
/// branch with cherry picks, there may not be a direct fast-forward route /// branch with cherry picks, there may not be a direct fast-forward route
/// to the next release. /// to the next release.
Future<void> attemptReset(FlutterVersion oldFlutterVersion, String newRevision) async { Future<void> attemptReset(String newRevision) async {
final RunResult result = await processUtils.run( try {
<String>['git', 'reset', '--hard', newRevision], await processUtils.run(
throwOnError: true, <String>['git', 'reset', '--hard', newRevision],
workingDirectory: workingDirectory, throwOnError: true,
); workingDirectory: workingDirectory,
if (result.exitCode != 0) { );
throwToolExit(null, exitCode: result.exitCode); } on ProcessException catch (e) {
throwToolExit(e.message, exitCode: e.errorCode);
} }
} }
......
...@@ -186,6 +186,26 @@ void main() { ...@@ -186,6 +186,26 @@ void main() {
Platform: () => fakePlatform, Platform: () => fakePlatform,
}); });
testUsingContext('git exception during attemptReset throwsToolExit', () async {
const String revision = 'abc123';
const String errorMessage = 'fatal: Could not parse object ´$revision´';
when(processManager.run(
<String>['git', 'reset', '--hard', revision]
)).thenThrow(const ProcessException(
'git',
<String>['reset', '--hard', revision],
errorMessage,
));
expect(
() async => await realCommandRunner.attemptReset(revision),
throwsToolExit(message: errorMessage),
);
}, overrides: <Type, Generator>{
ProcessManager: () => processManager,
Platform: () => fakePlatform,
});
testUsingContext('flutterUpgradeContinue passes env variables to child process', () async { testUsingContext('flutterUpgradeContinue passes env variables to child process', () async {
await realCommandRunner.flutterUpgradeContinue(); await realCommandRunner.flutterUpgradeContinue();
...@@ -315,7 +335,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner { ...@@ -315,7 +335,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {} Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
@override @override
Future<bool> attemptReset(FlutterVersion flutterVersion, String newRevision) async => alreadyUpToDate; Future<void> attemptReset(String newRevision) async {}
@override @override
Future<void> precacheArtifacts() async {} Future<void> precacheArtifacts() 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