Skip to content

Commit c8efcb6

Browse files
authored
Only fetch tags when not on dev/beta/stable (flutter#53450)
1 parent dfc3318 commit c8efcb6

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

packages/flutter_tools/lib/src/version.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,12 @@ class GitTagVersion {
722722

723723
static GitTagVersion determine(ProcessUtils processUtils, {String workingDirectory, bool fetchTags = false}) {
724724
if (fetchTags) {
725-
_runGit('git fetch $_flutterGit --tags', processUtils, workingDirectory);
725+
final String channel = _runGit('git rev-parse --abbrev-ref HEAD', processUtils, workingDirectory);
726+
if (channel == 'dev' || channel == 'beta' || channel == 'stable') {
727+
globals.printTrace('Skipping request to fetchTags - on well known channel $channel.');
728+
} else {
729+
_runGit('git fetch $_flutterGit --tags', processUtils, workingDirectory);
730+
}
726731
}
727732
return parse(_runGit('git describe --match v*.*.* --first-parent --long --tags', processUtils, workingDirectory));
728733
}

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

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ void main() {
428428

429429
GitTagVersion.determine(processUtils, workingDirectory: '.');
430430

431+
verifyNever(processUtils.runSync(
432+
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
433+
workingDirectory: anyNamed('workingDirectory'),
434+
environment: anyNamed('environment'),
435+
));
431436
verifyNever(processUtils.runSync(
432437
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
433438
workingDirectory: anyNamed('workingDirectory'),
@@ -440,21 +445,68 @@ void main() {
440445
)).called(1);
441446
});
442447

443-
testUsingContext('determine calls fetch --tags', () {
448+
testUsingContext('determine does not fetch tags on dev/stable/beta', () {
444449
final MockProcessUtils processUtils = MockProcessUtils();
450+
when(processUtils.runSync(
451+
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
452+
workingDirectory: anyNamed('workingDirectory'),
453+
environment: anyNamed('environment'),
454+
)).thenReturn(RunResult(ProcessResult(105, 0, 'dev', ''), <String>['git', 'fetch']));
445455
when(processUtils.runSync(
446456
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
447457
workingDirectory: anyNamed('workingDirectory'),
448458
environment: anyNamed('environment'),
449-
)).thenReturn(RunResult(ProcessResult(105, 0, '', ''), <String>['git', 'fetch']));
459+
)).thenReturn(RunResult(ProcessResult(106, 0, '', ''), <String>['git', 'fetch']));
450460
when(processUtils.runSync(
451461
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
452462
workingDirectory: anyNamed('workingDirectory'),
453463
environment: anyNamed('environment'),
454-
)).thenReturn(RunResult(ProcessResult(106, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));
464+
)).thenReturn(RunResult(ProcessResult(107, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));
465+
466+
GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true);
467+
468+
verify(processUtils.runSync(
469+
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
470+
workingDirectory: anyNamed('workingDirectory'),
471+
environment: anyNamed('environment'),
472+
)).called(1);
473+
verifyNever(processUtils.runSync(
474+
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
475+
workingDirectory: anyNamed('workingDirectory'),
476+
environment: anyNamed('environment'),
477+
));
478+
verify(processUtils.runSync(
479+
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
480+
workingDirectory: anyNamed('workingDirectory'),
481+
environment: anyNamed('environment'),
482+
)).called(1);
483+
});
484+
485+
testUsingContext('determine calls fetch --tags on master', () {
486+
final MockProcessUtils processUtils = MockProcessUtils();
487+
when(processUtils.runSync(
488+
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
489+
workingDirectory: anyNamed('workingDirectory'),
490+
environment: anyNamed('environment'),
491+
)).thenReturn(RunResult(ProcessResult(108, 0, 'master', ''), <String>['git', 'fetch']));
492+
when(processUtils.runSync(
493+
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
494+
workingDirectory: anyNamed('workingDirectory'),
495+
environment: anyNamed('environment'),
496+
)).thenReturn(RunResult(ProcessResult(109, 0, '', ''), <String>['git', 'fetch']));
497+
when(processUtils.runSync(
498+
<String>['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'],
499+
workingDirectory: anyNamed('workingDirectory'),
500+
environment: anyNamed('environment'),
501+
)).thenReturn(RunResult(ProcessResult(110, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe']));
455502

456503
GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true);
457504

505+
verify(processUtils.runSync(
506+
<String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
507+
workingDirectory: anyNamed('workingDirectory'),
508+
environment: anyNamed('environment'),
509+
)).called(1);
458510
verify(processUtils.runSync(
459511
<String>['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'],
460512
workingDirectory: anyNamed('workingDirectory'),

0 commit comments

Comments
 (0)