[flutter_tools] Make flutter git upstream configurable (#61513)
diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index e798a36..796dd81 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart
@@ -24,7 +24,7 @@ } /// 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 @@ 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 47f1343..2ee7c47 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 '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 @@ environment: anyNamed('environment'), )).called(1); }); + + testUsingContext('determine uses overridden git url', () { + final MockProcessUtils processUtils = MockProcessUtils(); + when(processUtils.runSync( + <String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(108, 0, 'master', ''), <String>['git', 'fetch'])); + when(processUtils.runSync( + <String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags', '-f'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(109, 0, '', ''), <String>['git', 'fetch'])); + when(processUtils.runSync( + <String>['git', 'tag', '--contains', 'HEAD'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn( + RunResult(ProcessResult(110, 0, '', ''), + <String>['git', 'tag', '--contains', 'HEAD'], + )); + when(processUtils.runSync( + <String>['git', 'describe', '--match', '*.*.*-*.*.pre', '--first-parent', '--long', '--tags'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenReturn(RunResult(ProcessResult(111, 0, 'v0.1.2-3-1234abcd', ''), <String>['git', 'describe'])); + + GitTagVersion.determine(processUtils, workingDirectory: '.', fetchTags: true); + + verify(processUtils.runSync( + <String>['git', 'fetch', 'https://githubmirror.com/flutter.git', '--tags', '-f'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).called(1); + }, overrides: <Type, Generator>{ + Platform: () => FakePlatform(environment: <String, String>{ + 'FLUTTER_GIT_URL': 'https://githubmirror.com/flutter.git', + }), + }); } void _expectVersionMessage(String message) {