Unverified Commit 7779a147 authored by 雷宇辰's avatar 雷宇辰 Committed by GitHub

[flutter_tools] Make flutter git upstream configurable (#61513)

parent f9499f44
...@@ -24,7 +24,7 @@ enum Channel { ...@@ -24,7 +24,7 @@ enum Channel {
} }
/// The flutter GitHub repository. /// 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]. /// Retrieve a human-readable name for a given [channel].
/// ///
...@@ -259,6 +259,13 @@ class FlutterVersion { ...@@ -259,6 +259,13 @@ class FlutterVersion {
branch: '$_versionCheckRemote/$branch', branch: '$_versionCheckRemote/$branch',
lenient: false, 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 { } finally {
await _removeVersionCheckRemoteIfExists(); await _removeVersionCheckRemoteIfExists();
} }
......
...@@ -7,6 +7,7 @@ import 'dart:convert'; ...@@ -7,6 +7,7 @@ import 'dart:convert';
import 'package:collection/collection.dart' show ListEquality; import 'package:collection/collection.dart' show ListEquality;
import 'package:flutter_tools/src/base/context.dart'; import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/base/io.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/process.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/base/utils.dart'; import 'package:flutter_tools/src/base/utils.dart';
...@@ -609,6 +610,45 @@ void main() { ...@@ -609,6 +610,45 @@ void main() {
environment: anyNamed('environment'), environment: anyNamed('environment'),
)).called(1); )).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) { void _expectVersionMessage(String message) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment