From e7ab846d14e244a245eb36049a5b67c7ce6cf77b Mon Sep 17 00:00:00 2001 From: Anurag Roy <44899587+RoyARG02@users.noreply.github.com> Date: Sat, 26 Mar 2022 06:05:10 +0530 Subject: [PATCH] [flutter_tools] Fix VersionUpstreamValidator to respect FLUTTER_GIT_URL (#100605) --- packages/flutter_tools/lib/src/version.dart | 15 +++++++++++---- .../test/general.shard/version_test.dart | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/packages/flutter_tools/lib/src/version.dart b/packages/flutter_tools/lib/src/version.dart index 19d71847b4..f2068a6ca2 100644 --- a/packages/flutter_tools/lib/src/version.dart +++ b/packages/flutter_tools/lib/src/version.dart @@ -449,15 +449,16 @@ class VersionUpstreamValidator { // Strip `.git` suffix before comparing the remotes final List sanitizedStandardRemotes = [ - 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 _standardRemotes = [ + '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. diff --git a/packages/flutter_tools/test/general.shard/version_test.dart b/packages/flutter_tools/test/general.shard/version_test.dart index 04dff00862..d69ee4a452 100644 --- a/packages/flutter_tools/test/general.shard/version_test.dart +++ b/packages/flutter_tools/test/general.shard/version_test.dart @@ -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.' ), );