Unverified Commit 52e4214d authored by Chris Bracken's avatar Chris Bracken Committed by GitHub

Fix crash on flutter update-packages (#28922)

When running git update-packages, if the goldens repo is dirty, the
flutter tool currently crashes and logs the failure from git pull.

This adds a check for a dirty git client and emits a friendlier error
message in the case where it's not clean, and avoid the crash by
catching the NonZeroExitCode exception and rethrowing as toolExit
instead.

Fixes: https://github.com/flutter/flutter/issues/28915
parent 4c1f4d14
......@@ -80,6 +80,7 @@ class GoldensClient {
if (currentCommit == null) {
await _initRepository();
}
await _checkCanSync();
await _syncTo(goldensCommit);
}
} finally {
......@@ -117,6 +118,23 @@ class GoldensClient {
);
}
Future<void> _checkCanSync() async {
final io.ProcessResult result = await process.run(
<String>['git', 'status', '--porcelain'],
workingDirectory: repositoryRoot.path,
);
if (result.stdout.trim().isNotEmpty) {
final StringBuffer buf = StringBuffer();
buf
..writeln('flutter_goldens git checkout at ${repositoryRoot.path} has local changes and cannot be synced.')
..writeln('To reset your client to a clean state, and lose any local golden test changes:')
..writeln('cd ${repositoryRoot.path}')
..writeln('git reset --hard HEAD')
..writeln('git clean -x -d -f -f');
throw NonZeroExitCode(1, buf.toString());
}
}
Future<void> _syncTo(String commit) async {
await _runCommands(
<String>[
......@@ -163,7 +181,7 @@ class NonZeroExitCode implements Exception {
/// The first argument must be non-zero.
const NonZeroExitCode(this.exitCode, this.stderr) : assert(exitCode != 0);
/// The code that the process will signal to th eoperating system.
/// The code that the process will signal to the operating system.
///
/// By definiton, this is not zero.
final int exitCode;
......
......@@ -132,8 +132,12 @@ class UpdatePackagesCommand extends FlutterCommand {
// package that is in the goldens repository. We need to make sure that the goldens
// repository is cloned locally before we verify or update pubspecs.
printStatus('Cloning goldens repository...');
final GoldensClient goldensClient = GoldensClient();
await goldensClient.prepare();
try {
final GoldensClient goldensClient = GoldensClient();
await goldensClient.prepare();
} on NonZeroExitCode catch (e) {
throwToolExit(e.stderr, exitCode: e.exitCode);
}
if (isVerifyOnly) {
bool needsUpdate = false;
......
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