mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[ Tool ] Do not remove version files when fetching tags on main / beta (#169994)
Fixes https://github.com/flutter/flutter/issues/142521
This commit is contained in:
parent
d271f270df
commit
68a920255a
@ -128,7 +128,7 @@ abstract class FlutterVersion {
|
||||
fetchTags: fetchTags,
|
||||
);
|
||||
final String frameworkVersion = gitTagVersion.frameworkVersionFor(frameworkRevision);
|
||||
return _FlutterVersionGit._(
|
||||
final _FlutterVersionGit result = _FlutterVersionGit._(
|
||||
clock: clock,
|
||||
flutterRoot: flutterRoot,
|
||||
frameworkRevision: frameworkRevision,
|
||||
@ -136,6 +136,10 @@ abstract class FlutterVersion {
|
||||
gitTagVersion: gitTagVersion,
|
||||
fs: fs,
|
||||
);
|
||||
if (fetchTags) {
|
||||
result.ensureVersionFile();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Ensure the latest git tags are fetched and recalculate [FlutterVersion].
|
||||
|
||||
@ -6,6 +6,7 @@ import 'dart:convert';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:file_testing/file_testing.dart';
|
||||
import 'package:flutter_tools/src/base/logger.dart';
|
||||
import 'package:flutter_tools/src/base/platform.dart';
|
||||
import 'package:flutter_tools/src/base/process.dart';
|
||||
@ -60,13 +61,19 @@ void main() {
|
||||
const String flutterRoot = '/path/to/flutter';
|
||||
|
||||
setUpAll(() {
|
||||
fs = MemoryFileSystem.test();
|
||||
Cache.disableLocking();
|
||||
VersionFreshnessValidator.timeToPauseToLetUserReadTheMessage = Duration.zero;
|
||||
});
|
||||
|
||||
setUp(() {
|
||||
fs = MemoryFileSystem.test();
|
||||
fs.directory(flutterRoot).createSync(recursive: true);
|
||||
FlutterVersion.getVersionFile(fs, flutterRoot).createSync(recursive: true);
|
||||
fs.file(fs.path.join(flutterRoot, 'version')).createSync(recursive: true);
|
||||
});
|
||||
|
||||
testUsingContext(
|
||||
'prints nothing when Flutter installation looks fresh',
|
||||
'prints nothing when Flutter installation looks fresh $channel',
|
||||
() async {
|
||||
const String flutterUpstreamUrl = 'https://github.com/flutter/flutter.git';
|
||||
processManager.addCommands(<FakeCommand>[
|
||||
@ -227,6 +234,199 @@ void main() {
|
||||
overrides: <Type, Generator>{ProcessManager: () => processManager, Cache: () => cache},
|
||||
);
|
||||
|
||||
// Regression test for https://github.com/flutter/flutter/issues/142521
|
||||
testUsingContext(
|
||||
'does not remove version files when fetching tags',
|
||||
() async {
|
||||
const String flutterUpstreamUrl = 'https://github.com/flutter/flutter.git';
|
||||
processManager.addCommands(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%H',
|
||||
],
|
||||
stdout: '1234abcd',
|
||||
),
|
||||
const FakeCommand(command: <String>['git', 'symbolic-ref', '--short', 'HEAD']),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'fetch',
|
||||
'https://github.com/flutter/flutter.git',
|
||||
'--tags',
|
||||
'-f',
|
||||
],
|
||||
),
|
||||
const FakeCommand(command: <String>['git', 'tag', '--points-at', '1234abcd']),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'describe',
|
||||
'--match',
|
||||
'*.*.*',
|
||||
'--long',
|
||||
'--tags',
|
||||
'1234abcd',
|
||||
],
|
||||
stdout: '0.1.2-3-1234abcd',
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>['git', 'symbolic-ref', '--short', 'HEAD'],
|
||||
stdout: channel,
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'rev-parse',
|
||||
'--abbrev-ref',
|
||||
'--symbolic',
|
||||
'@{upstream}',
|
||||
],
|
||||
stdout: 'origin/$channel',
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>['git', 'ls-remote', '--get-url', 'origin'],
|
||||
stdout: flutterUpstreamUrl,
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'HEAD',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ad',
|
||||
'--date=iso',
|
||||
],
|
||||
stdout: getChannelUpToDateVersion().toString(),
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'abcdefg',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ad',
|
||||
'--date=iso',
|
||||
],
|
||||
stdout: getChannelUpToDateVersion().toString(),
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'HEAD',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ad',
|
||||
'--date=iso',
|
||||
],
|
||||
stdout: getChannelUpToDateVersion().toString(),
|
||||
),
|
||||
const FakeCommand(command: <String>['git', 'fetch', '--tags']),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'@{upstream}',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ad',
|
||||
'--date=iso',
|
||||
],
|
||||
stdout: getChannelUpToDateVersion().toString(),
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ar',
|
||||
],
|
||||
stdout: '1 second ago',
|
||||
),
|
||||
FakeCommand(
|
||||
command: const <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'HEAD',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ad',
|
||||
'--date=iso',
|
||||
],
|
||||
stdout: getChannelUpToDateVersion().toString(),
|
||||
),
|
||||
const FakeCommand(
|
||||
command: <String>[
|
||||
'git',
|
||||
'-c',
|
||||
'log.showSignature=false',
|
||||
'log',
|
||||
'-n',
|
||||
'1',
|
||||
'--pretty=format:%ar',
|
||||
'abcdefg',
|
||||
],
|
||||
stdout: '2 seconds ago',
|
||||
),
|
||||
]);
|
||||
|
||||
final FlutterVersion flutterVersion = FlutterVersion(
|
||||
clock: _testClock,
|
||||
fs: fs,
|
||||
flutterRoot: flutterRoot,
|
||||
fetchTags: true,
|
||||
);
|
||||
await flutterVersion.checkFlutterVersionFreshness();
|
||||
|
||||
// Verify the version files exist and have been repopulated after the fetch.
|
||||
expect(FlutterVersion.getVersionFile(fs, flutterRoot), exists); // flutter.version.json
|
||||
expect(fs.file(fs.path.join(flutterRoot, 'version')), exists); // legacy
|
||||
|
||||
expect(flutterVersion.channel, channel);
|
||||
expect(flutterVersion.repositoryUrl, flutterUpstreamUrl);
|
||||
expect(flutterVersion.frameworkRevision, '1234abcd');
|
||||
expect(flutterVersion.frameworkRevisionShort, '1234abcd');
|
||||
expect(flutterVersion.frameworkVersion, '0.0.0-unknown');
|
||||
expect(
|
||||
flutterVersion.toString(),
|
||||
'Flutter • channel $channel • $flutterUpstreamUrl\n'
|
||||
'Framework • revision 1234abcd (1 second ago) • ${getChannelUpToDateVersion()}\n'
|
||||
'Engine • revision abcdefg (2 seconds ago) • ${getChannelUpToDateVersion()}\n'
|
||||
'Tools • Dart 2.12.0 • DevTools 2.8.0',
|
||||
);
|
||||
expect(flutterVersion.frameworkAge, '1 second ago');
|
||||
expect(flutterVersion.getVersionString(), '$channel/1234abcd');
|
||||
expect(flutterVersion.getBranchName(), channel);
|
||||
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd');
|
||||
expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel);
|
||||
|
||||
expect(testLogger.statusText, isEmpty);
|
||||
expect(processManager, hasNoRemainingExpectations);
|
||||
},
|
||||
overrides: <Type, Generator>{ProcessManager: () => processManager, Cache: () => cache},
|
||||
);
|
||||
|
||||
testUsingContext(
|
||||
'does not crash when git log outputs malformed output',
|
||||
() async {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user