From c8efcb632bc853780f78ddb793d0ff49e12b76a7 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Fri, 27 Mar 2020 22:31:01 -0700 Subject: [PATCH] Only fetch tags when not on dev/beta/stable (#53450) --- packages/flutter_tools/lib/src/version.dart | 7 ++- .../test/general.shard/version_test.dart | 58 ++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 301094236265..85e4fd74057e 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -722,7 +722,12 @@ class GitTagVersion { static GitTagVersion determine(ProcessUtils processUtils, {String workingDirectory, bool fetchTags = false}) { if (fetchTags) { - _runGit('git fetch $_flutterGit --tags', processUtils, workingDirectory); + final String channel = _runGit('git rev-parse --abbrev-ref HEAD', processUtils, workingDirectory); + if (channel == 'dev' || channel == 'beta' || channel == 'stable') { + globals.printTrace('Skipping request to fetchTags - on well known channel $channel.'); + } else { + _runGit('git fetch $_flutterGit --tags', processUtils, workingDirectory); + } } return parse(_runGit('git describe --match v*.*.* --first-parent --long --tags', processUtils, workingDirectory)); } diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart index 88a32622e716..2a71c5edabcf 100644 --- a/packages/flutter_tools/test/general.shard/version_test.dart +++ b/packages/flutter_tools/test/general.shard/version_test.dart @@ -428,6 +428,11 @@ void main() { GitTagVersion.determine(processUtils, workingDirectory: '.'); + verifyNever(processUtils.runSync( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )); verifyNever(processUtils.runSync( ['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'], workingDirectory: anyNamed('workingDirectory'), @@ -440,21 +445,68 @@ void main() { )).called(1); }); - testUsingContext('determine calls fetch --tags', () { + testUsingContext('determine does not fetch tags on dev/stable/beta', () { final MockProcessUtils processUtils = MockProcessUtils(); + when(processUtils.runSync( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(105, 0, 'dev', ''), ['git', 'fetch'])); when(processUtils.runSync( ['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'], workingDirectory: anyNamed('workingDirectory'), environment: anyNamed('environment'), - )).thenReturn(RunResult(ProcessResult(105, 0, '', ''), ['git', 'fetch'])); + )).thenReturn(RunResult(ProcessResult(106, 0, '', ''), ['git', 'fetch'])); when(processUtils.runSync( ['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'], workingDirectory: anyNamed('workingDirectory'), environment: anyNamed('environment'), - )).thenReturn(RunResult(ProcessResult(106, 0, 'v0.1.2-3-1234abcd', ''), ['git', 'describe'])); + )).thenReturn(RunResult(ProcessResult(107, 0, 'v0.1.2-3-1234abcd', ''), ['git', 'describe'])); + + GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true); + + verify(processUtils.runSync( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).called(1); + verifyNever(processUtils.runSync( + ['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )); + verify(processUtils.runSync( + ['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).called(1); + }); + + testUsingContext('determine calls fetch --tags on master', () { + final MockProcessUtils processUtils = MockProcessUtils(); + when(processUtils.runSync( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(108, 0, 'master', ''), ['git', 'fetch'])); + when(processUtils.runSync( + ['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(109, 0, '', ''), ['git', 'fetch'])); + when(processUtils.runSync( + ['git', 'describe', '--match', 'v*.*.*', '--first-parent', '--long', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(110, 0, 'v0.1.2-3-1234abcd', ''), ['git', 'describe'])); GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true); + verify(processUtils.runSync( + ['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).called(1); verify(processUtils.runSync( ['git', 'fetch', 'https://github.com/flutter/flutter.git', '--tags'], workingDirectory: anyNamed('workingDirectory'),