mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
[flutter_tool] Do not continue with a no-op 'upgrade' (#46011)
This commit is contained in:
parent
066a992a5c
commit
4484ae4043
|
@ -117,8 +117,13 @@ class UpgradeCommandRunner {
|
||||||
}
|
}
|
||||||
await resetChanges(gitTagVersion);
|
await resetChanges(gitTagVersion);
|
||||||
await upgradeChannel(flutterVersion);
|
await upgradeChannel(flutterVersion);
|
||||||
await attemptFastForward();
|
final bool alreadyUpToDate = await attemptFastForward(flutterVersion);
|
||||||
await flutterUpgradeContinue();
|
if (alreadyUpToDate) {
|
||||||
|
// If the upgrade was a no op, then do not continue with the second half.
|
||||||
|
printTrace('Flutter is already up to date on channel ${flutterVersion.channel}');
|
||||||
|
} else {
|
||||||
|
await flutterUpgradeContinue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> flutterUpgradeContinue() async {
|
Future<void> flutterUpgradeContinue() async {
|
||||||
|
@ -229,7 +234,10 @@ class UpgradeCommandRunner {
|
||||||
///
|
///
|
||||||
/// If there haven't been any hot fixes or local changes, this is equivalent
|
/// If there haven't been any hot fixes or local changes, this is equivalent
|
||||||
/// to a fast-forward.
|
/// to a fast-forward.
|
||||||
Future<void> attemptFastForward() async {
|
///
|
||||||
|
/// If the fast forward lands us on the same channel and revision, then
|
||||||
|
/// returns true, otherwise returns false.
|
||||||
|
Future<bool> attemptFastForward(FlutterVersion oldFlutterVersion) async {
|
||||||
final int code = await processUtils.stream(
|
final int code = await processUtils.stream(
|
||||||
<String>['git', 'pull', '--ff'],
|
<String>['git', 'pull', '--ff'],
|
||||||
workingDirectory: Cache.flutterRoot,
|
workingDirectory: Cache.flutterRoot,
|
||||||
|
@ -238,6 +246,17 @@ class UpgradeCommandRunner {
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
throwToolExit(null, exitCode: code);
|
throwToolExit(null, exitCode: code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the upgrade did anything.
|
||||||
|
bool alreadyUpToDate = false;
|
||||||
|
try {
|
||||||
|
final FlutterVersion newFlutterVersion = FlutterVersion();
|
||||||
|
alreadyUpToDate = newFlutterVersion.channel == oldFlutterVersion.channel &&
|
||||||
|
newFlutterVersion.frameworkRevision == oldFlutterVersion.frameworkRevision;
|
||||||
|
} catch (e) {
|
||||||
|
printTrace('Failed to determine FlutterVersion after upgrade fast-forward: $e');
|
||||||
|
}
|
||||||
|
return alreadyUpToDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update the engine repository and precache all artifacts.
|
/// Update the engine repository and precache all artifacts.
|
||||||
|
|
|
@ -121,6 +121,30 @@ void main() {
|
||||||
Platform: () => fakePlatform,
|
Platform: () => fakePlatform,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testUsingContext('Doesn\'t continue on known tag, dev branch, no force, already up-to-date', () async {
|
||||||
|
fakeCommandRunner.alreadyUpToDate = true;
|
||||||
|
final Future<FlutterCommandResult> result = fakeCommandRunner.runCommand(
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
gitTagVersion,
|
||||||
|
flutterVersion,
|
||||||
|
);
|
||||||
|
expect(await result, null);
|
||||||
|
verifyNever(processManager.start(
|
||||||
|
<String>[
|
||||||
|
fs.path.join('bin', 'flutter'),
|
||||||
|
'upgrade',
|
||||||
|
'--continue',
|
||||||
|
'--no-version-check',
|
||||||
|
],
|
||||||
|
environment: anyNamed('environment'),
|
||||||
|
workingDirectory: anyNamed('workingDirectory'),
|
||||||
|
));
|
||||||
|
}, overrides: <Type, Generator>{
|
||||||
|
ProcessManager: () => processManager,
|
||||||
|
Platform: () => fakePlatform,
|
||||||
|
});
|
||||||
|
|
||||||
testUsingContext('verifyUpstreamConfigured', () async {
|
testUsingContext('verifyUpstreamConfigured', () async {
|
||||||
when(processManager.run(
|
when(processManager.run(
|
||||||
<String>['git', 'rev-parse', '@{u}'],
|
<String>['git', 'rev-parse', '@{u}'],
|
||||||
|
@ -288,6 +312,8 @@ void main() {
|
||||||
class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
||||||
bool willHaveUncomittedChanges = false;
|
bool willHaveUncomittedChanges = false;
|
||||||
|
|
||||||
|
bool alreadyUpToDate = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> verifyUpstreamConfigured() async {}
|
Future<void> verifyUpstreamConfigured() async {}
|
||||||
|
|
||||||
|
@ -301,7 +327,7 @@ class FakeUpgradeCommandRunner extends UpgradeCommandRunner {
|
||||||
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
|
Future<void> upgradeChannel(FlutterVersion flutterVersion) async {}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> attemptFastForward() async {}
|
Future<bool> attemptFastForward(FlutterVersion flutterVersion) async => alreadyUpToDate;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> precacheArtifacts() async {}
|
Future<void> precacheArtifacts() async {}
|
||||||
|
|
Loading…
Reference in a new issue