mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
warn on uncomitted changes (#30235)
This commit is contained in:
parent
f66ee3e470
commit
316d44989a
@ -72,6 +72,17 @@ class UpgradeCommandRunner {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If there are uncomitted changes we might be on the right commit but
|
||||||
|
// we should still warn.
|
||||||
|
if (!force && await hasUncomittedChanges()) {
|
||||||
|
throwToolExit(
|
||||||
|
'Your flutter checkout has local changes that would be erased by '
|
||||||
|
'upgrading. If you want to keep these changes, it is recommended that '
|
||||||
|
'you stash them via "git stash" or else commit the changes to a local '
|
||||||
|
'branch. If it is okay to remove local changes, then re-run this '
|
||||||
|
'command with --force.'
|
||||||
|
);
|
||||||
|
}
|
||||||
await resetChanges(gitTagVersion);
|
await resetChanges(gitTagVersion);
|
||||||
await upgradeChannel(flutterVersion);
|
await upgradeChannel(flutterVersion);
|
||||||
await attemptFastForward();
|
await attemptFastForward();
|
||||||
@ -81,6 +92,18 @@ class UpgradeCommandRunner {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> hasUncomittedChanges() async {
|
||||||
|
try {
|
||||||
|
final RunResult result = await runCheckedAsync(<String>[
|
||||||
|
'git', 'status', '-s'
|
||||||
|
], workingDirectory: Cache.flutterRoot);
|
||||||
|
return result.stdout.trim().isNotEmpty;
|
||||||
|
} catch (e) {
|
||||||
|
throwToolExit('git status failed: $e');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if there is an upstream repository configured.
|
/// Check if there is an upstream repository configured.
|
||||||
///
|
///
|
||||||
/// Exits tool if there is no upstream.
|
/// Exits tool if there is no upstream.
|
||||||
|
@ -29,6 +29,7 @@ void main() {
|
|||||||
fakeCommandRunner = FakeUpgradeCommandRunner();
|
fakeCommandRunner = FakeUpgradeCommandRunner();
|
||||||
realCommandRunner = UpgradeCommandRunner();
|
realCommandRunner = UpgradeCommandRunner();
|
||||||
processManager = MockProcessManager();
|
processManager = MockProcessManager();
|
||||||
|
fakeCommandRunner.willHaveUncomittedChanges = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
test('throws on unknown tag, official branch, noforce', () async {
|
test('throws on unknown tag, official branch, noforce', () async {
|
||||||
@ -49,6 +50,26 @@ void main() {
|
|||||||
expect(await result, null);
|
expect(await result, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('throws tool exit with uncommited changes', () async {
|
||||||
|
fakeCommandRunner.willHaveUncomittedChanges = true;
|
||||||
|
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
|
||||||
|
false,
|
||||||
|
gitTagVersion,
|
||||||
|
flutterVersion,
|
||||||
|
);
|
||||||
|
expect(result, throwsA(isA<ToolExit>()));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not throw tool exit with uncommited changes and force', () async {
|
||||||
|
fakeCommandRunner.willHaveUncomittedChanges = true;
|
||||||
|
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
|
||||||
|
true,
|
||||||
|
gitTagVersion,
|
||||||
|
flutterVersion,
|
||||||
|
);
|
||||||
|
expect(await result, null);
|
||||||
|
});
|
||||||
|
|
||||||
test('Doesn\'t throw on known tag, dev branch, no force', () async {
|
test('Doesn\'t throw on known tag, dev branch, no force', () async {
|
||||||
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
|
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
|
||||||
false,
|
false,
|
||||||
@ -127,9 +148,14 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
||||||
|
bool willHaveUncomittedChanges = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> verifyUpstreamConfigured() async {}
|
Future<void> verifyUpstreamConfigured() async {}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> hasUncomittedChanges() async => willHaveUncomittedChanges;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> resetChanges(GitTagVersion gitTagVersion) async {}
|
Future<void> resetChanges(GitTagVersion gitTagVersion) async {}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user