[flutter_tools] Fix VersionUpstreamValidator to respect FLUTTER_GIT_URL (#100605)

This commit is contained in:
Anurag Roy 2022-03-26 06:05:10 +05:30 committed by GitHub
parent 71ec251a59
commit e7ab846d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 9 deletions

View File

@ -449,15 +449,16 @@ class VersionUpstreamValidator {
// Strip `.git` suffix before comparing the remotes // Strip `.git` suffix before comparing the remotes
final List<String> sanitizedStandardRemotes = <String>[ final List<String> sanitizedStandardRemotes = <String>[
if (flutterGit != null) flutterGit, // If `FLUTTER_GIT_URL` is set, use that as standard remote.
'https://github.com/flutter/flutter.git', if (flutterGit != null) flutterGit
'git@github.com:flutter/flutter.git', // Else use the predefined standard remotes.
else ..._standardRemotes,
].map((String remote) => stripDotGit(remote)).toList(); ].map((String remote) => stripDotGit(remote)).toList();
final String sanitizedRepositoryUrl = stripDotGit(repositoryUrl); final String sanitizedRepositoryUrl = stripDotGit(repositoryUrl);
if (!sanitizedStandardRemotes.contains(sanitizedRepositoryUrl)) { if (!sanitizedStandardRemotes.contains(sanitizedRepositoryUrl)) {
if (platform.environment.containsKey('FLUTTER_GIT_URL')) { if (flutterGit != null) {
// If `FLUTTER_GIT_URL` is set, inform to either remove the // If `FLUTTER_GIT_URL` is set, inform to either remove the
// `FLUTTER_GIT_URL` environment variable or set it to the current // `FLUTTER_GIT_URL` environment variable or set it to the current
// tracking remote. // tracking remote.
@ -482,6 +483,12 @@ class VersionUpstreamValidator {
return null; return null;
} }
// The predefined list of remotes that are considered to be standard.
static final List<String> _standardRemotes = <String>[
'https://github.com/flutter/flutter.git',
'git@github.com:flutter/flutter.git',
];
// Strips ".git" suffix from a given string, preferably an url. // Strips ".git" suffix from a given string, preferably an url.
// For example, changes 'https://github.com/flutter/flutter.git' to 'https://github.com/flutter/flutter'. // For example, changes 'https://github.com/flutter/flutter.git' to 'https://github.com/flutter/flutter'.
// URLs without ".git" suffix will remain unaffected. // URLs without ".git" suffix will remain unaffected.

View File

@ -379,17 +379,17 @@ void main() {
), isNull); ), isNull);
}); });
testWithoutContext('returns error at remote url and FLUTTER_GIT_URL set to different urls', () { testWithoutContext('respects FLUTTER_GIT_URL even if upstream remote url is standard', () {
final VersionCheckError error = runUpstreamValidator( final VersionCheckError error = runUpstreamValidator(
versionUpstreamUrl: flutterNonStandardUrlDotGit, versionUpstreamUrl: flutterStandardUrlDotGit,
flutterGitUrl: flutterStandardUrlDotGit, flutterGitUrl: flutterNonStandardUrlDotGit,
); );
expect(error, isNotNull); expect(error, isNotNull);
expect( expect(
error.message, error.message,
contains( contains(
'The Flutter SDK is tracking "$flutterNonStandardUrlDotGit" but "FLUTTER_GIT_URL" is set to "$flutterStandardUrlDotGit".\n' 'The Flutter SDK is tracking "$flutterStandardUrlDotGit" but "FLUTTER_GIT_URL" is set to "$flutterNonStandardUrlDotGit".\n'
'Either remove "FLUTTER_GIT_URL" from the environment or set it to "$flutterNonStandardUrlDotGit". ' 'Either remove "FLUTTER_GIT_URL" from the environment or set it to "$flutterStandardUrlDotGit". '
'If this is intentional, it is recommended to use "git" directly to manage the SDK.' 'If this is intentional, it is recommended to use "git" directly to manage the SDK.'
), ),
); );