[flutter_tools] catch ProcessException and throw ToolExit during upgrade (#55759)
This commit is contained in:
committed by
GitHub
parent
2aa9016652
commit
069dc9c72d
@@ -137,7 +137,7 @@ class UpgradeCommandRunner {
|
||||
}
|
||||
recordState(flutterVersion);
|
||||
await upgradeChannel(flutterVersion);
|
||||
await attemptReset(flutterVersion, upstreamRevision);
|
||||
await attemptReset(upstreamRevision);
|
||||
if (!testFlow) {
|
||||
await flutterUpgradeContinue();
|
||||
}
|
||||
@@ -243,14 +243,15 @@ class UpgradeCommandRunner {
|
||||
/// 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
|
||||
/// to the next release.
|
||||
Future<void> attemptReset(FlutterVersion oldFlutterVersion, String newRevision) async {
|
||||
final RunResult result = await processUtils.run(
|
||||
<String>['git', 'reset', '--hard', newRevision],
|
||||
throwOnError: true,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
if (result.exitCode != 0) {
|
||||
throwToolExit(null, exitCode: result.exitCode);
|
||||
Future<void> attemptReset(String newRevision) async {
|
||||
try {
|
||||
await processUtils.run(
|
||||
<String>['git', 'reset', '--hard', newRevision],
|
||||
throwOnError: true,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
} on ProcessException catch (e) {
|
||||
throwToolExit(e.message, exitCode: e.errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,6 +186,26 @@ void main() {
|
||||
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 {
|
||||
await realCommandRunner.flutterUpgradeContinue();
|
||||
|
||||
@@ -315,7 +335,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
||||
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
|
||||
|
||||
@override
|
||||
Future<bool> attemptReset(FlutterVersion flutterVersion, String newRevision) async => alreadyUpToDate;
|
||||
Future<void> attemptReset(String newRevision) async {}
|
||||
|
||||
@override
|
||||
Future<void> precacheArtifacts() async {}
|
||||
|
||||
Reference in New Issue
Block a user