Unverified Commit e7ab846d authored by Anurag Roy's avatar Anurag Roy Committed by GitHub

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

parent 71ec251a
...@@ -449,15 +449,16 @@ class VersionUpstreamValidator { ...@@ -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 { ...@@ -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.
......
...@@ -379,17 +379,17 @@ void main() { ...@@ -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.'
), ),
); );
......
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