From 7779a14794a5e60a329aa01e7a29a609b4169f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=AE=87=E8=BE=B0?= <6648049+TooYoungTooSimp@users.noreply.github.com> Date: Sat, 25 Jul 2020 07:16:31 +0800 Subject: [PATCH] [flutter_tools] Make flutter git upstream configurable (#61513) --- packages/flutter_tools/lib/src/version.dart | 9 ++++- .../test/general.shard/version_test.dart | 40 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index e798a36e43..796dd81e8a 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -24,7 +24,7 @@ enum Channel { } /// The flutter GitHub repository. -const String _flutterGit = 'https://github.com/flutter/flutter.git'; +String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git'; /// Retrieve a human-readable name for a given [channel]. /// @@ -259,6 +259,13 @@ class FlutterVersion { branch: '$_versionCheckRemote/$branch', lenient: false, ); + } on VersionCheckError catch (error) { + if (globals.platform.environment.containsKey('FLUTTER_GIT_URL')) { + globals.logger.printError('Warning: the Flutter git upstream was overriden ' + 'by the environment variable FLUTTER_GIT_URL = $_flutterGit'); + } + globals.logger.printError(error.toString()); + rethrow; } finally { await _removeVersionCheckRemoteIfExists(); } diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart index 47f1343a47..2ee7c47229 100644 --- a/packages/flutter_tools/test/general.shard/version_test.dart +++ b/packages/flutter_tools/test/general.shard/version_test.dart @@ -7,6 +7,7 @@ import 'dart:convert'; import 'package:collection/collection.dart' show ListEquality; import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/io.dart'; +import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/process.dart'; import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/utils.dart'; @@ -609,6 +610,45 @@ void main() { environment: anyNamed('environment'), )).called(1); }); + + testUsingContext('determine uses overridden git url', () { + 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://githubmirror.com/flutter.git', '--tags', '-f'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(109, 0, '', ''), ['git', 'fetch'])); + when(processUtils.runSync( + ['git', 'tag', '--contains', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn( + RunResult(ProcessResult(110, 0, '', ''), + ['git', 'tag', '--contains', 'HEAD'], + )); + when(processUtils.runSync( + ['git', 'describe', '--match', '*.*.*-*.*.pre', '--first-parent', '--long', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(111, 0, 'v0.1.2-3-1234abcd', ''), ['git', 'describe'])); + + GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true); + + verify(processUtils.runSync( + ['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags', '-f'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).called(1); + }, overrides: { + Platform: () => FakePlatform(environment: { + 'FLUTTER_GIT_URL': 'https://githubmirror.com/flutter.git', + }), + }); } void _expectVersionMessage(String message) {