Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68a9202

Browse files
authored
[ Tool ] Do not remove version files when fetching tags on main / beta (#169994)
Fixes flutter/flutter#142521
1 parent d271f27 commit 68a9202

2 files changed

Lines changed: 207 additions & 3 deletions

File tree

packages/flutter_tools/lib/src/version.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,18 @@ abstract class FlutterVersion {
128128
fetchTags: fetchTags,
129129
);
130130
final String frameworkVersion = gitTagVersion.frameworkVersionFor(frameworkRevision);
131-
return _FlutterVersionGit._(
131+
final _FlutterVersionGit result = _FlutterVersionGit._(
132132
clock: clock,
133133
flutterRoot: flutterRoot,
134134
frameworkRevision: frameworkRevision,
135135
frameworkVersion: frameworkVersion,
136136
gitTagVersion: gitTagVersion,
137137
fs: fs,
138138
);
139+
if (fetchTags) {
140+
result.ensureVersionFile();
141+
}
142+
return result;
139143
}
140144

141145
/// Ensure the latest git tags are fetched and recalculate [FlutterVersion].

packages/flutter_tools/test/general.shard/version_test.dart

Lines changed: 202 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import 'dart:convert';
66

77
import 'package:file/file.dart';
88
import 'package:file/memory.dart';
9+
import 'package:file_testing/file_testing.dart';
910
import 'package:flutter_tools/src/base/logger.dart';
1011
import 'package:flutter_tools/src/base/platform.dart';
1112
import 'package:flutter_tools/src/base/process.dart';
@@ -60,13 +61,19 @@ void main() {
6061
const String flutterRoot = '/path/to/flutter';
6162

6263
setUpAll(() {
63-
fs = MemoryFileSystem.test();
6464
Cache.disableLocking();
6565
VersionFreshnessValidator.timeToPauseToLetUserReadTheMessage = Duration.zero;
6666
});
6767

68+
setUp(() {
69+
fs = MemoryFileSystem.test();
70+
fs.directory(flutterRoot).createSync(recursive: true);
71+
FlutterVersion.getVersionFile(fs, flutterRoot).createSync(recursive: true);
72+
fs.file(fs.path.join(flutterRoot, 'version')).createSync(recursive: true);
73+
});
74+
6875
testUsingContext(
69-
'prints nothing when Flutter installation looks fresh',
76+
'prints nothing when Flutter installation looks fresh $channel',
7077
() async {
7178
const String flutterUpstreamUrl = 'https://github.com/flutter/flutter.git';
7279
processManager.addCommands(<FakeCommand>[
@@ -227,6 +234,199 @@ void main() {
227234
overrides: <Type, Generator>{ProcessManager: () => processManager, Cache: () => cache},
228235
);
229236

237+
// Regression test for https://github.com/flutter/flutter/issues/142521
238+
testUsingContext(
239+
'does not remove version files when fetching tags',
240+
() async {
241+
const String flutterUpstreamUrl = 'https://github.com/flutter/flutter.git';
242+
processManager.addCommands(<FakeCommand>[
243+
const FakeCommand(
244+
command: <String>[
245+
'git',
246+
'-c',
247+
'log.showSignature=false',
248+
'log',
249+
'-n',
250+
'1',
251+
'--pretty=format:%H',
252+
],
253+
stdout: '1234abcd',
254+
),
255+
const FakeCommand(command: <String>['git', 'symbolic-ref', '--short', 'HEAD']),
256+
const FakeCommand(
257+
command: <String>[
258+
'git',
259+
'fetch',
260+
'https://github.com/flutter/flutter.git',
261+
'--tags',
262+
'-f',
263+
],
264+
),
265+
const FakeCommand(command: <String>['git', 'tag', '--points-at', '1234abcd']),
266+
const FakeCommand(
267+
command: <String>[
268+
'git',
269+
'describe',
270+
'--match',
271+
'*.*.*',
272+
'--long',
273+
'--tags',
274+
'1234abcd',
275+
],
276+
stdout: '0.1.2-3-1234abcd',
277+
),
278+
FakeCommand(
279+
command: const <String>['git', 'symbolic-ref', '--short', 'HEAD'],
280+
stdout: channel,
281+
),
282+
FakeCommand(
283+
command: const <String>[
284+
'git',
285+
'rev-parse',
286+
'--abbrev-ref',
287+
'--symbolic',
288+
'@{upstream}',
289+
],
290+
stdout: 'origin/$channel',
291+
),
292+
const FakeCommand(
293+
command: <String>['git', 'ls-remote', '--get-url', 'origin'],
294+
stdout: flutterUpstreamUrl,
295+
),
296+
FakeCommand(
297+
command: const <String>[
298+
'git',
299+
'-c',
300+
'log.showSignature=false',
301+
'log',
302+
'HEAD',
303+
'-n',
304+
'1',
305+
'--pretty=format:%ad',
306+
'--date=iso',
307+
],
308+
stdout: getChannelUpToDateVersion().toString(),
309+
),
310+
FakeCommand(
311+
command: const <String>[
312+
'git',
313+
'-c',
314+
'log.showSignature=false',
315+
'log',
316+
'abcdefg',
317+
'-n',
318+
'1',
319+
'--pretty=format:%ad',
320+
'--date=iso',
321+
],
322+
stdout: getChannelUpToDateVersion().toString(),
323+
),
324+
FakeCommand(
325+
command: const <String>[
326+
'git',
327+
'-c',
328+
'log.showSignature=false',
329+
'log',
330+
'HEAD',
331+
'-n',
332+
'1',
333+
'--pretty=format:%ad',
334+
'--date=iso',
335+
],
336+
stdout: getChannelUpToDateVersion().toString(),
337+
),
338+
const FakeCommand(command: <String>['git', 'fetch', '--tags']),
339+
FakeCommand(
340+
command: const <String>[
341+
'git',
342+
'-c',
343+
'log.showSignature=false',
344+
'log',
345+
'@{upstream}',
346+
'-n',
347+
'1',
348+
'--pretty=format:%ad',
349+
'--date=iso',
350+
],
351+
stdout: getChannelUpToDateVersion().toString(),
352+
),
353+
const FakeCommand(
354+
command: <String>[
355+
'git',
356+
'-c',
357+
'log.showSignature=false',
358+
'log',
359+
'-n',
360+
'1',
361+
'--pretty=format:%ar',
362+
],
363+
stdout: '1 second ago',
364+
),
365+
FakeCommand(
366+
command: const <String>[
367+
'git',
368+
'-c',
369+
'log.showSignature=false',
370+
'log',
371+
'HEAD',
372+
'-n',
373+
'1',
374+
'--pretty=format:%ad',
375+
'--date=iso',
376+
],
377+
stdout: getChannelUpToDateVersion().toString(),
378+
),
379+
const FakeCommand(
380+
command: <String>[
381+
'git',
382+
'-c',
383+
'log.showSignature=false',
384+
'log',
385+
'-n',
386+
'1',
387+
'--pretty=format:%ar',
388+
'abcdefg',
389+
],
390+
stdout: '2 seconds ago',
391+
),
392+
]);
393+
394+
final FlutterVersion flutterVersion = FlutterVersion(
395+
clock: _testClock,
396+
fs: fs,
397+
flutterRoot: flutterRoot,
398+
fetchTags: true,
399+
);
400+
await flutterVersion.checkFlutterVersionFreshness();
401+
402+
// Verify the version files exist and have been repopulated after the fetch.
403+
expect(FlutterVersion.getVersionFile(fs, flutterRoot), exists); // flutter.version.json
404+
expect(fs.file(fs.path.join(flutterRoot, 'version')), exists); // legacy
405+
406+
expect(flutterVersion.channel, channel);
407+
expect(flutterVersion.repositoryUrl, flutterUpstreamUrl);
408+
expect(flutterVersion.frameworkRevision, '1234abcd');
409+
expect(flutterVersion.frameworkRevisionShort, '1234abcd');
410+
expect(flutterVersion.frameworkVersion, '0.0.0-unknown');
411+
expect(
412+
flutterVersion.toString(),
413+
'Flutter • channel $channel • $flutterUpstreamUrl\n'
414+
'Framework • revision 1234abcd (1 second ago) • ${getChannelUpToDateVersion()}\n'
415+
'Engine • revision abcdefg (2 seconds ago) • ${getChannelUpToDateVersion()}\n'
416+
'Tools • Dart 2.12.0 • DevTools 2.8.0',
417+
);
418+
expect(flutterVersion.frameworkAge, '1 second ago');
419+
expect(flutterVersion.getVersionString(), '$channel/1234abcd');
420+
expect(flutterVersion.getBranchName(), channel);
421+
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd');
422+
expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel);
423+
424+
expect(testLogger.statusText, isEmpty);
425+
expect(processManager, hasNoRemainingExpectations);
426+
},
427+
overrides: <Type, Generator>{ProcessManager: () => processManager, Cache: () => cache},
428+
);
429+
230430
testUsingContext(
231431
'does not crash when git log outputs malformed output',
232432
() async {

0 commit comments

Comments
 (0)