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 {
// Strip `.git` suffix before comparing the remotes
final List<String> sanitizedStandardRemotes = <String>[
if (flutterGit != null) flutterGit,
'https://github.com/flutter/flutter.git',
'git@github.com:flutter/flutter.git',
// If `FLUTTER_GIT_URL` is set, use that as standard remote.
if (flutterGit != null) flutterGit
// Else use the predefined standard remotes.
else ..._standardRemotes,
].map((String remote) => stripDotGit(remote)).toList();
final String sanitizedRepositoryUrl = stripDotGit(repositoryUrl);
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
// `FLUTTER_GIT_URL` environment variable or set it to the current
// tracking remote.
......@@ -482,6 +483,12 @@ class VersionUpstreamValidator {
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.
// For example, changes 'https://github.com/flutter/flutter.git' to 'https://github.com/flutter/flutter'.
// URLs without ".git" suffix will remain unaffected.
......
......@@ -379,17 +379,17 @@ void main() {
), 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(
versionUpstreamUrl: flutterNonStandardUrlDotGit,
flutterGitUrl: flutterStandardUrlDotGit,
versionUpstreamUrl: flutterStandardUrlDotGit,
flutterGitUrl: flutterNonStandardUrlDotGit,
);
expect(error, isNotNull);
expect(
error.message,
contains(
'The Flutter SDK is tracking "$flutterNonStandardUrlDotGit" but "FLUTTER_GIT_URL" is set to "$flutterStandardUrlDotGit".\n'
'Either remove "FLUTTER_GIT_URL" from the environment or set it to "$flutterNonStandardUrlDotGit". '
'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 "$flutterStandardUrlDotGit". '
'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